Scatter Chart Example

An example of a Google Scatter Chart.

by adamovic

HTML

<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
       <div id="chart_div" style="width: 400px; height: 200px;"></div>
       
       <div id="click" style="background-color: #aaa; padding: 5px; border: 1px solid blue; cursor: pointer; display: inline-block; ">
       Click Me
       </div>

JavaScript

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

      google.charts.setOnLoadCallback(function() {
        var data = google.visualization.arrayToDataTable([
          ['Age', 'Weight'],
          [ 8,      12],
          [ 4,      5.5],
          [ 11,     14],
          [ 4,      5],
          [ 3,      3.5],
          [ 6.5,    7]
        ]);

        var options = {
          title: 'Age vs. Weight comparison',
          hAxis: {title: 'Age', minValue: 0, maxValue: 15},
          vAxis: {title: 'Weight', minValue: 0, maxValue: 15},
          legend: 'none'
        };

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

        chart.draw(data, options);
      });
      });