Hi I'm getting my data with ajax, they are coming with json so my code is this
$.ajax({
async:true,
type: "POST",
dataType: "html",
contentType: "application/x-www-form-urlencoded",
url:"http://sosacelulares.com/index.php/chart/buygeneralreport",
success: function(response) {
var returnedData = JSON.parse(response);
The data looks like this
[{
"id_buy_report":"1",
"month":"1",
"year":"2016",
"total":"10"
},{
"id_buy_report":"2",
"month":"1",
"year":"2017",
"total":"20"
}]
Then I am trying to use that data to create a Pie Chart and the complete code is this:
$.ajax({
async:true,
type: "POST",
dataType: "html",
contentType: "application/x-www-form-urlencoded",
url:"http://sosacelulares.com/index.php/chart/buygeneralreport",
success: function(response) {
var returnedData = JSON.parse(response);
var donutData = [
{label: "Series2", data: 10},
{label: "Series3", data: 40},
{label: "Series4", data: 50}
];
$.plot("#donut-chart", donutData, {
series: {
pie: {
show: true,
radius: 1,
innerRadius: 0.5,
label: {
show: true,
radius: 2 / 3,
formatter: labelFormatter,
threshold: 0.1
}
}
},
legend: {
show: false
}
});
The problem is that my data are coming how you can see from a database and if i want to create the Pie Chart I need to put the data here..
var donutData = [
{label: "Series2", data: 10},
{label: "Series3", data: 40},
{label: "Series4", data: 50}
];
It will create a pie chart with three portions, but it is static i need to put a (for loop) to allow the data create automaticly..
How can I make a for loop in that donutData code? any loop it's no necessary a for loop..I need just a loop that it allows me to fill donutData automaticly. Thanks