Graphic with Google Charts

Asked

Viewed 845 times

0

How can I fill this chart with Mysql data?

<?php
$sql = 'SELECT * FROM historicos';
$resultado = mysqli_query($conn, $sql); 
?>
<script type="text/javascript">
  google.charts.load('current', {'packages':['corechart']});
  google.charts.setOnLoadCallback(drawChart);

  function drawChart() {
    var data = google.visualization.arrayToDataTable([
      ['Horario', 'Sales'],
      ['2004',  0.500],
      ['2005',  0.1],
      ['2006',  0.200],
      ['2007',  0.30]
    ]);

    var options = {
      title: 'Company Performance',
      curveType: 'function',
      legend: { position: 'bottom' }
    };

    var chart = new google.visualization.LineChart(document.getElementById('curve_chart'));

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

After a few adjustments it worked.. ` Function drawChart() { var data = google.visualization.arrayToDataTable([ ['Horario', 'Response time'], ]);

`

  • Welcome to Stack Overflow! What have you tried to do? So your question is very broad.

1 answer

0


just replace

function drawChart() {
var data = google.visualization.arrayToDataTable([
  ['Horario', 'Sales'],
  ['2004',  0.500],
  ['2005',  0.1],
  ['2006',  0.200],
  ['2007',  0.30]
]);

for something like that

function drawChart() {
var data = google.visualization.arrayToDataTable([
  ['Horario', 'Sales'],
  <?php 
    $sql="sua query";
    $query=mysqli_query($con,$sql);
    while($result=mysqli_fetch_array($query,MYSQLI_ASSOC)){
      echo "['".$result['campo1']."', '.$result['campo2']."'],";
    }
  ?>
]);

of course this in a php file

  • It didn’t work, it stayed that way. Function drawChart() { var data = google.visualization.arrayToDataTable([ ['Time', 'Time'], <?php $sql = 'SELECT * FROM historicos'; $query=mysqli_query($Conn, $sql); while($result=mysqli_fetch_array($query,MYSQI_ASSOC)){ echo "['". $result['Data']. ', '.$result['Time']." '],"; } ? > ]);

  • runs your php in the browser and looks at the source code as it looks and puts here for me to see please

  • Thanks for the feedback, I’m new here at stackoverflow, how can I put the source here? Something else, it is loading the data in the font, now just not showing the chart..

  • edits your original post makes a trace delimiting the post and the new information and put as Cod block

  • It worked, just like you sent it, I just made a few adjustments...

  • I just don’t know how to put the information..

  • bequeathed that it worked , clika no V ali in my post par Adar as concluded. to post a block of code you put the symbol of Craze your code codigo Voce tbm can use the site Pastebin.org to post the source Cod of your website and dai vc poe the link here.

  • Okay, thank you very much. Hug.

Show 3 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.