Problem to build dynamic chart with arrayToDataTable ...

1,662 views
Skip to first unread message

Jean Gorene

unread,
Aug 27, 2015, 1:14:52 PM8/27/15
to Google Visualization API
Hello everyone, I need help ... 
I try to build a dynamic chart from the values of a spreadsheet
So, I get my values from this sheet, no problem
Where it gets complicated is with "arrayToDataTable" ... I chose this solution to make it easier ... well it had to be easier :-/
In fact, I'd like to understand why my code works in one case (2) and not in case (1) (which is of course the one that interests me) see below
I probably missed something or I'm doing something wrong (!) ... anyway I do not find a way out of this impasse ... ... ...
Any ideas welcome, thank you in advance !

Case (1) - this not work see image ... there is only one merged column when it should be two ???
function onSuccessStore(values) { 
  var header01 = values[0][0];
  var header02 = values[0][4];
  
  var val = [];
  var columns = ["'" + header01 + "','" + header02 + "'"];
  val.push(columns)
  for (var i = 1 , nb = values.length; i < nb ; i++) {
    var rows = values[i];
    var severity = rows[0];
    var risk = rows[4]
    if ( severity != "" && risk  != "") {
      var value = ["'" + risk + "'," + severity];
      val.push(value);
    }    
  }
  var data = google.visualization.arrayToDataTable(val, false);
... and the next

Case (2) - This works properly (a priori, there is no reason to the contrary)
function onSuccessStore(values) {
// below the exact copy of "val" in output log from case 1
  var val = [ 
    ['Severity 1-4','#'], 
    ['R1',1], 
    ['R2',1], 
    ['R3',1], 
    ['R4',1], 
    ['R5',3.5], 
    ['R6',1.5], 
    ['R7',2.5], 
    ['R8',3]
  ];
  var data = google.visualization.arrayToDataTable(val, false);
... and the next


Case (1).png
Case (2).png

Daniel LaLiberte

unread,
Aug 27, 2015, 1:47:28 PM8/27/15
to Google Visualization API
It looks like your column headers for case 1 are wrong.  You have

  columns = ["'" + header01 + "','" + header02 + "'"];

The comma is in quotes, so you are getting one string rather than two.  Should be:

columns = ["'" + header01 + "'", "'" + header02 + "'"];

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/9c5a4509-84a1-4f53-8ca7-cc2a9e0d9570%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Jean Gorene

unread,
Aug 27, 2015, 2:19:29 PM8/27/15
to Google Visualization API
Hi Daniel,
Thank so much for your help :)
I understand the process, by cons it does not work either and there is no chart that appears !
Bellow the new code
function onSuccessStore(values) {
  var header01 = values[0][0];
  var header02 = values[0][4];
  
  var val = [];
  // var columns = ["'" + header01 + "','" + header02 + "'"];
  var columns = ["'" + header01 + "'", "'" + header02 + "'"];
  val.push(columns)
  for (var i = 1 , nb = values.length; i < nb ; i++) {
    var rows = values[i];
    var severity = rows[0];
    var risk = rows[4]
    if ( severity != "" && risk  != "") {
      var value = ["'" + risk + "'," + severity];
      val.push(value);
    }    
  }
  var data = google.visualization.arrayToDataTable(val, false);

Really, it is to not understanding anything ... I'm above since the beginning of the week ...
I tested, turned, tried to find a solution ... nothing to do!
I really do not understand why it works with the copy of the log ... but not with the output value from the function !?!
Maybe, I do something wrong and I can share the file, no problem ...
Ok, thank you again :)
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA
case (3).png

Daniel LaLiberte

unread,
Aug 27, 2015, 2:45:15 PM8/27/15
to Google Visualization API
Could you point us to your web page that shows what you are seeing?  Either that, or you could create an example in jsfiddle.net.   It is difficult to help you more otherwise.

To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Jean Gorene

unread,
Aug 28, 2015, 8:39:12 AM8/28/15
to Google Visualization API
Ok and sorry ...
Your suggestion works, but like mine with two columns merged, unfortunately.
So I can not make a jsfiddle because the charts are done on modal Dialog html output ... activated from the data on the spreadsheet ... in fact, it's just a test to be used in a support on educational setting. 
Nevertheless, I share the spreadsheet with the script, of course ... 
It's just a very simple basic configuration for test and you will quickly see how it is done and where is the problem ... if you'll look at, of course!
Anyway, thank you again :)
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.

Daniel LaLiberte

unread,
Aug 28, 2015, 9:06:40 AM8/28/15
to Google Visualization API
A lot of context was missing, so it helps to see your actual script for your spreadsheet.  Thanks.

In your ChartOutput.html, this doesn't make sense to me:

google.load('visualization', '1.0', {packages: ['controls']})
google.script.run.withSuccessHandler(onSuccessStore).getData();
google.setOnLoadCallback(onSuccessStore);

function onSuccessStore(values) {
...
}


The google.script.run.withSuccessHandler call is pretty bizarre, but that appears to be the way to do it:  https://developers.google.com/apps-script/guides/html/reference/run#withSuccessHandler(Function)

But if you do that, then the next line doesn't make sense: google.setOnLoadCallback(onSuccessStore);
This would call onSuccessStore yet again, but not pass any argument for the values.

I suspect that what you want is more like this:

google.setOnLoadCallback(onVisualizationLoad);

function onVisualizationLoad() {
  google.script.run.withSuccessHandler(onSuccessStore).getData();
}

function onSuccessStore(values) {
...
}

This will wait for the visualization library to be loaded, call onVisualizationLoad, which then calls the withSuccessHandler as before.


To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualizati...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.

For more options, visit https://groups.google.com/d/optout.



--
dlaliberte@Google.com   5CC, Cambridge MA
daniel.laliberte@GMail.com 9 Juniper Ridge Road, Acton MA

Jean Gorene

unread,
Aug 28, 2015, 10:34:17 AM8/28/15
to Google Visualization API
Yes indeed, thank you ;)
In fact as I built my code, it was redundant and I generates two calls in some ways with 'setOnLoadCallback' and 'google.script.run ...'
Anyway, I'm not a real developer (!) ... but I like scrape to the code with GAZ and visualization API ... because you can do some really amazing things and very convenient with just a spreadsheet !
By cons for now, the result is always the same and out, we still have merged the two columns in the table chart !!
It seems to me that that is not really 'normal' anyway ... but there is probably something that escapes me ... ??
Ok, for now I'm still in limbo ... but I'm learning at the same time;)
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.

Jean Gorene

unread,
Aug 30, 2015, 10:43:52 PM8/30/15
to Google Visualization API
Finally I found a solution here to create a dynamic chart via "dataTable" without using "arrayToDataTable" and it works perfectly !
Anyway, I think there is still a problem where I then misses a trick with "arrayToDataTable" because my function is the same to retrieve values, I just change their format adjust the values for format "dataTable".
Now I have a good solution and that's enough!
Ok Daniel, thank you again for your help ...
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.



--
dlali...@Google.com   5CC, Cambridge MA
daniel.l...@GMail.com 9 Juniper Ridge Road, Acton MA

--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-visualization-api+unsub...@googlegroups.com.

To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
Reply all
Reply to author
Forward
0 new messages