Re: Fix the color of each elements of Google pie chart

2,041 views
Skip to first unread message

asgallant

unread,
Dec 11, 2012, 12:08:32 PM12/11/12
to google-visua...@googlegroups.com
What do you mean by "it keeps changing randomly"?  Does it change when you change the data?  The way the colors work in PieCharts is that they are assigned in the row order of the data (so in your case, whatever data is in the first row will always have the color '#C1D558').  If you want to assign specific colors to specific data elements, you have to change the colors array to fit your data set.

On Tuesday, December 11, 2012 9:29:27 AM UTC-5, Manish Kumar wrote:
Hello Every body,
I am using Google pie chart where i have maximum 4 sectors and the data for them are coming from my database.
The code i used for colors is

var options = {
    chartArea: {width:300, height:135},
    height:165,
    margin:10,
   colors: ['#C1D558', '#22297A', '#C21536', '#996ab2'],
   is3D: false
   
            
    };

I want fix color for each element of the pie chart. It keep on changing randomly. Please suggest me how to get that.

Manish Kumar

unread,
Dec 12, 2012, 4:22:33 AM12/12/12
to google-visua...@googlegroups.com
Hello,
Actually what i am facing i am elaborating it bit more. If i have 4 data elements and for each these four colors are assigned. All these four elements are elaborating counts for 4 features.
When the data regarding any of the elements changes then after some changes if A element was green and B was red like that, then color sequence changes now A is showing red B as green. I need to make colors for each elements to be constant. Like A should always be red what ever may be data for it. Even if it is 0 when it comes it should be always red.
If A is not there no other element should be red. Like that all colors for other elements should be specific.

Thanks.

asgallant

unread,
Dec 12, 2012, 11:45:25 AM12/12/12
to google-visua...@googlegroups.com
You have to build the colors array to match your data.  If you have 4 elements A, B, C, and D, where A is green, B is red, C is blue, and D is yellow, then you will have to check your data before you draw the chart to see what elements are present and what order they are in.  If the data contains C, B, D, then you will have to set your colors to array to ['blue', 'red', 'yellow'].

Manish Kumar

unread,
Dec 13, 2012, 2:48:36 AM12/13/12
to google-visua...@googlegroups.com
Thank you asgallant ,
I got what you are trying to give the solution. I will try this way.
Thanks.
Reply all
Reply to author
Forward
0 new messages