Google Charts - Change individual bar color

后端 未结 9 1462
走了就别回头了
走了就别回头了 2020-12-10 01:36

With Google Charts bar graph, is it possible to to change the color of one bar. For example I\'d like to make the 2006 data red (other bars are blue).

 funct         


        
9条回答
  •  粉色の甜心
    2020-12-10 02:07

    You could always insert an extra column and so it will have different color. Thats all that can be done I guess.

    function drawVisualization() {
      // Create and populate the data table.
      var data = new google.visualization.DataTable();
                data.addColumn('string', 'Year');
                data.addColumn('number', 'Sales');
                data.addColumn('number', 'SalesMax');
    
                data.addRows(4);
                data.setValue(0, 0, '2004');
                data.setValue(0, 1, 1000);
                data.setValue(0, 2, 0);
    
                data.setValue(1, 0, '2005');
                data.setValue(1, 1, 1170);
                data.setValue(1, 2, 0);
    
      /* NEED TO MAKE THIS BAR RED? */
                data.setValue(2, 0, '2006');
                data.setValue(2, 1, 0);
                data.setValue(2, 2, 1400);
    
                data.setValue(3, 0, '2007');
                data.setValue(3, 1, 1030);
                data.setValue(3, 2, 0);
    
    
                var chart = new google.visualization.BarChart(document.getElementById('visualization'));
                chart.draw(data, {width: 400, height: 240, title: 'Company Performance',
                                  vAxis: {title: 'Year', titleTextStyle: {color: 'red'}},
                                  series: [{color: 'blue', visibleInLegend: true}, {color: 'red', visibleInLegend: false}]
                                 });
    } 
    

提交回复
热议问题