柱状图+折线图+双Y轴

编程入门 行业动态 更新时间:2024-10-11 17:23:50

<a href=https://www.elefans.com/category/jswz/34/1767203.html style=柱状图+折线图+双Y轴"/>

柱状图+折线图+双Y轴

时间格式问题

后台中的日期格式是java.util.Date 传到前台变成String类型的时间格式,所以要把格式转变一下。
renderTime:是把上面的那种格式改成String的YYYY-MM-DD HH:mm;ss
convertDateFromString:把YYYY-MM-DD HH:mm;ss改成date格式

数据类型都能对上以后,但是数据在前台显示不出来的问题

BUG原因:把ajax请求弄成同步的。原因在于你请求数据后还为等数据返回。echarts 就已经在展示数据了。当然这个时候数组是空的

解决方法:chart2.setOption(option); 把这句话放入到post的请求方法里面

echarts y轴数据如果太大就会造成坐标轴显示不完全的问题

我的解决方法是

grid: {left: 40},

JS完整代码

//时间格式化函数renderTime:function(date){var dateee = new Date(date).toJSON();return new Date(+new Date(dateee) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')},convertDateFromString:function(dateString){if (dateString) {var arr1 = dateString.split(" ");var sdate = arr1[0].split('-');var date = new Date(sdate[0], sdate[1]-1, sdate[2]);return date;}},initChart2:function () {var me=this;var category = [];var lineData = [];var barData = [];var	chart2= echarts.init(document.getElementById('chart2'));var url=__ctx+"/platform/home/getCountDataBytime";// $.ajaxSetup({//     async: false// });$.post(url,function(result){$(result).each(function(){var obj = this;var dt = me.renderTime(obj.endTime);var date = me.convertDateFromString(dt);category.push([date.getFullYear(),date.getMonth()  +1,date.getDate()].join('-'));// console.log(category);b= parseInt(obj.countVal);d=parseInt(obj.totalMoney);barData.push(b);lineData.push(d);});chart2.setOption(option);});var option = {tooltip: {trigger: 'axis',axisPointer: {type: 'shadow',label: {show: true,backgroundColor: '#333'}}},legend: {data: ['加氢金额', '加氢量'],textStyle: {color: '#ccc'}},xAxis: {data: category,axisLine: {lineStyle: {color: '#ccc'}}},yAxis:[{type: 'value',name: '加氢金额',splitLine: {show: false},axisLine: {lineStyle: {color: '#ccc'}}},{type: 'value',name: '加氢量',splitLine: {show: false},axisLine: {lineStyle: {color: '#ccc'}}},],grid: {left: 40},series: [{name: '加氢金额',type: 'line',itemStyle: {normal: {color: "#14c8d4",}},smooth: true,showAllSymbol: true,symbol: 'emptyCircle',symbolSize: 2,data: lineData}, {name: '加氢量',type: 'bar',yAxisIndex: 1,barWidth: 8,itemStyle: {normal: {barBorderRadius: 3,color: new echarts.graphic.LinearGradient(0, 0, 0, 1,[{offset: 0, color: '#8b24ee'},{offset: 1, color: '#30c9d4'}])}},data: barData}]};var faultByHourIndex = 0; //播放所在下标var faultByHourTime = setInterval(function() { //使得tootip每隔三秒自动显示chart2.dispatchAction({type: 'showTip', // 根据 tooltip 的配置项显示提示框。seriesIndex: 0,dataIndex: faultByHourIndex});faultByHourIndex++;if (faultByHourIndex > option.series[0].data.length) {faultByHourIndex = 0;}if (faultByHourIndex > option.series[1].data.length) {faultByHourIndex = 0;}}, 3000);},

更多推荐

柱状图+折线图+双Y轴

本文发布于:2024-03-10 08:03:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1727419.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:柱状图   折线图

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!