在我的代码下面:
$(document).ready(function() {
for(var j = 0; j < productsSize; j++) {
//tmStringToDisplay.push(name[j], parseInt(percent[j]));
var tmStringToDisplay = [name[j], parseInt(percent[j])];
tmStringToDisplay.push(temp);
}
console.log(tmStringToDisplay);
chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
title: {
text: 'The best selling products :'
},
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: 'Product share',
data: tmStringToDisplay
}]
});
我必须制作“ tmStringToDisplay”选项卡,然后将其放入系列数组的数据变量中。
在静态中,就像这样:
series: [{
type: 'pie',
name: 'Browser share',
data: [
['Firefox', 45.0],
['IE', 26.8],
{
name: 'Chrome',
y: 12.8,
sliced: true,
selected: true
},
['Safari', 8.5],
['Opera', 6.2],
['Others', 0.7]
]
}]
那是循环的,因为一切正常:
for(var j = 0; j < productsSize; j++) {
//tmStringToDisplay.push(name[j], parseInt(percent[j]));
var tmStringToDisplay = [name[j], parseInt(percent[j])];
tmStringToDisplay.push(temp);
}
我必须创建并准备“ tmStringToDisplay”,它需要像静态示例一样。
谢谢 !
最佳答案
将tmStringToDisplay解析为json
例如
jQuery.parseJSON(tmStringToDisplay);