在右侧显示yAxis值的额外工具提示

时间:2019-03-26 09:26:03

标签: javascript highcharts

我想在我的图表中显示一个额外的工具提示,以显示yAxis的值。我在谈论的这些工具提示已在许多ohlc图表中看到。出于演示目的,我使用了绘画工具。

Tooltip on right side 1

Tooltip on right side 2

如果您在右侧看到主工具提示,则还有另一个工具提示正在显示yAxis值。我们如何才能在Highcharts中做到相同。我有以下代码。

Highcharts.chart('container', {
    title: {
        text: 'Non-snapped crosshair'
    },
    xAxis: {
        crosshair: {
            snap: false
        }
    },
    yAxis: {
        crosshair: {
            snap: false
        },
        opposite: true
    },
    tooltip: {
        borderWidth: 1,
        shape: 'rect',
        positioner: function () {
            return { x: 0, y: 0 };
        },
    },
    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
    }]
});

注意:为了使鼠标指针跟随十字准线,我将两个轴上的snap的{​​{1}}属性设置为false。

1 个答案:

答案 0 :(得分:2)

您可以将highstock源代码和label属性用于十字准线:

yAxis: {
    crosshair: {
        snap: false,
        label: {
            enabled: true,
            format: '{value:.2f}'
        }
    },
    ...
},

实时演示:https://jsfiddle.net/BlackLabel/yz4b6cus/

API参考:https://api.highcharts.com/highstock/xAxis.crosshair.label