Set a specific color for a specific bar in Google charts - Javascript Google Chart

Javascript examples for Google Chart:Bar Chart

Description

Set a specific color for a specific bar in Google charts

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script> 
      <script type="text/javascript">
    window.onload=function(){/*from   w  w w  . ja  v  a2  s .c  om*/
google.charts.load('current', {'packages':['corechart','bar']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Statistics', 'Amount', { role: 'style' }],
        ['Categories', 5, '#D9534F'],
        ['Posts', 4, '#337AB7'],
        ['Comments', 8, '#5CB85C'],
        ['Users', 3, '#F0AD4E'],
      ]);
    var options = {
      chart: {
        title: 'Analysis',
        subtitle: '',
      },
      bars: 'horizontal' 
    };
    var chart = new google.visualization.BarChart(document.getElementById('barchart_material'));
    chart.draw(data, options);
}
    }

      </script> 
   </head> 
   <body> 
      <div id="barchart_material" style="width: 'auto'; height: 500px;"></div>  
   </body>
</html>

Related Tutorials