2 Replies Latest reply on Sep 11, 2018 7:52 PM by revdave

    I need some help with arrays and google charts add rows

    revdave Level 1

      Hi all,

       

      I am trying to set up a google scatter chart page from these links...

       

      https://developers.google.com/chart/interactive/docs/gallery/scatterchart

      and create data table here...

      https://developers.google.com/chart/interactive/docs/drawing_charts#chart.draw

       

      Basically I have the basic demo copy working.

      Now I am trying to populate the data table with time and date data like this...

      add rows like this...

      // Create the data table.

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

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

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

            data.addRows([

       

         // this raw text works

         [22,5],[10,24],[9,5],[10,6],[10,7],[7,8]

        

        

         // but my var - datetime  from database not working 

        //Error: Every row given must be either null or an array.

       

        datetime

       

       

       

           ]);

      If I manually type in this:

      [22,5],[10,24],[9,5],[10,6],[10,7],[7,8]

      it works.

       

      Now I am trying to query a database - then do a .each loop to get the data...

      //Query the dataase...

      // query here..

      datetime = "";

      $.each(data, function(key, value) {

       

      //note: each row comes in from the database like:

      //thedate: "02/17/2018" thetime: "18:00:00"

       

      //then I split to just get basic hour and day

       

      t = value.thetime.split(":")

      d = value.thedate.split("/")

       

      //and create as numbers

       

      tnum = parseInt(t[0]);

      dnum = parseInt(d[1]);

       

      //and add to the datetime var

       

      datetime += "["+ dnum + ","+ tnum + "],"

       

      // there was more code to eliminate last ","

      // then the end result var datetime looks something like:

       

      //[22,5],[10,24],[9,5],[10,6],[10,7],[7,8]

       

       

      If I manually paste this: [22,5],[10,24],[9,5],[10,6],[10,7],[7,8] into the add rows area - it works, however if just paste the datetime var into the same add rows area. the error says:

      Error: Every row given must be either null or an array.

       

      Q: I'm sure I am missing something basic, such as the graph needs numbers that may be showing as strings or something else. Is there something to change to get the graph to accept my datetime var?

       

      Thanks very much for any help with this issue...