The string is not valid JSON, which is the problem. The strings internal to the JSON have to be double-quoted, eg: ['Time','Temperature', 'Humidity']should be ["Time","Temperature", "Humidity"]
On Thursday, February 20, 2014 6:33:34 PM UTC-5, [email protected] wrote: > > Same results. Ie, nothing. > > > getData.php outputs : [ ['Time','Temperature', 'Humidity'], ['2014-02-20 > 01:06:21',68.54,51.9],['2014-02-20 01:09:09',68.18,59.9],['2014-02-20 > 01:12:16',67.64,68.6],['2014-02-20 01:15:14',67.64,73.9],['2014-02-20 > 01:19:06',67.82,66.1],['2014-02-20 01:21:13',67.28,61.7],.... > > maybe a better way to phrase the question is: > > If I do : > > var jsonData = <?php include 'getData.php' ?> ; > > everything works. > > If I do : > > var jsonData = $.ajax({ > url: "getData.php", > dataType:"json", > async: false > }).responseText; > > It does not work. However at that point : > > document.write(jsonData); > > outputs the exact same thing as getData.php does. > > > > On Thursday, February 20, 2014 3:25:43 PM UTC-8, asgallant wrote: >> >> If your PHP is generating something like this: >> >> { >> "cols": [ >> {"id":"","label":"Topping","pattern":"","type":"string"}, >> {"id":"","label":"Slices","pattern":"","type":"number"} >> ], >> "rows": [ >> {"c":[{"v":"Mushrooms","f":null},{"v":3,"f":null}]}, >> {"c":[{"v":"Onions","f":null},{"v":1,"f":null}]}, >> {"c":[{"v":"Olives","f":null},{"v":1,"f":null}]}, >> {"c":[{"v":"Zucchini","f":null},{"v":1,"f":null}]}, >> {"c":[{"v":"Pepperoni","f":null},{"v":2,"f":null}]} >> ] >> } >> >> then you need to use the regular DataTable constructor instead of the >> arrayToDataTable method: >> >> var data = new google.visualization.DataTable(JSON.parse(jsonData)); >> >> If it is an array of data instead, you need to remove the "new" keyword >> from the line I posted previously: >> >> var data = google.visualization.arrayToDataTable(JSON.parse(jsonData)); >> >> On Thursday, February 20, 2014 5:50:50 PM UTC-5, [email protected] wrote: >>> >>> Tried that. No change. But it feels like the right direction to look in. >>> That jquery code is exactly from the php example. The difference is it uses >>> google.visualization.DataTable instead of arrayToDataTable. Is there a >>> change to the jquery I need to make so it passes back whatever >>> arrayToDataTable wants? Again worth noting that just sourcing the >>> getData.php code instead of the jsonData variable name works fine. That >>> just leads to the kludge of having to reload the whole page to refresh the >>> chart. >>> >>> I guess the other way to go is to add a bunch of extra code in >>> getData.php to add all the extra quotes and commas and useless metadata and >>> output a DataTable instead of an array. Just feels like pointless work. >>> >>> >>> >>> >>> On Thursday, February 20, 2014 2:38:50 PM UTC-8, asgallant wrote: >>>> >>>> The responseText property of the AJAX call gives the string value of >>>> the returned data, which is not usable by the arrayToDataTable method. >>>> Assuming jsonData is a valid JSON string for a javascript array, you need >>>> to call JSON.parse on jsonData: >>>> >>>> var data = new >>>> google.visualization.arrayToDataTable(JSON.parse(jsonData)); >>>> >>>> On Thursday, February 20, 2014 4:41:35 PM UTC-5, [email protected]: >>>>> >>>>> Im trying to get the basic PHP example to work. >>>>> >>>>> >>>>> This is what I want to work, but does not: >>>>> >>>>> function drawChart() { >>>>> var jsonData = $.ajax({ >>>>> url: "getData.php", >>>>> dataType:"json", >>>>> async: false >>>>> }).responseText; >>>>> >>>>> // Create our data table out of JSON data loaded from server. >>>>> var data = new google.visualization.arrayToDataTable(jsonData); >>>>> >>>>> my getData.php does some sql and parsing. If I do this instead, it >>>>> works fine, just only once since its php instead of a jquery ajax call : >>>>> >>>>> function drawChart() { >>>>> >>>>> // Create our data table out of JSON data loaded from server. >>>>> var data = new google.visualization.arrayToDataTable( <?php include >>>>> 'getData.php'; ?> ) >>>>> >>>>> If I do >>>>> >>>>> var jsonData = $.ajax({ >>>>> url: "getData.php", >>>>> dataType:"json", >>>>> async: false >>>>> }).responseText; >>>>> >>>>> document.write(jsonData); >>>>> >>>>> >>>>> // Create our data table out of JSON data loaded from server. >>>>> var data = new google.visualization.arrayToDataTable( PASTE STUFF >>>>> HERE ); >>>>> >>>>> and then run it once to cut and paste the output into PASTE STUFF HERE >>>>> then it works fine. If I actually use the jsonData variable as in the >>>>> example, it does not work. What newb mistake am I making here? >>>>> >>>>> >>>>> >>>>> -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/google-visualization-api. For more options, visit https://groups.google.com/groups/opt_out.
