Home › Forums › Chart Support › Issues retrievng data from MySql › Reply To: Issues retrievng data from MySql
No luck, it renders in the same way, without the lables…
here is the query:
$data_points = array(); $result = mysqli_query($con, "SELECT Tipus_1 AS Tipus, COUNT(*) AS 'Count' FROM values GROUP BY Tipus_1 ORDER BY Count"); while($row = mysqli_fetch_array($result)) { $point = array("label" => $row['Tipus_1'] , "y" => $row['Count']); array_push($data_points, $point); } echo json_encode($data_points, JSON_NUMERIC_CHECK);
here is the js file:
var dataPoints = []; $.getJSON("tipus_recursos.php", function (result) { for(var i = 0; i <= result.length-1; i++) { dataPoints.push({label: result[i].Tipus_1, y: parseInt(result[i].y)}); } var chart = new CanvasJS.Chart("chartContainer2", { data: [ { type: "pie", dataPoints: dataPoints } ] }); chart.render(); });