两种图表组合(柱状图和折线图),数据来自json对象

来源:互联网 发布:如何注册公司域名 编辑:程序博客网 时间:2024/05/21 14:45

关于这里面的参数,参考http://echarts.baidu.com/echarts2/doc/doc.html#%E9%80%89%E9%A1%B9

// 基于准备好的dom,初始化echarts实例var myChart = echarts.init(document.getElementById('chart'));var mc_code=[];var sum_hours = [];var sum_times = [];for (var i = 0; i < jsonObj.length; i++){    mc_code.push(jsonObj[i].MC_CODE);    sum_hours.push(jsonObj[i].SumHours);    sum_times.push(jsonObj[i].SumTimes);}// 指定图表的配置项和数据var option = {    color: ['#16abfe', '#ff7070'],    tooltip: {        trigger: 'axis',        axisPointer: {            type: 'cross',            crossStyle: {                color: '#999'            }        }    },    legend: {        data: ['累计时间', '累计次数']    },    xAxis: [{        type: 'category',        name: '故障代码',        nameLocation: 'start',        data: mc_code,        axisPointer: {            type: 'shadow'        },        axisLabel:{            rotate: 45        }    }],    yAxis: [        {            type: 'value',            name: '累计时间',            axisLabel: {                formatter: '{value}'            }        },         {            type: 'value',name: '累计次数',            axisLabel: {                formatter: '{value}'            }        },    ],    series: [        {            name: '累计时间',            type: 'bar',            yAxisIndex: 0,            data: sum_hours        },        {            name: '累计次数',            type: 'line',            yAxisIndex: 1,            data: sum_times        }    ]};// 使用刚指定的配置项和数据显示图表。myChart.setOption(option);
阅读全文
0 0