Skip to content Skip to sidebar Skip to footer

Google Chart Candlestick Colors

I am trying to customize candlecharts from google charts. I have found how to change the color of the candle themselves, but not the one of the line indicating the highest and lowe

Solution 1:

if you want all the lines to be the same color, you can use the colors option...

see following working snippet...

google.charts.load('current', {'packages':['corechart']});

google.charts.setOnLoadCallback(drawChart);

functiondrawChart() {
  var data = google.visualization.arrayToDataTable([
    ['Mon', 20, 28, 38, 45],
    ['Tue', 31, 38, 55, 66],
    ['Wed', 50, 55, 77, 80],
    ['Thu', 77, 77, 66, 50],
    ['Fri', 68, 66, 22, 15]
    // Treat first row as data as well.
  ], true);

  var options = {
    legend:'none',
    candlestick: {
      risingColor: {stroke: '#4CAF50', fill: 'white'},
      fallingColor: {stroke: '#F44336'}
    },
    colors: ['magenta']
  };

  var chart = new google.visualization.CandlestickChart(document.getElementById('chart_div'));

  chart.draw(data, options);
}
<scripttype="text/javascript"src="https://www.gstatic.com/charts/loader.js"></script><divid="chart_div"style="width: 900px; height: 500px;"></div>

Solution 2:

As I'm using jQuery for other stuff and still no official solutions (afaik) from Google, I ended up with this:

jQuery('div[id*="chart_div"] svg g g[clip-path] g:nth-of-type(3) g' ).each(function() {
    jQuery(this).find('rect:first-of-type').attr('fill',jQuery(this).find('rect:nth-of-type(2)').attr('fill'));
});

(Please note the official examples have only one chart, mine page has several, hence each one has a unique id like chart_div_uniqueid, so evertything wrapped into a .each.)

Post a Comment for "Google Chart Candlestick Colors"