I have an issue which hope can get help with. I've read a few tutorials and also a few questions on here but none seem to answer my question. I'm making an ajax request to my PHP file which is coming back with a JSON response something like this for example (console logged output):
{ Email addresses: 4, IP addresses: 2, Names: 1 }
I would like to be able to take this and plot it onto a chart using Chart.js however I have tried:
$.each(res, function(i, item) {
data = {
label: i,
value: item
}
}
var myDoughnutChart = new Chart(ctx).Pie(data);
Problem is it's only filling with one color and one label with one value. Is there any way I can change the the format of the JSON output so it might read:
{ "Label":"Email addresses","Value":"4" }
The change would have to be made using Javascript/JQuery. I must point out the labels aren't always the same as sometimes the JSON output might be different like:
{ Usernames: 3, Passwords: 3, Names: 1 }
Again the above is only what I'm getting when outputting to the console.
How would I also go about charting this maybe using a $.each() in JQuery or other? Any help would be appreciated, sorry for the length of this question.
datawith each iteration of the loop. Trydata.push({label: i, value: item});instead. And make suredatais an array first.