user3718259
user3718259

Reputation: 15

Google Visualization: Organizational Chart background color for Node not working

I'm using Google Org Chart to create an organisation chart and with different coloured boxes for each person. However, I can't get either the 'style' or 'selectedStyle' to work in the data.setRowProperty for background-color. It works for the border property. I'm new to javascript and google visualization so apologies if this is obvious.

<head>
    <script type='text/javascript' src='https://www.google.com/jsapi'></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {packages:['orgchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
      var data = new google.visualization.DataTable();
      data.addColumn('string', 'Name');
      data.addColumn('string', 'Manager');
      data.addColumn('string', 'ToolTip');
      data.addRows([
        [{v:'Row0', f:'Row0'}, '', 'The President'],
        [{v:'Row1', f:'Row1<div style="color:red; font-style:italic">Vice
                President</div>'}, 'Row0', 'VP'],
          ['Row2', 'Row0', ''],
          ['Row3', 'Row0', ''],
          ['Row4', 'Row0', ''],
          ['Row5', 'Row0', ''],
          ['Row6', 'Row1', 'Bob Sponge']
          ]);
// This works and puts a border round the node
        data.setRowProperty(3, 'style', 'border: 1px solid red');

// Neither of these work
        data.setRowProperty(4, 'style', 'background-color:red');
        data.setRowProperty(5, 'selectedStyle', 'background-color:red');

        var chart = new 
           google.visualization.OrgChart(document.getElementById('chart_div'));
        chart.draw(data, {allowHtml:true});
    }
    </script>
</head>
<body>
    <div id='chart_div'></div>
</body>
</html>

Upvotes: 0

Views: 5596

Answers (2)

ggonzal
ggonzal

Reputation: 147

You should use background:red instead of background-color:red

Upvotes: 1

juvian
juvian

Reputation: 16068

It is working correctly, problem is that the nodes have a background image property, so you do not see it as red. So to be able to view the nodes red, you also need to set the background-image to none. This should work:

      data.setRowProperty(4, 'style', 'background-color:red;background-image:none');
      data.setRowProperty(5, 'selectedStyle', 'background-color:red;background-image:none');

Upvotes: 3

Related Questions