Home › Forums › Chart Support › How can I use PHP MySQL Dynamic data › Reply To: How can I use PHP MySQL Dynamic data
hi, i tried those example above but my chart didn’t render at all
this is my json
`<?php header(‘Content-Type: application/json’);
session_start();
$element = $_POST[‘name’]; $year = $_POST[‘nama’]; $post = $_POST[‘name’] . $_POST[‘nama’];
include ‘koneksi.php’;
$data_points = array();
$query = mysql_query(“select nilai,tanggal from $post where bulan = 1 order by tanggal asc”); while ($row = mysql_fetch_array($query)) { $nila [$row[‘tanggal’]] = $row[‘nilai’]; $point = array(“x” => $row[‘tanggal’] , “y” => $row[‘nilai’]); array_push($data_points, $point); }
echo json_encode($data_points, JSON_NUMERIC_CHECK); header( “refresh:5;url=chart.php” );
?> and it returns
[{“x”:1,”y”:49},{“x”:10,”y”:”53,7″},{“x”:11,”y”:”51,3″},{“x”:12,”y”:”52,7″},{“x”:13,”y”:”46,3″},{“x”:14,”y”:”69,5″},{“x”:15,”y”:”65,3″},{“x”:16,”y”:”64,7″},{“x”:17,”y”:”60,8″},{“x”:18,”y”:”59,4″},{“x”:19,”y”:59},{“x”:2,”y”:”60,7″},{“x”:20,”y”:”45,5″},{“x”:21,”y”:”55,7″},{“x”:22,”y”:”48,4″},{“x”:23,”y”:”44,4″},{“x”:24,”y”:”49,4″},{“x”:25,”y”:”44,5″},{“x”:26,”y”:”55,3″},{“x”:27,”y”:”57,9″},{“x”:28,”y”:”51,9″},{“x”:29,”y”:”52,6″},{“x”:3,”y”:73},{“x”:30,”y”:”56,9″},{“x”:31,”y”:”69,4″},{“x”:4,”y”:”73,6″},{“x”:5,”y”:”56,3″},{“x”:6,”y”:”54,9″},{“x”:7,”y”:”60,3″},{“x”:8,”y”:”58,8″},{“x”:9,”y”:”51,3″}]
and then it’s my html
<!DOCTYPE html> <html> <head> <title>JSON test</title> <script src=”jquery/jquery.js”></script> <script src=”canvasjs.js”></script> <script type=”text/javascript”> $(document).ready(function () { $.getJSON(“jsonparser.php”, function (result) { var chart = new CanvasJS.Chart(“chartContainer”, { data: [ { type:’line’, dataPoints: result } ] }); chart.render(); }); }); </script> </head> <body> body test <div id=”chartContainer” style=”width: 800px; height: 380px;”></div> </body> </html>
<!DOCTYPE html> <html> <head> <title>JSON test</title> <script src=”jquery/jquery.js”></script> <script src=”canvasjs.js”></script> <script type=”text/javascript”> $(document).ready(function () {
$.getJSON(“jsonparser.php”, function (result) {
var chart = new CanvasJS.Chart(“chartContainer”, { data: [ { type:’line’, dataPoints: result } ] });
chart.render(); }); }); </script> </head> <body> body test <div id=”chartContainer” style=”width: 800px; height: 380px;”></div>
</body> </html>
and its not rendering, is something missing or something wrong with my code???thank you in advance