Jump to content
Fórum Script Brasil
  • 0

(Resolvido) Grafico com php e api google


RRH
 Share

Question

Achei um tutorial para gerar gráficos utilizando api do google e estou tentando adaptar inserindo os dados do banco de dados mysql. Vejam o código:

<?php
include "config.php";

$largura = "500";
$altura = "200";

function geraGrafico($largura, $altura, $valores, $referencias, $tipo = "p3"){

$sql = "SELECT turno, COUNT(*) AS total FROM tabela GROUP BY turno ORDER BY total DESC";
 $result = mysql_query($sql);
  while ($linha = mysql_fetch_array($result)) {

$valores .= $linha ['total'].",";
$referencias .= $linha ['turno']."|";
} 

header("Location: http://chart.apis.google.com/chart?chs=". $largura ."x". $altura . "&chd=t:" . $valores . "&cht=p3&chl=" . $referencias);

}
  
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>Gerador de gráficos do Google</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>
    <?php $grafico = geraGrafico($largura, $altura, $valores, $referencias) ?>
    <img src="<?php //echo $grafico ?>" title="Grafico gerado pelo Google Chart" />
  </body>
</html>

O código acima retorna a seguinte url:

chart.apis.google.com/chart?chs=500x200&chd=t:700,439,412,112,&cht=p3&chl=3%20Turno|2%20Turno|4%20Turno|1%20Turno|

O que não consegui foi retirar a ultima "," aqui:

chart.apis.google.com/chart?chs=500x200&chd=t:700,439,412,112,&cht=p3&chl=3%20Turno|2%20Turno|4%20Turno|1%20Turno|

e o último "|" aqui:

chart.apis.google.com/chart?chs=500x200&chd=t:700,439,412,112,&cht=p3&chl=3%20Turno|2%20Turno|4%20Turno|1%20Turno|

para funcionar é necessário ficar assim:

chart.apis.google.com/chart?chs=500x200&chd=t:700,439,412,112&cht=p3&chl=3%20Turno|2%20Turno|4%20Turno|1%20Turno

Edited by RRH
Link to comment
Share on other sites

3 answers to this question

Recommended Posts

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



  • Forum Statistics

    • Total Topics
      150.9k
    • Total Posts
      648.7k
×
×
  • Create New...