在highcharts上添加和删除plotLine时出错

Joh*_*ith 2 highcharts

click: function() {
                          if (!hasPlotLine) {
                                chart.xAxis[0].addPlotLine({
                                    value: 5.5,
                                    color: '#FF0000',
                                    width: 2,
                                    id: 'plot-line-1'
                                });

                            } else {
                                chart.xAxis[0].removePlotLine('plot-line-1');
                            }
                            hasPlotLine = !hasPlotLine;
                    }
Run Code Online (Sandbox Code Playgroud)

我试图添加和删除点击事件的情节线,我最终得到这个皇帝"无法读取属性xAxis of undefined"

DEMO

Seb*_*han 7

我假设您要删除"旧"plotLine并在点击的x值中添加新内容.首先,我建议删除条件,并仅使用删除/添加情节.

http://jsfiddle.net/FzNqA/8/

click: function () {

                        var chart = this.series.chart.xAxis[0];


                            chart.removePlotLine('plot-line-1');
                            chart.addPlotLine({
                                value: this.x,
                                color: '#FF0000',
                                width: 2,
                                id: 'plot-line-1'
                            });
                    }
Run Code Online (Sandbox Code Playgroud)