PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, April 23, 2022

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

 April 23, 2022     echarts, javascript, pie-chart     No comments   

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,
...
]

pen



Answered By - Aykhan
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing