How to get jsontable (created via PHP) to genereate Line Graph via google chart ?

42 views
Skip to first unread message

Eriovaldo Andrietta

unread,
Jun 1, 2018, 10:47:01 AM6/1/18
to Google Visualization API
Why this code is not working fine ?
I have the php code that generates do jsontable but I cannot use it in the html?
Any idea ?

<html>
 <head>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
  <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
  <script type="text/javascript">
   google.charts.load('current', {'packages':['corechart']});
   google.charts.setOnLoadCallback(drawChart);
   function drawChart()
   {
    var data = new google.visualization.DataTable(<?php
$conn = oci_connect('eri', 'senha123', 'localhost/orcl');
if (!$conn)  {
$erro = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
$query = oci_parse($conn, "select tipo, tempo from eri");
oci_execute($query);
$rows = array();
$table = array();
$table['cols'] = array(
array('label' => 'tipo', 'type' => 'string'),
array('label' => 'tempo', 'type' => 'int'),
);
$rows = array();
while($r = oci_fetch_array($query, OCI_ASSOC+OCI_RETURN_NULLS)) {
$temp = array();
$temp[] = array('v' => (string) $r['TIPO']);
$temp[] = array('v' => (int) $r['TEMPO']); 
$rows[] = array('c' => $temp);
}
$table['rows'] = $rows;
$jsontable = json_encode($table);
echo $jsontable;
?>
);

    var options = {
     title:'Sensors Data',
     legend:{position:'bottom'},
     chartArea:{width:'95%', height:'65%'}
    };

    var chart = new google.visualization.LineChart(document.getElementById('line_chart'));
    chart.draw(data, options);
   }
  </script>
  <style>
  .page-wrapper
  {
   width:1000px;
   margin:0 auto;
  }
  </style>
 </head>  
 <body>
  <div class="page-wrapper">
   <br />
   <h2 align="center">SHOW 1 - Display Google Line Chart with JSON PHP & Oracle </h2>
   <div id="line_chart" style="width: 100%; height: 500px"></div>
  </div>
 </body>
</html>

Eriovaldo Andrietta

unread,
Jun 1, 2018, 11:55:12 AM6/1/18
to Google Visualization API
The issue is : the html code is not executing the php code.

Daniel LaLiberte

unread,
Jun 1, 2018, 12:10:15 PM6/1/18
to Google Visualization API
Hi Eriovaldo,

Not many people on this list can help you with PHP, myself included.

But since the PHP code executes on your server, where it generates HTML and JS which is sent to the browser where it is interpreted, it would help to see what HTML and JS is generated by the PHP.  Can you look in your browser's debugger and view the source?  It might become clear to you what happened in your PHP.  

--
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-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-visualization-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/4d530bf7-5bde-45ff-81f2-206ec4084ec9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--

Eriovaldo Andrietta

unread,
Jun 1, 2018, 4:54:19 PM6/1/18
to Google Visualization API
Thanks Daniel.
You are right.
There is an error in the sintaxe.
I fixed it but I cannot see the data yet.
I will try anothers ways.

Regards
Eriovaldo


Em sexta-feira, 1 de junho de 2018 11:47:01 UTC-3, Eriovaldo Andrietta escreveu:

Eriovaldo Andrietta

unread,
Jun 1, 2018, 9:14:09 PM6/1/18
to Google Visualization API
I don´t know how to make available the variable json with data generated by php in the javascript/html code.
I supose that if I generate if via php , the data must be available for code.
It is not happeging. This is the sintaxe error in the javascript.

Tks
Eriovaldo


Em sexta-feira, 1 de junho de 2018 11:47:01 UTC-3, Eriovaldo Andrietta escreveu:

Eriovaldo Andrietta

unread,
Jun 3, 2018, 8:48:54 AM6/3/18
to Google Visualization API
Hi All,

My issue is solved.
I just put it in the php code:

header('Access-Control-Allow-Origin: *');

Thanks.
Eriovaldo



Em sexta-feira, 1 de junho de 2018 11:47:01 UTC-3, Eriovaldo Andrietta escreveu:
Reply all
Reply to author
Forward
0 new messages