Reputation: 607
I'm using morris donuy chart and I'm not able to pass my json array data to the jquery corectly I think. Here is my php file:
$stmt=$dbh->prepare("Select COUNT(Incasari.id_produs) as cnt,Incasari.id_produs,denumire_produs from Incasari
INNER JOIN Produse on Produse.id_produs=Incasari.id_produs Group By Incasari.id_produs order by cnt desc limit 3 ");
$stmt->execute();
while ($row=$stmt->fetch())
{
$arr[]= array(
'id' => ''.$row['id_produs'].'',
'denumire' => ''.$row['denumire_produs'].'',
'cnt' => ''.$row['cnt'].''
);
}
echo json_encode($arr);
The returned result is:
[{"id":"3","denumire":"bere","cnt":"5"},
{"id":"1","denumire":"Suc","cnt":"3"},
{"id":"2","denumire":"pepsi","cnt":"2"}]
And the javascript part:
$(document).ready(function(){
$.ajax({
url: 'app/chart_produse.php', // getchart values
dataType: 'JSON',
type: 'POST',
data: {get_values: true},
success: function(response) {
var donut = new Morris.Donut({
element: 'sales-chart',
resize: true,
colors: ["#3c8dbc", "#f56954", "#00a65a"],
data: response,
hideHover: 'auto'
});
}
});
});
Upvotes: 1
Views: 6058
Reputation: 2741
Your format of passing data is not right.http://morrisjs.github.io/morris.js/donuts.html According to Moris donut documentation
The data to plot. This is an array of objects, containing
label
andvalue
attributes corresponding to the labels and sizes of the segments of the donut chart.
Upvotes: 1