1
當試圖將Series添加到Highcharts餅圖時,只顯示系列的名稱,而不顯示圖形本身。爲什麼我的addSeries(在highcharts中)只顯示系列名稱而不顯示實際餅圖本身
如果我手動輸入系列,圖表正確顯示,但是通過.each循環完成時,它只顯示添加的系列名稱。
這裏是我的代碼:
function my_pie(){
// Build the chart
$('#pie_chart').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
marginBottom: 0,
spacingTop: 0,
marginTop:0,
marginLeft:50,
marginRight:50
},
credits:{
enabled:false
},
title: {
text: ''
},
tooltip: {
pointFormat: '{point.percentage:.1f}%</b>'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false
},
showInLegend: false
}
},
series: [{
type: 'pie',
name: 'Innehav',
data: [ ]
}]
});
var chart = $('#pie_chart').highcharts();
$.each(data_array, function(index, value) {
chart.addSeries({
name: index,
y: parseInt(value)
}, false);
});
chart.redraw();
};
這裏是從的console.log輸出(data_array中)
Object {Ja: "272", Nej: "30", Vet ej: "1"}
更新: 這裏是如何產生data_array中(我加num_check使值整數)
var data_array = <?php echo json_encode($data_pie, JSON_NUMERIC_CHECK) ?>;
而現在console.log(data_array)的外觀像這樣:
Object {Ja: 272, Nej: 30, Vet ej: 1}