Hi trying to create this array dynamically. This is the static way:
var pieData = [
{
value: 300,
color:getRandomColor(),
highlight: getRandomColor(),
},
{
value: 50,
color: getRandomColor(),
highlight: "#fac878",
},
{
value: 100,
color: getRandomColor(),
highlight: getRandomColor(),
},
{
value: 120,
color: getRandomColor(),
highlight: getRandomColor(),
}
];
This is what I achieved:
$.ajax({
method: "POST",
url: "getPieChartData"
})
.done(function(data){
obj = $.parseJSON(data);
var pieData = []; i = 0;
$.each(obj, function(key, item) {
pieData[i].value = item.total + " - " + item.d_name;
pieData[i].color = getRandomColor();
pieData[i].highlight = getRandomColor();
i++;
});
});
I am getting value from my function that is not a problem. My issue is that I am getting in the console that this part:
pieData[i].value = item.total +" - " + item.d_name; TypeError: pieData[i] is undefined
What am I doing wrong? thx