1
我有一張餅圖,我想根據數據項的名稱爲tooltip
部分添加自定義描述。但是我的fiddle似乎不能正常運行。Highcharts自定義工具提示
這是在Highcharts中添加自定義工具提示的正確方法嗎?
$(function() {
var dataPie =[];
var abc =[{"name":"Dual","load":"20"},{"name":"Gas","load":"35"},{"name":"Other_Fossil_Fuels","load":"15"},{"name":"Nuclear","load":"12"},{"name":"Hydro","load":"8"},{"name":"Wind","load":"10"},{"name":"Other_Renewables","load":"10"}];
$.each(abc,function(i,el)
{
dataPie.push({name :el.name,y: parseInt(el.load)});
});
$('#container').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
type: 'pie'
},
title: {
text: 'Browser market shares January, 2015 to May, 2015'
},
tooltip: {
useHTML: true,
formatter: function() {
$.each(dataPie, function(i, e){
\t if(e.name == "Hydro"){
\t \t return 'Hydro descript';
\t }else if (e.name == "Wind"){
\t return 'Wind descript';
}else if (e.name == "Other_Renewables"){
\t return 'OR descript';
}else if (e.name == "Dual"){
\t return 'Dual descript';
}else if (e.name == "Gas"){
\t return 'Gas descript';
}else if (e.name == "Other_Fossil_Fuels"){
\t return 'FF descript';
}else if (e.name == "Nuclear"){
\t return 'Nuclear descript';
}
\t return 'Other';
});
}
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
format: '<b>{point.name}</b>: {point.percentage:.1f} %',
style: {
color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
}
}
}
},
series: [{
name: "Brands",
colorByPoint: true,
data: dataPie
}]
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto"></div>
媽的這麼近!非常感謝你 –