我是使用Highcharts的新手,我有一个包含7系列的图表。这些系列显示价格,现在我需要在主图表工具提示中显示主图表价格和另一个图表之间的百分比差异。 我正在观看如何格式化工具提示但我找不到如何解决这个问题,也许很容易或者可能没有,所以你的帮助会很受欢迎。
在这里,您可以看到我的代码示例:
series: [{
name: "User Price",
type:'line',
data: JSON.parse(data)
},
{
type: 'line',
name: 'Average Price',
color: "#E82315",
dataLabels: false,
visible: true,
data: JSON.parse(precio_medio)
},
{
type: 'line',
name: 'Other Price',
color: "#CC8604",
visible: false,
dataLabels: false,
data: [0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,
0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884,0.126884]
},
{
type: 'line',
name: 'Other Price 2',
color: "#F29D00",
visible: false,
dataLabels: false,
data: [0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368
,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368,0.124368]
}]
我想在工具提示中显示用户价格和平均价格之间的百分比差异。
提前谢谢大家。
答案 0 :(得分:1)
试试这个
formatter:function() {
var pointPct='';
var baseValue= this.points[0].point.y;
var tooTipTxt='';
console.log(baseValue);
$.each(this.points, function(i, point) {
pointPct = (point.y)*100/baseValue;
tooTipTxt += "<span>"+pointPct+"</span> "
});
return tooTipTxt;
}