简体   繁体   English

如何使用 echarts 更改饼图的颜色?

[英]How can I change the color of the Pie charts using echarts?

I am using echarts .我正在使用echarts I want to assign my own color palette for the generated pie chart.我想为生成的饼图分配我自己的调色板。 I write the following code;我写了以下代码;

var myChart = echarts.init(document.getElementById('EAR-charts'));
var colorPalette = ['#00b04f', '#ffbf00', 'ff0000']
optionEAR = {
    title: {
        text: 'Element at Risk',
        subtext: 'Pie chart',
        x: 'center'
    },
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b} : {c} ({d}%)"
    },
    legend: {
        orient: 'vertical',
        left: 'left',
        data: ['Agriculture', 'Builtup', 'Roads']
    },
    series: [
        {
            name: 'Element at Risk',
            type: 'pie',
            radius: '55%',
            center: ['50%', '60%'],
            data: [
                { value: 335, name: 'Agriculture' },
                { value: 310, name: 'Builtup' },
                { value: 234, name: 'Roads' }
            ],
            itemStyle: {
                emphasis: {
                    shadowBlur: 10,
                    shadowOffsetX: 0,
                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                }
            }
        }
    ],
    graph: {
        color: colorPalette
    }
};
myChart.setOption(optionEAR);

But the color is not changing.但是颜色没有变化。 But the output shows the default color of pie chart.但是 output 显示饼图的默认颜色。 How can I change the color of the pie charts to my unique color palette?如何将饼图的颜色更改为我独特的调色板?

adding it this way changes the colors.以这种方式添加它会改变 colors。

series: [
...
color: colorPalette,
...
]

pen

adding it two way changes the colors.以两种方式添加它会更改 colors。

the first is:第一个是:

series: [
...
color: colorPalette,
...
]

the second is:第二个是:

series: [
...
],
color: colorPalette,
...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM