Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change row color from cell value in google visualization table

I have a google visualization table with some numerical and some non numerical columns. I need a JavaScript function that will change the color of the whole google visualization row based on the value of a cell in the row.

I am already able to change the color of the numerical cell using the colorformater but I need to also change the color of the remaining cells of the row.

like image 901
Ioannis Antonellis Avatar asked Sep 14 '12 19:09

Ioannis Antonellis


People also ask

How do you change the color of a line in a Google graph?

You can change the color of the lines that connect data points in Google Charts in two subtly different ways: with the colors option to change the chart palette, or with the series option to specify the color for particular series. In the following chart, we set the color of each series explicitly.

How do I change the color of a bar graph in Google?

To change the colors assigned to data series in a specific chart: Select that chart, then on the right, open the STYLE tab. In the Color by section, select Series order, Bar order, or Slice order, depending on the type of chart. Click a color box to set the color for each series.

What is arrayToDataTable?

arrayToDataTable()This helper function creates and populates a DataTable using a single call. Advantages: Very simple and readable code executed in the browser.


1 Answers

Hey I just had the same problem as you and I was able to hack together a response. I'm sure there is a better way to do this, but it works for me.

Use the data.setProperty tag and you can do that for each column of the row you are working on. So if you know the row number, which I assume you do since you can do it for just the one column using the colorformater, you can do this easily.

dataTable.setProperty(0, 0, 'style', 'background-color: red;');
dataTable.setProperty(0, 1, 'style', 'background-color: red;');

The first parameter is the row index, so that should stay constant, and the next parameter is the column index, so just loop this through all of your columns. And then you should be able to change the background-color to any css style.

Hope that helps!

like image 146
Pompey Avatar answered Sep 29 '22 18:09

Pompey