日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

Echarts - 更改圖表圖例(legend)自定義顏色(并與數據段顏色對應)

作者:王佳斌 更新時間: 2022-02-26 編程語言

前言

示例來自 Echarts 官網:https://echarts.apache.org/examples/zh/editor.html?c=line-stack

如下圖所示,這是默認圖例的顏色,我們接下來進行更改。
在這里插入圖片描述

實現代碼

主要是 color 調色盤的配置,具體可看文檔。

在這里插入圖片描述

option = {
    title: {
        text: ''
    },
    tooltip: {
        trigger: 'axis'
    },
    
    
    // 更改圖例默認顏色(依次應用)
    color:['red', 'black', 'yellow', 'pink', 'cyan'],
    // end

    
    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: [120, 132, 101, 134, 90, 230, 210]
        },
        {
            name: '聯盟廣告',
            type: 'line',
            stack: '總量',
            data: [220, 182, 191, 234, 290, 330, 310]
        },
        {
            name: '視頻廣告',
            type: 'line',
            stack: '總量',
            data: [150, 232, 201, 154, 190, 330, 410]
        },
        {
            name: '直接訪問',
            type: 'line',
            stack: '總量',
            data: [320, 332, 301, 334, 390, 330, 320]
        },
        {
            name: '搜索引擎',
            type: 'line',
            stack: '總量',
            data: [820, 932, 901, 934, 1290, 1330, 1320]
        }
    ]
};

效果

完成。
在這里插入圖片描述

原文鏈接:https://wangjiabin.blog.csdn.net/article/details/116118213

欄目分類
最近更新