Zawartość pliku wykres3.php
<?php ), ); while($row = mysqli_fetch_assoc($sth)) { // date assumes "yyyy-MM-dd" format $year = (int) $dataArr[0]; $month = (int) $dataArr[1] - 1; // subtract 1 to make month compatible with javascript months $day = (int) $dataArr[2]; )); } $json = json_encode($results, JSON_PRETTY_PRINT);
<html> <head> <!--Load the Ajax API--> <script type="text/javascript"> // Load the Visualization API and the piechart package. google.load('visualization', '1', {'packages':['corechart']}); // Set a callback to run when the Google Visualization API is loaded. google.setOnLoadCallback(drawChart); function drawChart() { // Create our data table out of JSON data loaded from server. var data = new google.visualization.DataTable(<?php echo $json ?>); var options = { title: 'Cena paliw', is3D: 'true', width: 800, height: 600 }; // Instantiate and draw our chart, passing in some options. // Do not forget to check your div ID var chart = new google.visualization.LineChart(document.getElementById('chart_div')); chart.draw(data, options); } </script> </head> <body> <!--this is the div that will hold the pie chart--> </body> </html>
Polecenie echo $json; daje:
Kod
{ "cols": [ { "label": "data", "type": "date" }, { "label": "cenaon", "type": "number" } ], "rows": [] }
Tabela Bazy danych wygląda tak:
Kod
Host: localhost
Baza danych: latino_orlen
Czas wygenerowania: 27 Lut 2016, 09:58
Wygenerowany przez: phpMyAdmin 4.0.10.7 / MySQL 5.6.23
Zapytanie SQL: SELECT * FROM `ceny` LIMIT 0, 30;
Rekordy: 4
id data cenaon
19 2016-02-24 2.939
20 2016-02-25 2,99
21 2016-02-26 2.95
22 2016-02-27 2.964
Baza danych: latino_orlen
Czas wygenerowania: 27 Lut 2016, 09:58
Wygenerowany przez: phpMyAdmin 4.0.10.7 / MySQL 5.6.23
Zapytanie SQL: SELECT * FROM `ceny` LIMIT 0, 30;
Rekordy: 4
id data cenaon
19 2016-02-24 2.939
20 2016-02-25 2,99
21 2016-02-26 2.95
22 2016-02-27 2.964
Struktura tabeli:
Kod
Kolumna Typ Null
id int(11) Nie
data date Nie
cenaon varchar(100) Nie
id int(11) Nie
data date Nie
cenaon varchar(100) Nie
Co robię źle? Pomoże ktoś? Z góry dziękuję
