Chart.js Doughnut Chart Not Properly Work
I am trying to use chart.js Doughnut chart. my JSON data is properl fetch from data base. But at the fill time of value chart will not display. If i am pasting example code static
Solution 1:
i have done by using this just do this, i'm pasting my code
var doughnutData="";
$.ajax({
type : "POST",
url : contextPath + '/common/action', //contextPath for dynamic
dataType : 'json',
data : {predictionID:oID},
success : function(data) {
var id=newArray();
var name=newArray();
for ( var i = 0; i < data.properties.length; i++) {
id[i]= data.properties[i].id;
name[i]= data.properties[i].name;
}
doughnutData = [
{
value: id[0],
color:"#F7464A",
highlight: "#FF5A5E",
label: name[0]
},
{
value: id[1],
color: "#46BFBD",
highlight: "#5AD3D1",
label: name[1]
},
{
value: id[2],
color: "#FDB45C",
highlight: "#FFC870",
label: name[2]
},
{
value: id[3],
color: "#949FB1",
highlight: "#A8B3C5",
label: name[3]
},
{
value: id[4],
color: "#4D5360",
highlight: "#616774",
label: name[4]
}
];
var ctx = document.getElementById("canvas").getContext("2d");
window.myDoughnut = newChart(ctx).Doughnut(doughnutData, {responsive : true});
}
});
so just declare doughnutData variable global and remove windows.load
function and just remain internal code. that's it
Post a Comment for "Chart.js Doughnut Chart Not Properly Work"