Issue
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?
Solution
adding it this way changes the colors.
series: [
...
color: colorPalette,
...
]
Answered By - Aykhan Answer Checked By - Marie Seifert (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.