hello, I try set array to dataPoints but that not work, and I don’t know why, maybe somebody can help, thank you
that the code
var models = [];
var cars = [];
var sumMod;
var text;
var count = 0;
var dps = [];
window.onload = function() {
/**RECEIVE json**********/
$(document).ready(function(){
/* call the php that has the php array which is json_encoded */
$.getJSON('androidSortBySumCars.php', function(data) {
/* data will hold the php array as a javascript object */
$.each(data, function(key, val) {
/* $('ul').append('<li id="' + key + '">' + val.model + ' ' + val.counter + '</li>');*/
if(typeof val.model !== "undefined"){// === equal !== not equal
models[count] = val.model;
cars[count++] = val.counter;
}
});
for(var i=0;i<cars.length; i++){
cars[i] =100 * (cars[i]/cars.length);
}
for(var j=0;j<cars.length; j++){
dps.push({
y: cars[j], label: models[j]
});
}
window.alert(dps[0]['y']); //66.66
//window.alert(models);
//window.alert(sum);
});
});
/*End RECEIVE json*/
var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
title: {
text: "Sum of Cars"
},
data: [{
type: "pie",
startAngle: 240,
yValueFormatString: "##0.00\"%\"",
indexLabel: "{label} {y}",
dataPoints: dps
}]
});
chart.render();
}