Color of the Bar in Columnchart

41 views
Skip to first unread message

Surya

unread,
Nov 30, 2011, 2:00:43 AM11/30/11
to Google Visualization API
Hi,

Is there anyway i can get the color of the Bar in the Columnchart
using Datatable/ dataview api?
I got one response from this group to get using the node
(SVGRectElement Object).

Thank you,
Surya

asgallant

unread,
Nov 30, 2011, 3:32:55 PM11/30/11
to google-visua...@googlegroups.com
The API does not expose any methods of getting the bars' colors after the chart is drawn.  You can either a) set the colors using the chart's 'colors' option so you know ahead of time what the colors are, or b) search the SVG for the bar and locate its color that way.

Surya Vempati

unread,
Dec 1, 2011, 6:35:35 AM12/1/11
to google-visua...@googlegroups.com
Thank you for the response.
But the problem is .. colors option will give the same color to all the bars in the chart.. i means if i give
red and blue as colors then all the first bars would be in red and the second bars in the column chart would be red.
this is what i dont want..

i want both the bars in same color on certain condition which i want to set dynamically..

I tried to do it using SVGRectElement but the problem is i dont know which API i should be used.. ..
If you have any idea.. pl let me know..

BR,
Surya

On Thu, Dec 1, 2011 at 2:02 AM, asgallant <drew_g...@abtassoc.com> wrote:
The API does not expose any methods of getting the bars' colors after the chart is drawn.  You can either a) set the colors using the chart's 'colors' option so you know ahead of time what the colors are, or b) search the SVG for the bar and locate its color that way.

--
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/-/TyUhwoCRHGsJ.
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.

Roni Biran

unread,
Dec 1, 2011, 8:37:50 AM12/1/11
to google-visua...@googlegroups.com
Hi there Surya,

Is it possible for you to rearrange your data in advance, so that the data will be sorted in a way that the charts will know how to deal with it. So that in that case you will not have to drill into the SVG?

asgallant

unread,
Dec 1, 2011, 11:58:18 AM12/1/11
to google-visua...@googlegroups.com
If you want to dynamically change the color of bars, use a DataView, and sort your data into different View columns depending on what color you want the bars to be.  Here's an example function that splits a column's data into two columns depending on whether they are greater than or less than a threshold value, and then draws the chart (uses jQuery to merge options objects, but there are other ways if you don't use jQuery):

function colorChange (data, chart, options, threshold) {
    var view = new google.visualization.DataView(data);
    view.setColumns([0, {
        calc: function (dataTable, rowNum) {
            return (dataTable.getValue(rowNum, 1) > threshold) ? dataTable.getValue(rowNum, 1) : null;
        },
        type: 'number',
        label: data.getColumnLabel(1)
    }, {
        calc: function (dataTable, rowNum) {
            return (dataTable.getValue(rowNum, 1) <= threshold) ? dataTable.getValue(rowNum, 1) : null;
        },
        type: 'number',
        label: data.getColumnLabel(1)
    }]);
    chart.draw(view, jQuery.extend({}, options, {colors: ['#FF0000', '#0000FF']}));
}
Reply all
Reply to author
Forward
0 new messages