Google Charts
Google Charts Introduction Getting Started Area Charts Bar Charts Bubble Charts Calendar Charts Candlestick Charts Column Charts Combination Chart Gauge Chart Geo Charts Histogram Charts Line Charts Maps Organization Chart Pie Charts Sankey Charts Scatter Charts Stepped Area Charts Table Chart Trendline Charts Wordtree Charts

Google Candlestick Chart

A candlestick chart is used to show an opening and closing value overlaid on top of a total variance.

Candlestick charts are often used to show stock value behavior.

In this chart, items where the opening value is less than the closing value (a gain) are drawn as filled boxes, and items where the opening value is more than the closing value (a loss) are drawn as hollow boxes.

A candlestick chart is rendered within the browser using SVG or VML.

Like all Google charts, candlestick charts display tooltips when the user hovers over the data.


Basic Candlestick Chart

The following example shows how to draw a basic candlestick chart, using google charts API:


Example Explained

First add a <div> element with the id "chart-div" and set width and height:

<!DOCTYPE html> <html lang="en-US"> <body> <div id="chart-div" style="width:100%; height:350px;"></div> </body> </html>

Then add a reference to the Chart API:

<script src="https://www.gstatic.com/charts/loader.js"></script>

Finally add a JavaScript function:

// Load the corechart package and set a callback google.charts.load('current', {'packages':['corechart']}); google.charts.setOnLoadCallback(drawChart); // Callback that creates and populates a data table function drawChart() { // Create the data table 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] ], true); // Treat first row as data as well // Set chart options var options = { legend: 'none' }; // Display the chart inside the <div> element with id="chart-div" var chart = new google.visualization.CandlestickChart(document.getElementById('chart-div')); chart.draw(data, options); }


Waterfall charts

With the right set of options, candlestick charts can be made to resemble simple waterfall charts.

Set bar.groupWidth to '100%' to remove the space between the bars.

// Set chart options var options = { legend: 'none', bar: { groupWidth: '100%' }, // Remove space between bars. candlestick: { fallingColor: { strokeWidth: 0, fill: '#902C2C' }, // brown risingColor: { strokeWidth: 0, fill: '#2DEC84' } // green } };
Run code

Animated Candlestick Chart

Google charts can animate smoothly in one of two ways, either on startup when you first draw the chart, or when you redraw a chart after making a change in data or options.

To animate on startup:

  • Set your chart data and options. Be sure to set an animation duration and easing type
  • Set animation: {startup: true} — setting this in your options will cause your chart to start with series values drawn at the baseline, and animate out to their final state

Here is a simple example which animate smoothly on startup:

// Set chart options var options = { legend: 'none', animation: { duration: 2000, easing: 'out', startup: true } };
Run code

To animate a transition:

  • Start with an already rendered chart
  • Modify the data table or options
  • Specify the transition behavior using the animation option
  • Call chart.draw() on your chart to transition to the new values

Here is a simple example which changes the values presented in a chart upon each click on a button:

Click the button to animate chart:

Run code