user3711703
user3711703

Reputation: 1

How to set the background color of specific cells of a table chart on a Google Site?

I need to set the background color of specific cells of a table. Here is the Google Apps Script code that I am using to draw the table in Google Site. How can I set the color of, say, first column of last row to red?

<script type='text/javascript' src='https://www.google.com/jsapi'></script>
<script type='text/javascript'>
  google.load('visualization', '1', {packages:['table']});
  google.setOnLoadCallback(drawTable);
  function drawTable() {
    var data = new google.visualization.DataTable();
    data.addColumn('string', 'Name');
    data.addColumn('number', 'Salary');
    data.addColumn('boolean', 'Full Time Employee');
    data.addRows([
      ['Mike',  {v: 10000, f: '$10,000'}, true],
      ['Jim',   {v:8000,   f: '$8,000'},  false],
      ['Alice', {v: 12500, f: '$12,500'}, true],
      ['Bob',   {v: 7000,  f: '$7,000'},  true]
    ]);

    var table = new google.visualization.Table(document.getElementById('table_div'));
    table.draw(data, {showRowNumber: true});
  }
</script>

Upvotes: 0

Views: 1875

Answers (1)

dan.m.kumar
dan.m.kumar

Reputation: 838

There is a function called setBackgroundColor(color) in the api https://developers.google.com/apps-script/reference/document/table-cell#setBackgroundColor%28String%29

You can only set the color of individual cells, so you will have to run it through a loop to color an entire column or row.

It returns a TableCell type, so I'm guessing the logic would be

currentCell.setBackgroundColor("red");

Just a guess.

Upvotes: 1

Related Questions