如何在图表点击事件中绘制高图中的线?

Joh*_*ith 2 highcharts

是否可以在图表的点击事件上绘制一条线?

图表单击事件

chart: {
        events: {
            click: function(event) {
                alert ('x: '+ event.xAxis[0].value  +', y: '+
                      event.chartY );
                 var chart = event.xAxis[0];
                            chart.removePlotLine('plot-line-1');
                            chart.addPlotLine({
                                value: event.chartX,
                                color: '#FF0000',
                                width: 2,
                                id: 'plot-line-1'
                            });
            }
        }        
    },
Run Code Online (Sandbox Code Playgroud)

我最初在highcharts的plotoptions click事件上做了同样的事情.现在,使用图表点击事件做同样的事情?但无法获得系列xaxis对象.

Joh*_*ith 6

成功了!不得不阅读highcharts文件... :-)

工作链接

 chart: {
        events: {
            click: function (event) {
                var chart = this.xAxis[0];
                chart.removePlotLine('plot-line-1');
                chart.addPlotLine({
                    value: event.xAxis[0].value,
                    color: '#FF0000',
                    width: 2,
                    id: 'plot-line-1'
                });
            }
        }
Run Code Online (Sandbox Code Playgroud)