Hi everyone,

Yesterday I played around with google charts. 
It's nice and powerful, buth I had some troubles loading information from 
my mySQL database.
My files are similar as yours so I post them here hoping somebody can help 
me out:

html page (with just a few values in data.addRows :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
   <head>
    <script type="text/javascript" 
src="https://www.google.com/jsapi?autoload={'modules':[{'name':'visualization','version':'1','packages':['annotationchart']}]}"></script>
    <script type='text/javascript'>
      google.load('visualization', '1', {'packages':['annotationchart']});
      google.setOnLoadCallback(drawChart);
      function drawChart() {
        var data = new google.visualization.DataTable();
       data.addColumn('date', 'Date');
       data.addColumn('number', 'Download volume');
       data.addColumn('number', 'Upload volume');
      data.addRows([
          
          // <?php include 'getData.php'; ?> NOT WORKING
          [new Date(2014,09,08), 0, 0],[new Date(2014,09,08), 346, 104]   
// just a few > original index.html includes all data
  
   ]);

       var chart = new 
google.visualization.AnnotationChart(document.getElementById('chart_div'));

        var options = {
          displayAnnotations: true
        };

        chart.draw(data, options);
      }
    </script>
  </head>

  <body>

Question:
index.html is working. The values in data.addRows are a copy paste of the 
result of the getData.php (created through the test.php).
index_not_working.html has the include getData.php that creates exactly the 
same data as the test.php, but the data are not loaded..

I'm quite new in programming and have no clue what's going wrong. 
Anybody any idea what's going wrong?

thanks!

Kasper


Op donderdag 24 juli 2014 14:52:12 UTC+2 schreef Romain Bernard:
>
> Hi Everyone,First of all, I'd like to thank you all for being so helpful!Here 
> is my concern. I'm trying to build an PHP page that render a Annotation 
> chart from a query done on a Mysql DB.
>
> I tried many examples found in the forums to make an annotation chart 
> working, but I miserably fail to have it working...
>
> I always get this error, and even if mysql_num_rows() is deprecated, I 
> cannot find a way to have it replaced
>
> *Warning*: mysql_num_rows() expects parameter 1 to be resource, object 
> given in 
> */Applications/XAMPP/xamppfiles/htdocs/server1/Result_console4.php* on 
> line *11*
>
> Is anyone able to provide me some help ?
>
>
> Thanks a lot!
>
> Romain
>
> Here is the entire code of my php page.
>
> <?php
>
> //DB connection parameters
>
> require_once("mysql_connect.php");
>
>
> $result = mysqli_query($con,"select date,value1,value2 from DATABASE");
>
>
> if ($result !== false) {
>
> $num=mysql_num_rows($result);
>
> $i=0;
>
> echo"";
>
>
> $output = Array();
>
> while ($i < $num) {
>
>     $DateTimeArray=explode(' ', mysql_result($result,$i,"date"));
>
>     $MYvalue1=mysql_result($result,$i,"value1");
>
>     $MYvalue2=mysql_result($result,$i,"value2");
>
>     
>
>     $dateArray = explode('-', $DateTimeArray[0]);
>
>     $year = $dateArray[0];
>
>     $month = $dateArray[1] - 1; // adjust for javascript's 0-indexed months
>
>     $day = $dateArray[2];
>
>     
>
>     $timeArray = explode(':', $DateTimeArray[1]);
>
>     $hours = $timeArray[0];
>
>     $minutes = $timeArray[1];
>
>     $seconds = $timeArray[2];
>
>     
>
>     $output[] = "[new 
> Date($year, $month, $day, $hours, $minutes, $seconds), $MYvalue1, $MYvalue2]";
>
>     $i++;
>
> }
>
> }
>
>
> ?>
>
>
>
> <html>
>
>   <head>
>
>   </head>
>
>       <script type='text/javascript' src='http://www.google.com/jsapi
> '></script>
>
>     <script type='text/javascript'>
>
>       google.load('visualization', '1.1', 
> {'packages':['annotationchart']});
>
>       google.setOnLoadCallback(drawChart);
>
>       function drawChart() {
>
>         var data = new google.visualization.DataTable();
>
>         data.addColumn('datetime', 'Date');
>
>         data.addColumn('number', 'value1');
>
>         data.addColumn('number', 'value2');
>
>         data.addRows([ <?php echo implode(',', $output); ?>]);
>
>
>         var chart = new 
> google.visualization.AnnotationChart(document.getElementById('chart_div'));
>
>
>         var options = {
>
>           displayAnnotations: true,
>
>         };
>
>
>         chart.draw(data, options);
>
>       }
>
>     </script>
>
>
>   <body>
>
>   
>
>   Graph should be here.
>
>   
>
>     <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 google-visualization-api+unsubscr...@googlegroups.com.
To post to this group, send email to google-visualization-api@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

<<attachment: getData.php>>

<<attachment: test.php>>

Reply via email to