This:

{ role : 'style' }

is a problem.  It should be this:

{ "role" : "style" }

Also, the railing comma at the end of the array is a problem for IE:

[["Sensor", "Temp", { role : 'style' }], ["Baby",71.15,"green"], 
["Main",71.2616,"green"], ["A",75.425,"green"], ["C",69.575,"blue"], 
["D",60.6866,"blue"],] <-- this comma

If you build your data as an array in PHP and use json_encode, it will take 
care of all of the nitty-gritty stuff for you, so you don't have to deal 
with it.  As an example, this PHP would output your array in the correct 
format:

$myArray = array(
    array('Sensor', 'Temp', array('role' => 'style')),
    array('Baby', 71.15, 'green'),
    array('Main', 71.2616, 'green'),
    array('A', 75.425, 'green'),
    array('C', 69.575, 'blue'),
    array('D', 60.6866, 'blue')
);
echo json_encode($myArray);

If you need more help with this, perhaps you could post your PHP code and I 
could help you get it to output the correct format?

On Tuesday, February 25, 2014 12:24:30 AM UTC-5, [email protected] wrote:
>
> While more cumbersome than just dealing with the basic data in an array, 
> Ive beeen outputting a DataTable for multiple charts and gotten it working 
> fine. I have still not gotten an array through arrayToDataTable even once 
> however.
>
> Ive used single quotes, double quotes, json_encode, JSON.parse, and many 
> other things in every possible combination, but nothing formats things the 
> way that arrayToDataTable wants if I use jquery at all.
>
> The array looks like :
>
> [["Sensor", "Temp", { role : 'style' }], ["Baby",71.15,"green"], 
> ["Main",71.2616,"green"], ["A",75.425,"green"], ["C",69.575,"blue"], 
> ["D",60.6866,"blue"],]
>
> This is for a column chart, and I cannot find a way get the third data 
> column to work with a DataTable call, I suspect due to none of the listed 
> "types" working for that column.  If I plug in the array directly into 
> arrayToDataTable it works like a charm. But now I'm back to banging my head 
> against some way to force arrayToDataTable to take input from jquery. 
>
> So Im back to... 
>
> this works:
>
> var data = new google.visualization.arrayToDataTable(  [["Sensor", 
> "Temp", { role : 'style' }], ["Baby",71.15,"green"], 
> ["Main",71.2616,"green"], ["A",75.425,"green"], ["C",69.575,"blue"], 
> ["D",60.6866,"blue"],] );
>  
> this works :
>
> var data = new google.visualization.arrayToDataTable ( <?php include 
> 'getData-roombars2.php'?>); 
>
> (also looks identical to above when viewed as html source in browser)
>
>
> This does not work:
>
> var jsonData = $.ajax({
>          url: "getData-roombars2.php",
>          dataType:"json",
>         async: false
>          }).responseText;
>
>
>
>         var data = new google.visualization.arrayToDataTable( jsonData );
>
>
> If I do a json_encode on the php side, I get :
>
> " [[\"Sensor\", \"Temp\", { role : 'style' }], 
> [\"Baby\",74.1866,\"green\"], [\"Main\",74.075,\"green\"], 
> [\"A\",75.7616,\"green\"], [\"C\",72.5,\"green\"], 
> [\"D\",60.0116,\"blue\"],]"
>
> but then neither  var data = new google.visualization.arrayToDataTable( 
> jsonData ); nor  var data = new google.visualization.arrayToDataTable( 
> JSON.parse(jsonData) ); work.
> If I use JSON.parse on the javascript side, it just makes an array of each 
> of the characters in the string instead of an array of the elements since 
> it cant seem to figure out which commas to use.
> Ive also tried double quotes on the role: "style", but that makes no 
> difference. 
>
> So, my question boils down to .... if my getData-roombars2.php script is 
> going to output something like :
> [["Sensor", "Temp", { role : 'style' }], ["Baby",71.15,"green"], 
> ["Main",71.2616,"green"], ["A",75.425,"green"], ["C",69.575,"blue"], 
> ["D",60.6866,"blue"],]
>
> What does the
>   
>  var jsonData = $.ajax({
>          url: "getData-roombars2.php",
>          dataType:"json",
>          });.responseText;
>
> need to make jsonData the right format for arrayToDataTable?
>
> Ive tried your
>
>  $.ajax({
>          url: "getData-roombars2.php",
>          dataType:"json",
>          success : function (jsonData) {
>                 var data = new google.visualization.DataTable(jsonData);
>                 // draw chart(s) with data
>                 }
>
>          });
>
> Which works fine if I can get the PHP script to output all the extra non 
> functional meta data correctly for a DataTable, But since I cant find 
> documentation on how to do the 'type' for the third data column in a column 
> chart, Im forced back to outputting an array. I'd like to be able to use 
> array's since they are a much simpler anyhow, which would seem to be the 
> point of arrayToDataTable. 
>
>
>
>
>
>
>
>
> On Thursday, February 20, 2014 1:41:35 PM UTC-8, [email protected] wrote:
>>
>> 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?
>>  
>>
>>
>>
> On Thursday, February 20, 2014 1:41:35 PM UTC-8, [email protected] wrote:
>>
>> 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.

Reply via email to