getting data from php page and I am passing chartData array to pie(title,chartData) function as second parameter.
Now chartData array is placing in data: [ chartData ] but it not working.
But when I add manually with key then It work data: [ chartData[0],chartData[1], ].
But I don’t want to mention it manually with key. I want to arry work automatically like data: [ chartData ]
What I have to do?
function createChart(chart) {
if ( chart == 'pie' ) {
var title = $("#chart-title").val();
/***************** Data Elements ****************/
var totalElements = $("#addMoreRowNo").val();
var chartData = new Array();
for(var j = 1; j <= totalElements; j++)
{
var key = $("#chart-pie-text_"+j).val();
var value = $("#chart-pie-percentage_"+j).val();
var data = [key, parseFloat(value)];
chartData[j-1] = data;
}
/***************** Data Elements ****************/
pie(title,chartData);
}
}
function pie(title,chartData) {
var chart;
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: title
},
tooltip: {
pointFormat: '{series.name}: <b>{point.percentage}%</b>',
percentageDecimals: 1
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
formatter: function() {
return '<b>'+ this.point.name +'</b>: '+ this.percentage +' %';
}
}
}
},
series: [{
type: 'pie',
name: 'Browser share',
data: [
chartData
/*chartData[0],
chartData[1],*/
//['Active Postings (13)', 20.00],
]
}]
});
}
I’m pretty sure your problem can be solved by replacing
with
The way you’re writing it, you’re defining data as an array containing chartData, which itself is an array. The way you indicate you’re testing it, though, is to get the items out of chartData and put each item into data, which results in a different structure.