You can use a DataView to make this dynamic:

// get min/max from column 1
var range = data.getColumnRange(1);
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 == range.max) {
              return '#d51711'; // max
         }
         else if (val == range.min) {
              return '#11d517'; // min
         }
         else {
              return '#f9f107'; // all others
         }
    }
}]);

You need to recalculate range whenever your data changes.  Use view in 
place of data when drawing the chart.

On Friday, June 27, 2014 1:08:29 PM UTC-4, Nagendra Singh wrote:
>
> I meant color based on value... I do not need to hard code it.. My values 
> changes dynamically.
>
>
> On Fri, Jun 27, 2014 at 10:14 PM, Andrew Gallant <asgall...@gmail.com 
> <javascript:>> wrote:
>
>> Use a "style" role column to color your bars:
>>
>> var data = google.visualization.arrayToDataTable([
>>     ['Name', 'Value', {role: 'style', type: 'string'}],
>>     ['High', 50, '#d51711'],
>>     ['Medium', 25, '#f9f107'],
>>     ['Low', 10, '#11d517']
>> ]);
>>
>>
>> On Friday, June 27, 2014 3:02:01 AM UTC-4, Nagendra Singh wrote:
>>>
>>> Hi all, 
>>> How can we apply color to a bar as red whenever it is high?
>>>
>>> Like a bar which has the highest value should be always red, and medium 
>>> value should have yellow and at last lowest value as green..
>>>
>>> Please suggest a way as soon as possible....
>>>
>>  -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Google Visualization API" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/google-visualization-api/UMGeagSZ8eo/unsubscribe
>> .
>> To unsubscribe from this group and all its topics, send an email to 
>> google-visualization-api+unsubscr...@googlegroups.com <javascript:>.
>> To post to this group, send email to google-visua...@googlegroups.com 
>> <javascript:>.
>> Visit this group at 
>> http://groups.google.com/group/google-visualization-api.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to