有没有办法将多线图表工具提示格式化为单线?
Is there any way to format multi-line chart tooltips to a single-line?
我有一个多系列图表(线条和区域范围类型)。
图表图片
我想格式化工具提示,而不是:
POSITIVE: 20%
POSITIVE RANGE: 19% - 21%
NEGATIVE: 45%
NEGATIVE RANGE: 43% - 46%
NEUTRAL: 35%
NEUTRAL RANGE: 34% - 36%
格式化为:
POSITIVE: 20% (19% - 21%)
NEGATIVE: 45% (43% - 46%)
NEUTRAL: 35% (34% - 36%)
我需要它成为一个 SHARED 工具提示,因为图表中有很多数据。
我已经尝试为每个系列提供 id
和 relatedid
,但未能实现更改格式。
您可以使用 formatter
工具提示功能:
tooltip: {
shared: true,
formatter: function(e) {
var points = this.points,
i,
result = '';
function formatPoint(p, low, high) {
return '<span style="color:' + p.point.color + '">\u25CF</span> ' + p.series.name + ': <b>' + p.point.y + '% (' + low + '% -' + high + ' %)</b><br/>'
}
for (i = 0; i < points.length; i += 2) {
result += formatPoint(points[i], points[i + 1].point.low, points[i + 1].point.high)
}
return result
}
}
现场演示:http://jsfiddle.net/BlackLabel/g3qeobaf/
API参考:https://api.highcharts.com/highcharts/tooltip.formatter
在 x 轴上我有日期,我想将它添加到工具提示的顶部,我试过:
return Highcharts.dateFormat('%b - %Y',
new Date(p.x)) +' <span style="color:' + p.point.color + '">\u25CF</span> ' + p.series.name + ': <b>' + Math.round(p.point.y) + '% (' + Math.round(low) + '-' + Math.round(high) + ')</b><br/>'
}
但是它将它添加到每一行而不是仅在顶部
我有一个多系列图表(线条和区域范围类型)。 图表图片
我想格式化工具提示,而不是:
POSITIVE: 20%
POSITIVE RANGE: 19% - 21%
NEGATIVE: 45%
NEGATIVE RANGE: 43% - 46%
NEUTRAL: 35%
NEUTRAL RANGE: 34% - 36%
格式化为:
POSITIVE: 20% (19% - 21%)
NEGATIVE: 45% (43% - 46%)
NEUTRAL: 35% (34% - 36%)
我需要它成为一个 SHARED 工具提示,因为图表中有很多数据。
我已经尝试为每个系列提供 id
和 relatedid
,但未能实现更改格式。
您可以使用 formatter
工具提示功能:
tooltip: {
shared: true,
formatter: function(e) {
var points = this.points,
i,
result = '';
function formatPoint(p, low, high) {
return '<span style="color:' + p.point.color + '">\u25CF</span> ' + p.series.name + ': <b>' + p.point.y + '% (' + low + '% -' + high + ' %)</b><br/>'
}
for (i = 0; i < points.length; i += 2) {
result += formatPoint(points[i], points[i + 1].point.low, points[i + 1].point.high)
}
return result
}
}
现场演示:http://jsfiddle.net/BlackLabel/g3qeobaf/
API参考:https://api.highcharts.com/highcharts/tooltip.formatter
在 x 轴上我有日期,我想将它添加到工具提示的顶部,我试过:
return Highcharts.dateFormat('%b - %Y',
new Date(p.x)) +' <span style="color:' + p.point.color + '">\u25CF</span> ' + p.series.name + ': <b>' + Math.round(p.point.y) + '% (' + Math.round(low) + '-' + Math.round(high) + ')</b><br/>'
}
但是它将它添加到每一行而不是仅在顶部