I have the following code:
window.onload = function () {
var chart = new CanvasJS.Chart("chartContainer",
{
title:{
text: "Desktop Search Engine Market Share, Dec-2012"
},
animationEnabled: true,
legend:{
verticalAlign: "center",
horizontalAlign: "left",
fontSize: 20,
fontFamily: "Helvetica"
},
theme: "theme2",
data: [
{
type: "pie",
indexLabelFontFamily: "Garamond",
indexLabelFontSize: 20,
indexLabel: "{label} {y}%",
startAngle:-20,
showInLegend: true,
toolTipContent:"{legendText} {y}%",
dataPoints: [
{ y: 83.24, legendText:"Google", label: "Google" },
{ y: 8.16, legendText:"Yahoo!", label: "Yahoo!" },
{ y: 4.67, legendText:"Bing", label: "Bing" },
{ y: 1.67, legendText:"Baidu" , label: "Baidu"},
{ y: 0.98, legendText:"Others" , label: "Others"}
]
}
]
});
chart.render();
}
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script><!DOCTYPEHTML><body><divid="chartContainer" style="height: 300px; width: 100%;"></div>
I would like to enter my own value in the chart. The return of my php looks like this:
[
{
"y": 83.24,
"legendText": "Google",
"label": "Google"
},
{
"y": 8.16,
"legendText": "Yahoo!",
"label": "Yahoo!"
},
{
"y": 4.67,
"legendText": "Bing",
"label": "Bing"
},
{
"y": 1.67,
"legendText": "Baidu",
"label": "Baidu"
},
{
"y": 0.98,
"legendText": "Others",
"label": "Others"
}
]
I'm trying to put this value in place and I can not:
I've tried this:
var dados = [];
$.ajax({
url : 'file.php',
type : 'post',
dataType : 'json',
data :{
acao : 'a'
}
,success : function( data ){
$.each( data, function( i, j ){
dados.push( j )
} );
}
});
I replace the data with mine and nothing.