You can use a DataView to add in a "style" role column that sets the color
according to the value of the data point:
// assumes you have a DataTable "data" with two columns
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
type: 'string',
role: 'style',
calc: function (dt, row) {
var val = dt.getValue(row, 1);
if (val < 10) {
return 'red';
}
else if (val < 20) {
return 'yellow';
}
else {
return 'green';
}
}
}]);
You can return any valid HTML color string for the style. Use the view to
draw your chart instead of the DataTable.
On Thursday, July 24, 2014 12:53:53 PM UTC-4, Mirko Nulla wrote:
>
> Hello,
> I need to make the bars colour change according to particular values
> related to specific ranges.
> For example every value between null and 10 must give the red colour,
> between 10 and 20 the yellow one etc.
>
> I tried to use .view() with the calc function without any success. Was it
> the right way?
> Finally how can I do it?
>
--
You received this message because you are subscribed to the Google Groups
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.