Hello all,
I'm trying to use goole line chart to plot some information that i've
stored in a MYSQL data base, but it is not working. The chart is not
plotted.
If I copy the line chart code it works fine, so I don't think there is a
problem with my browser.
I"m using Chrome version 50, MAMP version 3.5, and Netbeans 8.1 as my IDE.
I've successfully plotted the chart with the barcode chart code, but I need
a line chart.
Follow my code, and I'm not find any problem in it, but, since the line
chart is not being plotted I'm guessing that there is a mistake that I
can't find or recognise.
<?php
$dsn = 'mysql:host=localhost; port=3306; dbname=trctaguatinga';
$username = 'root';
$password = '';
try{
$pdo = new PDO($dsn, $username, $password,[
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
]);
} catch (PDOException $ex) {
echo $ex -> getMessage();
die();
}
//importando dados de um arquivo CSV
//Abre o Arquivo no Modo r (para leitura - r de read)
$arquivo =fopen ('dados_consumo.csv', 'r');
//Lê o conteúdo do arquivo
while (!feof($arquivo)){
//Pega os dados da linha
$linha = fgets($arquivo,1024);
// Divide as Informações das celular para poder salvar
$dados = explode(',', $linha);
// Verifica se o Dados Não é o cabeçalho ou não esta em branco
if($dados[0] !='mes' && !empty($linha)){
$stmt = $pdo -> query ('INSERT INTO contaagua (mes, consumo)
VALUES ("'.$dados[0].'", "'.$dados[1].'")');
}
}
fclose ($arquivo);
$query = $pdo -> query ('select * from contaagua');
$meses = array ();
$consumos = array();
$j = 0;
$cor = array ();
while ($row = $query -> fetch(PDO::FETCH_OBJ)){
$meses[$i] = $row -> mes;
$consumos [$i] = $row -> consumo;
$i = $i + 1;
}
print_r ($meses) . print_r ($consumos);
?>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"
/>
<script type="text/javascript"
src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript">
google.charts.load('current', {'packages':['corechart']});
google.charts.setOnLoadCallback(drawChart);
function drawChart() {
var data = google.visualization.arrayToDataTable([
<?php
$k = $i;
for ($i = 0; $i < $k; $i++){
?>
[<?php echo $meses[$i] ?>, <?php echo $consumos[$i]?>],
<?php } ?>
]);
var options = {
title: 'Company Performance',
curveType: 'function',
legend: { position: 'bottom' }
};
var chart = new
google.charts.Line(document.getElementById('curve_chart'));
chart.draw(data, options);
}
</script>
</head>
<body>
<div id="curve_chart" style="width: 900px; height: 500px"></div>
</body>
</html>
Follow the information that is being retrieved from the data base.
Array
(
[] => 2015-06-01
[1] => 2015-07-01
[2] => 2015-08-01
[3] => 2015-09-01
[4] => 2015-10-01
[5] => 2015-11-01
[6] => 2015-12-01
[7] => 2016-01-01
[8] => 2016-02-01
[9] => 2016-03-01
[10] => 2016-04-01
[11] => 2016-05-01
)
Array
(
[] => 482
[1] => 446
[2] => 529
[3] => 526
[4] => 540
[5] => 480
[6] => 555
[7] => 451
[8] => 515
[9] => 512
[10] => 512
[11] => 513
)
11
Can anyone help me solve this issue?
Regards
Alex
--
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 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/0fafb6f5-d703-4d5d-ab26-45c2352a7e5e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.