[英]Custom tooltip names Pie Chart
我正在使用Highcharts餅圖,並且想為每個點添加自定義后綴。 例如,現在我在工具提示格式化程序中具有此功能:
tooltip : { formatter : function() { return 'Daily KB: <b>'+ this.point.y +'</b>'; } },
彈出窗口的顯示方式類似於每一塊Pie Daily KB: 300
。 我該如何修改它,以使彈出的內容像“ Daily KB: 700 remaining
,而另一個彈出框卻是“ Daily KB: 300
?
Highcharts script:
(function($){
$(this.document).ready(function(){
//get local time
Highcharts.setOptions({
colors: ['#fa604c', '#00CC66']
});;
myChart_d = new Highcharts.Chart({
chart: {
height:200,
width:200,
type: 'pie',
animation: false,
renderTo: 'dailychart',
zoomType: 'x',
events: {
load: function () {
requestDataLim();
}
}
},
title: {
text: 'Daily'
},
tooltip : {
formatter : function() {
return 'Daily KB: <b>'+ this.point.y +'</b>';
}
},
//tooltip: {
//shared:true
//},
plotOptions: {
pie: {
// allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: false,
},
borderColor: '#A0A0A0',
innerSize: '40%',
},
series:{
dataLabels: {
style:{ fontSize: '14px', fontWeight:'bold' },
enabled: true,
formatter: function() {
return Math.round(this.percentage) + ' %';
},
distance: -15,
color:'black'
}
},
},
credits: {
enabled: false
},
series: [{
name: 'DailyKB',
data:
[<?php echo join(',',$d);
echo ',';
echo join (',',$dl);?>]
}],
exporting: {
buttons: {
printButton: {
enabled: false
},
exportButton: {
enabled: false
}
}
}
});
我通過ajax和JSON獲取數據,目前是這樣的[300, 700]
如何將數據格式更改為對象數組? 例如:
[{y: 300, suffix: ""}, {y: 700, suffix: " remaining" }]
然后在工具提示集中添加suffix
信息:
return 'Daily KB: <b>'+ this.point.y +'</b>' + this.point.options.suffix;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.