Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I need some help with arrays and google charts add rows

Contributor ,
Sep 09, 2018 Sep 09, 2018

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...

3.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 09, 2018 Sep 09, 2018

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

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

Neither Time or Date are numbers, they are either STRING's or, better, TIME and DATE. Also Time and Date are reserved terms that cannot be used as the name for a column. Use MyTime and MyDate or similar.

Wappler is the DMXzone-made Dreamweaver replacement and includes the best of their powerful extensions, as well as much more!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 11, 2018 Sep 11, 2018
LATEST

Hi Ben - Thanks for this info - I'll check into this.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines