简体   繁体   中英

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

I am using 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. How can I change the color of the pie charts to my unique color palette?

adding it this way changes the colors.

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

pen

adding it two way changes the colors.

the first is:

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

the second is:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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