JSON into a simple chart

51 views
Skip to first unread message

hefei...@yahoo.com

unread,
Aug 19, 2015, 4:39:58 PM8/19/15
to Google Visualization API
Why is my chart not populating?  I am trying to get data, create columns, loop through row creation, and display the data in a simple chart.  I can't see what is wrong here:

<!DOCTYPE html>

<html>

  <head>

    <!-- EXTERNAL LIBS-->

    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

    <script src="https://www.google.com/jsapi"></script>

 

    <!-- EXAMPLE SCRIPT -->

    <script>

 

      // onload callback

      function drawChart() {

 

        // JSONP request

        var jsonData = $.ajax({

          url: 'https://www.quandl.com/api/v1/datasets/WSJ/FE_TJN.json',

          data: {page: 1},

          dataType: 'json',

        }).done(function (results) {

 

          var data = new google.visualization.DataTable();

 

          data.addColumn('datetime', 'Time');

          data.addColumn('number', 'Price');

      

 

          $.each(results, function (i, row) {

            data.addRow([

              (new Date(row.Date)),

              parseFloat(row.Value)

            ]);

          });

 

var chart = new google.visualization.LineChart($('#chart').get(0));

 

          chart.draw(data, {

            title: 'Prices'

          });

 

        });

 

      }

// load chart lib

      google.load('visualization', '1', {

        packages: ['corechart']

      });

 

      // call drawChart once google charts is loaded

      google.setOnLoadCallback(drawChart);

 

    </script>

 

  </head>

  <body>

    <div id="chart" style="width: 75%;"></div>

  </body>

</html>

Reply all
Reply to author
Forward
0 new messages