Search code examples
javascriptchartsgoogle-visualization

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 lowest value:

enter image description here

Those are the options I provided:

    let options = {
      legend: 'none',
      candlestick: {
        risingColor: {stroke: '#4CAF50', fill: 'white'},
        fallingColor: {stroke: '#F44336'}
      }
    }

You can try it on this jsFiddle: https://jsfiddle.net/El_Matella/h5p36t3w/2/

I can't find in the documentation how to change it, does someone have an idea? (https://developers.google.com/chart/interactive/docs/gallery/candlestickchart)


Solution

  • 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);
    
    function drawChart() {
      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);
    }
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
    <div id="chart_div" style="width: 900px; height: 500px;"></div>