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

Scatter charts plot points on a graph.

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

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

Basic Scatter Chart

The following example shows how to draw a basic scatter 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=""></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([ ['Age', 'Weight'], [ 8, 12], [ 4, 5.5], [ 11, 14], [ 4, 5], [ 3, 3.5], [ 6.5, 7] ]); // Set chart options var options = { title: 'Age vs. Weight comparison', hAxis: {title: 'Age', minValue: 0, maxValue: 15}, vAxis: {title: 'Weight', minValue: 0, maxValue: 15}, legend: 'none' }; // Display the chart inside the <div> element with id="chart-div" var chart = new google.visualization.ScatterChart(document.getElementById('chart-div')); chart.draw(data, options); }

Creating Material Scatter Charts

Material Scatter Charts have many small improvements over Classic Scatter Charts, including variable opacity for legibility of overlapping points, an improved color palette, clearer label formatting, tighter default spacing, softer gridlines and titles (and the addition of subtitles).

Creating a Material Scatter Chart is similar to creating what we'll now call a "Classic" Scatter Chart.

You load the Google Visualization API (although with the 'scatter' package instead of the 'corechart' package):

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

And then create an object (but of class google.charts.Scatter instead of google.visualization.ScatterChart):

var chart = new google.charts.Scatter(document.getElementById('chart-div')); chart.draw(data, google.charts.Scatter.convertOptions(options));
Run code

Material Charts will not work in old versions of Internet Explorer. (IE8 and earlier versions don't support SVG, which Material Charts require.)

Animated Scatter 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 = { 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