Thats working for me now.  I had left out the 2 in my getdata2.php url when 
testing. Silly mistake.

Formatting the string as you described was the solution.

Thanks for your help.

Vincent

On Wednesday, 16 April 2014 13:37:41 UTC+1, Andrew Gallant wrote:
>
> The JSON string works for me: http://jsfiddle.net/asgallant/p64fm/
>
> There is probably a problem with your AJAX call.  Call 
> console.log(jsonData) and check the contents of the developer's console 
> in Chrome or Firefox to see what jsonData contains.
>
> On Tuesday, April 15, 2014 7:13:11 PM UTC-4, Vincent_IRE wrote:
>
> Hi, 
>
> Tried that.  Got the output you described. getdata2.php output now. 
>
> { "cols": [{"label": "name","type": "string"},{"label": "up","type": 
> "number"}],"rows" : [{"c":[{"v": "Google"},{"v": 1}]},{"c":[{"v": 
> "mercury"},{"v": 2}]}]}
>
>  Code playground still says that the "table has no columns"?  
>
> Any ideas?
>
> This is my getdata2.php
>
> <?php
> mysql_connect('localhost','root','*******') or die("Cannot connect to 
> host");
> mysql_select_db('DBname');
> $query="select name,up from sites";
> $result=mysql_query($query);
> $resultJsonString=MakeJSONFormatForChart($result);
> echo $resultJsonString;
> ?>
> <?php
>         function MakeJSONFormatForChart($results){
>                 $resultString = "";
>                 $resultString = MakeColumnsBlock($results,$resultString);
>   $resultString = $resultString . '"rows" : [';
>                 $rows=array();
>                 while($r=mysql_fetch_array($results)){
>                         $rows[]='{"c":[{"v": "'.$r['name'].'"},{"v": 
> '.$r['up'].'}]}';                   
>                 }
>                 $resultString = $resultString . implode(',', $rows)."]}";
>                 return $resultString;
>         }
>                 function MakeColumnsBlock($results,$resultString){
>                 $resultString = '{ "cols": [{"label": "name","type": 
> "string"},{"label": "up","type": "number"}],';
>                 return $resultString;
>         }
> ?>
>
> This is my chart.html
>            <html>
>   <head>
>     <!--Load the AJAX API-->
>     <script type="text/javascript" src="https://www.google.com/jsapi";></
> script>
>     <script type="text/javascript" src="//
> ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
>     <script type="text/javascript">    
>     // Load the Visualization API and the piechart package.
>     google.load('visualization', '1', {'packages':['corechart']});      
>     // Set a callback to run when the Google Visualization API is loaded.
>     google.setOnLoadCallback(drawChart);   
>     function drawChart() {
>       var jsonData = $.ajax({
>         url: "localhost/servermonitor/getdata2.php",
>           dataType:"json",
>           async: false
>           }).responseText;
>       // Create our data table out of JSON data loaded from server.
>       var data = new google.visualization.DataTable(jsonData<span 
> style="color:rgb(102,102,102);font-family:monospace;white
>
> ...

-- 
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/d/optout.

Reply via email to