有什么方法可以将多线图表工具提示格式化为单线?

时间:2019-01-17 01:54:22

标签: highcharts tooltip

我有一个多系列图表(折线和面积范围类型)。 图表图片

enter image description here

我想设置工具提示的格式,而不要使用以下内容:

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%)

由于图表中有很多数据,因此我需要将其用作共享工具提示。

我尝试给每个系列都使用idrelatedid,但是无法更改格式。

2 个答案:

答案 0 :(得分:0)

您可以使用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 } } 函数作为工具提示:

{{1}}

实时演示:http://jsfiddle.net/BlackLabel/g3qeobaf/

API参考:https://api.highcharts.com/highcharts/tooltip.formatter

答案 1 :(得分:0)

在xaxis上我有日期,我想将其添加到工具提示的顶部,我尝试过:

            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/>'
        }

但是它将它添加到每一行而不是仅仅添加到顶部

相关问题