Orcasz
Orcasz

Reputation: 11

How to change the chart colors in google charts as an event?

What i want to achieve:
I want the color of the bars of my columnchart to be determined by column 0, so when the user filters the columns via the implemented CategoryFilter, they see the bars in the color fitting for the data displayed.
For example:

column0, column1, column2
   pig, height, weight 
   bird, heigth, weight

So that if pig is choosen height will be pink and weight will be brown, while when bird is choosen height will be red and weight will be blue.

What I already tried:
I've tried to set an eventhandler and I tried to shoehorn an if...else statement which both absolutely didn't work

Edit:
Okay, I've forgot to mention that in my original file I have used variables to populate the dataView with data from an sql database, so normal role assignments won't work either

Upvotes: 1

Views: 38

Answers (1)

WhiteHat
WhiteHat

Reputation: 61222

you can use the style column role to specify a specific color

to use the style role, you simply add the color to the column following the value

for example, if the following is your data structure...

['column0', 'column1', 'column2'],
['pig', height, weight],
['bird', heigth, weight],

following would be the new data structure using the style role...

['column0', 'column1', {role: 'style', type: 'string'}, 'column2', {role: 'style', type: 'string'}],
['pig', height, 'pink', weight, 'brown'],
['bird', heigth, 'red', weight, 'blue'],

Upvotes: 1

Related Questions