我是 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]
}]
我想在工具提示中显示用户价格和平均价格之间的百分比差异。
提前谢谢大家。
最佳答案
试试这个
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;
}
关于javascript - Highcharts 共享工具提示显示系列之间的百分比差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32778461/