Ok, that is a bit different from what I thought you were doing. The
ColorFormatter should work for the Table, but it won't do anything for the
ColumnChart.
You can modify the DataView to accommodate your ranges and additional
columns:
var view = new google.visualization.DataView(data);
view.setColumns([0, 1, {
type: 'string',
role: 'style',
calc: function (dt, row) {
// buffer colors
var val = dt.getValue(row, 1);
if (val > 200) {
return '#d51711'; // max
}
else if (> 50) {
return '#11d517'; // min
}
else {
return '#f9f107'; // all others
}
}
}, 2, {
type: 'string',
role: 'style',
calc: function (dt, row) {
// cpu colors
var val = dt.getValue(row, 1);
if (val > 85) {
return '#d51711'; // max
}
else if (> 70) {
return '#11d517'; // min
}
else {
return '#f9f107'; // all others
}
}
}, 3, {
type: 'string',
role: 'style',
calc: function (dt, row) {
// memory colors
var val = dt.getValue(row, 1);
if (val > 85) {
return '#d51711'; // max
}
else if (> 70) {
return '#11d517'; // min
}
else {
return '#f9f107'; // all others
}
}
}]);
Use this view to draw the ColumnChart only.
On Friday, June 27, 2014 1:30:36 PM UTC-4, Nagendra Singh wrote:
>
> //THIS IS MY JS PAGE
>
>
> google.load('visualization', '1.1', {packages:
> ['corechart','controls','table']});
> google.setOnLoadCallback(drawChart);
> function drawChart() {
> var jsonData = $.ajax({
> url: "/RestartSpringRestService/rest/allIndicator",
> dataType: "json",
> async: false
> }).responseText;
>
>
> var jsonObj = JSON.parse(jsonData);
> // Create our data table out of JSON data loaded from server.
> var size = 0;
> for(var sizeCount in jsonObj){
> size++;
> }
> var dataArray = new Array(size+1);
> dataArray[0] = new Array(4);
> dataArray[0][0] = 'Date';
> dataArray[0][1] = 'Buffer';
> dataArray[0][2] = 'Cpu';
> dataArray[0][3] = 'Memory';
>
>
> //dataArray[0][2] = {type:'string', role:'tooltip'};
> var i = 1;
>
> while(i < size+1){
> dataArray[i] = new Array();
> //dataArray[i][1] = (jsonObj[i].siteIndicatorColor);
> dataArray[i][0] =new Date(jsonObj[i].dateOfOccurence);
> dataArray[i][1] = (jsonObj[i].bufferCount);
> dataArray[i][2] = (jsonObj[i].cpu);
> dataArray[i][3] = (jsonObj[i].memory);
>
> i++;
>
> }
>
>
> var data = new google.visualization.arrayToDataTable(dataArray);
>
>
> var options = {
>
> is3d: true,
> //colors: ['green','red','yellow'],
> bar: { groupWidth: '3%' },
> title: 'Date vs. CriticalParameters comparison', titleTextStyle:
> {color: '#DF0101', bold: true},
> width: 1000, height: 450,
> vAxis: {minValue: 0},
> hAxis: {title: 'Date', titleTextStyle: {color: '#08088A', bold:
> true}},
> legend: { position: 'top', maxLines: 4 }
> };
>
> var chart = new
> google.visualization.ColumnChart(document.getElementById('ColumnChart'));
> var table = new
> google.visualization.Table(document.getElementById('TableChart'));
> var formatter1 = new google.visualization.ColorFormat();
> formatter1.addRange(200, null, 'white', 'red');
> formatter1.addRange(50, 200, 'black', 'yellow');
> formatter1.addRange(0, 50, 'white', 'green');
> formatter1.format(data, 1);
> var formatter2 = new google.visualization.ColorFormat();
> formatter2.addRange(85, 100, 'white', 'red');
> formatter2.addRange(70, 85, 'white', 'orange');
> formatter2.addRange(0, 70, 'white', 'green');
> formatter2.format(data, 2);
> formatter2.format(data, 3);
> table.draw(data, {allowHtml: true, showRowNumber: true});
> chart.draw(data, options);
> }
>
>
>
>
> ------------------------------------------------------------------------------
>
> I am using formatter now, but I have hardcoded the value for high, low and
> medium. I need to read high, low and medium values from the properties file
> inside the project. Or as an alternative, if out of the three params
> (bufferCount, cpu and memory) any one is high it should show red , orange
> for medium and green for low..
>
> If you have a solution, you can make my day.. Please help...
>
>
> On Fri, Jun 27, 2014 at 10:48 PM, Andrew Gallant <[email protected]
> <javascript:>> wrote:
>
>> 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 <[email protected]>
>>> 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
>>>> [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.
>>>>
>>>
>>> --
>> 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
>> [email protected] <javascript:>.
>> To post to this group, send email to [email protected]
>> <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 [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.