如何将 Highstock 工具提示显示到二维距离中的最近点?

How to show Highstock tooltip to nearest point in 2-D distance?

在同一图表上绘制多个系列时,工具提示是否可以捕捉到二维距离中的最近点,而不是仅捕捉到 x 轴值中的最近点。在这种情况下,不可能仅从颜色判断哪个系列是哪个系列,捕捉到最接近的 x 轴值是非常无用的,因为它基本上在许多系列中随机跳跃,所有系列都具有围绕相同 x 值的数据点。

我没有找到以这种方式设置工具提示的方法,但从算法上讲,它确实没有那么昂贵,因为可以简单地为每个系列挑选出最接近的 x 值数据点,然后从这些点中挑选具有最短的二维距离(或者甚至只是最近的 y 值点,因为通常 x 值比 y 值更密集)。

更新 我使用了下面建议的 findNearestPointBy,除了我实际上使用的是 stockChart,它应该可以满足我的要求。 stockChart 的行为似乎与 chart 不同 - 请参阅 stockChart vs. chart

  1. findNearestPointBy好像没什么区别。如果您将鼠标直接放在 "bump" 旁边两个点中的任何一个上方但在凸起的高度处,工具提示将捕捉到 chart 上的凸起但捕捉到 stockChart 上的较低点.

  2. 当鼠标悬停在两个系列的相同 x 值的点附近时,stochChart 工具提示显示两个系列,而 chart 工具提示仅显示最近点更近的系列- 我更喜欢后者,因为我希望工具提示告诉我最近的点属于哪个系列。

更新 2 我在 Highcharts 支持页面上问了同样的问题,并指出了解决方案。添加 tooltip: {shared: false} 解决了我的两个问题 stockChart v2.

Series.findNearestPointBy 选项设置为 'xy'

来自API:

findNearestPointBy: String

Determines whether the series should look for the nearest point in both dimensions or just the x-dimension when hovering the series. Defaults to 'xy' for scatter series and 'x' for most other series. If the data has duplicate x-values, it is recommended to set this to 'xy' to allow hovering over all points.

Applies only to series types using nearest neighbor search (not direct hover) for tooltip.

src: http://api.highcharts.com/highcharts/plotOptions.area.findNearestPointBy

示例:http://jsfiddle.net/gh/get/library/pure/highslide-software/highcharts.com/tree/master/samples/highcharts/series/findnearestpointby/