Bar chart: Get color of the bars

163 views
Skip to first unread message

Manish

unread,
Jul 27, 2011, 7:37:43 PM7/27/11
to Google Visualization API
Hi,

I have used google charts API to create a bar chart. I am trying to
show different scores and percentiles of a student in various
subjects. The subjects may vary according to each student and hence is
dynamic. I was successfully able to render the graph, but I need to
get the colors of each bar (for some text styling in html file). How
can this be achieved?

Thanks

asgallant

unread,
Jul 28, 2011, 9:32:02 AM7/28/11
to google-visua...@googlegroups.com
AFAIK, there isn't anything in the charts that lets you get the column colors.  The best you can do is assign colors to the chart series manually and extrapolate based on that.  Ex: if you set your colors option to "colors: ['red', 'green', 'blue']" then column 0 is always red, regardless of how many columns you have in total.  If you assign more colors than columns, the extras are ignored.

Benjamin Press

unread,
Jun 20, 2012, 4:46:46 PM6/20/12
to google-visua...@googlegroups.com
What if you assign fewer colors than columns?

asgallant

unread,
Jun 20, 2012, 11:45:39 PM6/20/12
to google-visua...@googlegroups.com
I believe the chart repeats the array's contents as many times as is necessary to color all the series, so using "colors: ['red', 'green', 'blue']" with 4 series would result in the first and fourth data series being red (as I recall, anyway; it is easy to test to verify).
Reply all
Reply to author
Forward
0 new messages