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 Area Chart

Area charts are used to draw area based charts.

An area chart is rendered within the browser using SVG or VML.

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


Basic Area Chart

The following example shows how to draw a basic area 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([ ['Year', 'Sales', 'Expenses'], ['2016', 1000, 400], ['2017', 1170, 460], ['2018', 660, 1120], ['2019', 1030, 540] ]); // Set chart options var options = { title: 'Company Performance', hAxis: {title: 'Year'}, vAxis: {minValue: 0} }; // Display the chart inside the <div> element with id="chart-div" var chart = new google.visualization.AreaChart(document.getElementById('chart-div')); chart.draw(data, options); }


Stacked Area Chart

By default, the area chart draws the series on top of one another.

You can stack them atop one another instead, so that the data values at each x-value are summed.

To stack them atop one another use isStacked configuration option and set it to true:

// Set chart options var options = { title: 'Company Performance', hAxis: {title: 'Year'}, vAxis: {minValue: 0}, isStacked: true };
Run code

Animated Area 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 = { title: 'Company Performance', hAxis: {title: 'Year'}, vAxis: {minValue: 0}, 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