Home › Forums › Chart Support › Issues retrievng data from MySql › Reply To: Issues retrievng data from MySql
I have compare them, and the only difference I find is in the query file not in the js one…
file any_publicacio.js (the one that correctly shows the labels)
$(document).ready(function () {
$.getJSON("any_publicacio.php", function (result) {
var chart = new CanvasJS.Chart("chartContainer1", {
data: [
{
dataPoints: result
}
]
});
chart.render();
});
});
File tipus_recursos.js this one does not shows the labels
$(document).ready(function () {
$.getJSON("tipus_recursos.php", function (result) {
var chart = new CanvasJS.Chart("chartContainer2", {
data: [
{
type: "pie",
dataPoints: result,
indexLabel: "#percent"
}
]
});
chart.render();
});
});
query of the first one, the one that works, file any_publicacio.php
$data_points = array();
$result = mysqli_query($con, "SELECT <code>Any_publicacio</code>, COUNT(*) AS 'Publicacions' FROM <code>values</code> GROUP BY <code>Any_publicacio</code> DESC");
while($row = mysqli_fetch_array($result))
{
$point = array("label" => $row['Any_publicacio'] , "y" => $row['Publicacions']);
array_push($data_points, $point);
}
echo json_encode($data_points, JSON_NUMERIC_CHECK);
query of the second one, the one that does not shows de labels: tipus_recursos.php
$data_points = array();
$result = mysqli_query($con, "SELECT <code>Tipus_1</code> AS Tipus, COUNT(*) AS 'Recursos' FROM <code>values</code> GROUP BY <code>Tipus_1</code> DESC");
while($row = mysqli_fetch_array($result))
{
$point = array("label" => $row['Tipus_1'] , "y" => $row['Recursos']);
array_push($data_points, $point);
}
echo json_encode($data_points, JSON_NUMERIC_CHECK);
The difference in the query is that in the second one I have to put “AS Tipus” otherwise graphic does not renders