Re: [visualization-api] Changing column chart color dynamically

1,221 views
Skip to first unread message

Sergey Grabkovsky

unread,
Dec 17, 2012, 11:00:57 AM12/17/12
to google-visua...@googlegroups.com
Hi, unfortunately there is no way to control specific chart elements through the API. One possible solution is to manipulate the SVG directly, but that is not recommended. Luckily, redrawing the chart doesn't recalculate all the data, it actually remembers a lot of things from the previous draw. So redrawing shouldn't be as expensive as you suspect it is.

- Sergey



On Mon, Dec 17, 2012 at 9:42 AM, Rastko Jokic <rastk...@gmail.com> wrote:
I am using column chart to represent my data.

So, I would like to add feature that when the user selects one of the columns, others (non-selected) change their color to gray (just make the selection more obvious)..

I would like to do this dynamically without of need to redraw the entire chart again.

Anyone have any ideas how to achieve this?

Thank you in advance!

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/5lnIcfWuukIJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

asgallant

unread,
Dec 17, 2012, 11:02:02 AM12/17/12
to google-visua...@googlegroups.com
Any change in the chart requires a redraw.  I wrote a hack that does something similar (it actually changes the color of the selected bar rather than all the others, but you can modify it to fit your needs): http://jsfiddle.net/asgallant/5SX8w/

Note that this may not work well if you have multiple series of data, as it adds a new series of data to change the color of the bar and sets the "isStacked" option to true to hide the visual side effects of multiple data series.  If you you chart is stacked anyway, this won't be as much of a problem, but you have to be careful about where you insert the new data series in the chart so you keep everything in the same relative position.

Rastko Jokic

unread,
Dec 18, 2012, 1:59:31 AM12/18/12
to google-visua...@googlegroups.com
Thanks guys!

Asgallant, I'll try to adapt your hack to see if its going to fit in :)
Reply all
Reply to author
Forward
0 new messages