I am trying to make a line graph using google chart from sql database, but 
the coding just shows a blank page. I need a graph which shows date and 
price from my database.Below is the coding:

<html>
>   <head>
>     <!--Load the AJAX API-->
>     <script type="text/javascript" 
> src="https://www.google.com/jsapi";></script>
>     <script type="text/javascript">
>
>       // Load the Visualization API and the piechart package.
>       google.load('visualization', '1.0', {'packages':['corechart']});
>
>       // Set a callback to run when the Google Visualization API is loaded.
>       google.setOnLoadCallback(drawChart);
>
>       // Callback that creates and populates a data table,
>       // instantiates the pie chart, passes in the data and
>       // draws it.
>       
>     
>   function drawChart() {
>     // use explicit DataTable construction instead of arrayToDataTable 
>     var data = new google.visualization.DataTable();
>     data.addColumn('date', 'Datee');
>     data.addColumn('number', 'Generic22K');
>     data.addRows([
>  <?php
>            ///Connect
> $con=mysqli_connect("*****","****","****","****");
> // Check connection
> if (mysqli_connect_errno()) {
>   echo "Failed to connect to MySQL: " . mysqli_connect_error();
> }
> $sql_data = mysqli_query($con, 'SELECT * FROM *** order by Datee desc 
> limit 10');
> if (!$sql_data)
> {
> die('can not cnct to price');
> }
>
>                  while($result = mysqli_fetch_array($sql_data)) {
>                 $t1 = strtotime($result['Datee']);
>                 // convert date into javascript date object: new 
> Date(year, month, day) 
>                 $year = date("Y",$t1);
>                 $month = date("m",$t1) - 1; // need to zero-index the month
>                 $day = date("d",$t1);
>                 $output[] = "[new Date($year, $month, $day), 
> {$result['Generic22K']}]";
>             }
>             echo implode(',', $output);
>         ?>
>
>     ]);
>
>     var options = {
>         title: 'Sales  Analysis',
>         vAxis: {title: "Generic22K"},
>         hAxis: {title: "Datee"}  // also got rid of an errant comma here 
>     };
>
>
>     var chart = new 
> google.visualization.LineChart(document.getElementById('chart_div'));
>     chart.draw(data, options);
> }? 
>
>     </script>
>   </head>
>
>   <body>
>     <!--Div that will hold the pie chart-->
>     <div id="chart_div"></div>
>   </body> 

</html>

Note: Astricks put above is to hide private data.

When i execute only this php code: 

>   <?php
>            ///Connect
> $con=mysqli_connect("*****","****","****","****");
> // Check connection
> if (mysqli_connect_errno()) {
>   echo "Failed to connect to MySQL: " . mysqli_connect_error();
> }
> $sql_data = mysqli_query($con, 'SELECT * FROM *** order by Datee desc 
> limit 10');
> if (!$sql_data)
> {
> die('can not cnct to price');
> }
>
>                  while($result = mysqli_fetch_array($sql_data)) {
>                 $t1 = strtotime($result['Datee']);
>                 // convert date into javascript date object: new 
> Date(year, month, day) 
>                 $year = date("Y",$t1);
>                 $month = date("m",$t1) - 1; // need to zero-index the month
>                 $day = date("d",$t1);
>                 $output[] = "[new Date($year, $month, $day), 
> {$result['Generic22K']}]";
>             }
>             echo implode(',', $output);
>         ?>

It Works and gives following output:
 

>     [new Date(2014, 5, 17), 25924.878571429],[new Date(2014, 5, 16), 
> 25924.878571429],[new Date(2014, 0, 29), 7000],[new Date(2014, 0, 28), 
> 7000],[new Date(2014, 0, 27), 7000],[new Date(2014, 0, 26), 8000],[new 
> Date(2014, 0, 25), 4000],[new Date(2014, 0, 24), 566],[new Date(2014, 0, 
> 05), 5645],[new Date(2014, 0, 04), 556] 

But when i execute whole code, it shows up a blank page.       

-- 
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