Hi plz help, I tried to generate a chart using database data but it doesn’t work
Html…………
<!DOCTYPE html>
<html >
<head>
<title>Untitled Document</title>
<script type=”text/javascript” src=”canvasjs.min.js”></script>
<script src=”source/jquery.js”></script>
<script type=”text/javascript” src=”source/canvasjs.js”></script>
<script type=”text/javascript”>
$(document).(function () {
$.getJSON(“data.php”, function (result) {
var chart = new CanvasJS.Chart(“chartContainer”, {
data: [
{
dataPoints: result
}
]
});
chart.render();
});
});
</script>
</head>
<body>
<title></title>
</body>
</html>
PHP……………………..
<?php
$servername = “localhost”;
$username = “root”;
$password = “”;
$dbname = “assignment2”;
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die(“Connection failed: ” . $conn->connect_error);
}
header(‘Content-Type: application/json’);
$data_points = array();
$sql = “SELECT * FROM power1 sales”;
$result = mysqli_query($conn,$sql);
if (!$result) {
echo ‘MySQL Error: ‘ . mysqli_error($conn);
}
;
while($row = mysqli_fetch_array($result))
{
$point = array(“label” => $row[‘product’] , “y” => $row[‘total_sales’]);
array_push($data_points, $point);
}
echo json_encode($data_points, JSON_NUMERIC_CHECK);
mysqli_close($con);
?>