You must be logged in to post your query.
Home › Forums › Chart Support › candlestick chart with mysql
Tagged: chart candlestick mysql
hello everyone, my name is rizki,really need help, i want to make candlestick from mysql and show it to the page ihave one table named harga consist of id,open,low,close,high
this is the data.php to take the value from mysql
<?php
header(‘Content-Type: application/json’);
$con = mysqli_connect(“127.0.0.1″,”root”,””,”saham”);
// Check connection if (mysqli_connect_errno($con)) { echo “Failed to connect to DataBase: ” . mysqli_connect_error(); }else { $data_points = array();
$result = mysqli_query($con, “SELECT * FROM harga”);
while($row = mysqli_fetch_array($result)) { $point = array(“x” => $row[‘tanggal’] , “y” => $row[‘open’],$row[‘low’],$row[‘high’],$row[‘close’]);
array_push($data_points, $point); }
echo json_encode($data_points, JSON_NUMERIC_CHECK); } mysqli_close($con);
?>
and this is web page
<!DOCTYPE HTML> <html> <head> <script type=”text/javascript”> $(document).ready(function () {
$.getJSON(“data.php”, function (result) { var chart = new CanvasJS.Chart(“chartContainer”, { title: { text: “Basic Candle Stick Chart” }, zoomEnabled: true, axisY: { includeZero: false, title: “Prices”, prefix: “$ ” }, axisX: { interval: 2, intervalType: “month”, valueFormatString: “MMM-YY”, }, data: [ { type: “candlestick”, dataPoints: result
} ] }); chart.render(); } </script> <script src=”../../canvasjs.min.js”></script> <title>CanvasJS Example</title> </head> <body> <div id=”chartContainer” style=”height: 400px; width: 100%;”> </div> </body> </html>
i am really stuck did not know what to do,really need help,thanks in advance
kiukiu
What is the problem that you are facing? Are you getting some error?
Thanks Bivek Singh, I have try it but did not work,the real problem is the chart not reloading and the page just in blank,, hope any solution then,,
data_points must be array of objects. So, each element inside an array must be an object. y value should be an array of 4 values not just comma separated value.
Also, try with following things and check if there is some error:
-> echo $result and see if it is returning a value from DB -> echo $data_points to check if you have the value in prescribed format.
You must be logged in to reply to this topic. Login/Register