I suspect the problem is here:

echo("['".$f[1]."', ".$f[0]."]");


This would create output like this:

['foo', 1]['bar', 2]...

which is not valid javascript syntax, as the arrays have to be separated by 
commas.  Try this instead:

var data = google.visualization.arrayToDataTable([
    ['building', 'Facteur'],
    <?php
        $data = array();
        for($i=0; $i<$n; $i++) {
            $f=pg_fetch_row($query);
            $data[] = array($f[1], (int) $f[0]); // use (int), (float), 
(bool) as appropriate to typecast the data 
        }
        echo json_encode($data);
    ?>
]);

On Tuesday, June 11, 2013 8:39:51 AM UTC-4, armon d wrote:
>
> this is my cod, there is any error but when i test it my page web a empty 
>   ???????
>
>
>
> <?php
>
>
> pg_connect("host=localhost port=5432 dbname=base_test user=postgres 
> password=123456") or die('Could not connect: ' . pg_last_error());
>
>     $q='SELECT "Facteur","building" from "Cout" where site=\'Montmorin\'';
> $query=pg_query($q);
> $n=pg_num_rows($query); 
>  ?> 
>
>
> <html>
>   <head>
>     <script type="text/javascript" src="https://www.google.com/jsapi
> "></script>
>     <script type="text/javascript">
>       google.load("visualization", "1", {packages:["corechart"]});
>       google.setOnLoadCallback(drawChart);
>       function drawChart() {
>         var data = google.visualization.arrayToDataTable([
>           ['building', 'Facteur'],
>           <?php
>    for($i=0; $i<$n; $i++)
> {
> $f=pg_fetch_row($query);
> echo("['".$f[1]."', ".$f[0]."]");
>  }
> ?> 
>           
>         ]);
>
>         var options = {
>           title: 'My Daily Activities'
>         };
>
>         var chart = new 
> google.visualization.PieChart(document.getElementById('chart_div'));
>         chart.draw(data, options);
>       }
>     </script>
>   </head>
>   <body>
>     <div id="chart_div" style="width: 900px; height: 500px;"></div>
>   </body>
> </html> 
>           
>
>

-- 
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?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to