【发布时间】:2014-03-20 16:05:21
【问题描述】:
我对 Highcharts 还很陌生。我有一个使用动态数据 (JSON String) 可以很好地呈现的饼图。但我想将某些切片自定义为 Sliced: true 和 Selected: True。我不知道该怎么做。请在下面找到我的代码,
<div id="container_${page_id}" style="min-width: 310px; height: 400px; margin: 0 auto;"></div>
var series = [];
var total = 0;
$.each(data, function(index, value) {
series.push([value.statisticData+'_'+value.sizes,parseInt(value.sizes)]);
console.log("statisticData",value.statisticData);
console.log("value.sizes",value.sizes);
total += parseInt(value.count);
});
var chartSessionStatus = new Highcharts.Chart({
chart: {
renderTo: $("#container_"+testSessionPageId).get(0),
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false
},
exporting: {
enabled: true,
buttons: {
contextButton: {
menuItems: [{
text: 'Statistics',
}]
}}
},
tooltip: {
formatter: function() {
return this.point.name.split('_')[0] + ': <b>'+this.y+'</b>';
}
},
title: {
text: '<h4 style="font-style: bold">Tenant Statistics</h4>'
},
legend: {
labelFormatter: function() {
return this.name.split('_')[0] + ' (' + this.y+')';
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
distance: 0,
useHTML: true,
formatter: function() {
if( this.y > 0)
return '<b>'+this.point.name.split('_')[0] +'('+ this.y +')</b>';
}
},
showInLegend: true,
size: 150
}
},
series: [{
type: 'pie',
name: 'Tenant Statistics',
data: series
}]
});
});
主要关注点,在系列中,我可以选择数据为“数据:系列”,但我想自定义本系列中的某些切片。但由于数据是动态的,我不确定如何仅使用 json 字符串的某些部分 我收到的 Json 格式如下:
[{"statisticData":"创建的测试","sizes":"3"},{"statisticData":"Students","sizes":"2"},{"statisticData":"Users", "sizes":"7"},{"statisticData":"Schools","sizes":"10"}]
非常感谢任何帮助!提前致谢。
【问题讨论】:
标签: highcharts pie-chart