echarts中series的循环显示

将代码复制到此地址就可以看到效果 https://www.echartsjs.com/examples/zh/editor.html?c=line-stack

var keys = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
var datas = [
    [120, 132, 101, 134, 90, 230, 210],
    [220, 182, 191, 234, 290, 330, 310],
    [150, 232, 201, 154, 190, 330, 410],
    [320, 332, 301, 334, 390, 330, 320],
    [820, 932, 901, 934, 1290, 1330, 1320]
    ]

var series = [
        {
            name: products[0],
            type: 'line',
            stack: '总量',
            data: datas[0]
        },
        {
            name: products[1],
            type: 'line',
            stack: '总量',
            data: datas[1]
        },
        {
            name: products[2],
            type: 'line',
            stack: '总量',
            data: datas[2]
        },
        {
            name: products[3],
            type: 'line',
            stack: '总量',
            data: datas[3]
        },
        {
            name: products[4],
            type: 'line',
            stack: '总量',
            data: datas[4]
        }
    ]

var seriesArr = [];
for(var i = 0; i<products.length; i++){
        seriesArr.push({
            name: products[i],
            type: 'line',
            stack: '总量',
            // data:[120, 132, 101, 134, 90, 230, 210]
            data: datas[i]
        });
    }
    
    
option = {
    title: {
        text: '折线图堆叠'
    },
    tooltip: {
        trigger: 'axis'
    },
    legend: {
        data: products
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: keys
    },
    yAxis: {
        type: 'value'
    },
    series: seriesArr
};
posted @ 2020-03-10 16:35  我见青山应如是  阅读(1901)  评论(0编辑  收藏  举报