1. 程式人生 > 實用技巧 >ECharts series data 數組裡面的元素,可以是物件

ECharts series data 數組裡面的元素,可以是物件

修改自:https://echarts.apache.org/examples/zh/editor.html?c=line-stack

option = {
    title: {
        text: '折線圖堆疊'
    },
    tooltip: {
        trigger: 'axis',
        formatter: p => {
            let returnStr = ''
            let len = p.length
            for (let i = 0;i< len;i++) {
                if (p[i].seriesName ='郵件營銷' && i == 0) {
                    console.log(p[i])
                    returnStr += p[i].data['age']
                } else {
                    returnStr += String(p[i].value) + ' '
                }
            }
            return returnStr
        }
    },
    legend: {
        data: ['郵件營銷', '聯盟廣告', '視訊廣告', '直接訪問', '搜尋引擎']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    toolbox: {
        feature: {
            saveAsImage: {}
        }
    },
    xAxis: {
        type: 'category',
        boundaryGap: false,
        data: ['週一', '週二', '週三', '週四', '週五', '週六', '週日']
    },
    yAxis: {
        type: 'value'
    },
    series: [
        {
            name: '郵件營銷',
            type: 'line',
            stack: '總量',
            data: [{'name':'jeff','age':18,'value':18}, 132, 101, 134, 90, 230, 210]
        },
        {
            name: '聯盟廣告',
            type: 'line',
            stack: '總量',
            data: [{'name':'jeff','age':18,'value':18}, 182, 191, 234, 290, 330, 310]
        },
        {
            name: '視訊廣告',
            type: 'line',
            stack: '總量',
            data: [{'name':'jeff','age':18,'value':18}, 232, 201, 154, 190, 330, 410]
        },
        {
            name: '直接訪問',
            type: 'line',
            stack: '總量',
            data: [{'name':'jeff','age':18,'value':18}, 332, 301, 334, 390, 330, 320]
        },
        {
            name: '搜尋引擎',
            type: 'line',
            stack: '總量',
            data: [{'name':'jeff','age':18,'value':18}, 932, 901, 934, 1290, 1330, 1320]
        }
    ]
};