在高图中单击系列时绘制垂直线

Draw a vertical line when clicking on the series in highcharts.

本文关键字:绘制 垂直线 系列 高图中 单击      更新时间:2023-09-26

我知道如何在highcharts中绘制竖线。但只有当我点击除系列以外的任何地方时才有可能。当我单击该系列时,没有提示。如果我单击图表容器中的其他任何地方,那么如果我得到一个提示。请给我一个解决办法。我的尝试到目前为止:

$('#save_line_vertical').click(function(event) {
        var label=document.getElementById("line_label_vertical").value;
        if(label!=null)
        {
            var id = 'vertLine' + Math.random();
            chart.addPlotLine({
            value: axis_value,
            color: '#'+(Math.random()*0xEEEEEE<<0).toString(16),
            width: 2,
            id: id,
            label : {
            text : label
            },
            events: {
            click: function(e) {
                chart.removePlotLine(id);
                }
            },
            });
        }
    });

这是我的小提琴:

http://jsfiddle.net/das_palash89/3AqM7/

你也需要添加点击事件到系列对象,与小抛光,见:

    plotOptions: {
        series: {
            events: {
                click: function (event) {
                    var label = prompt('Label for Vertical Line');
                    if (label != null) {
                        var chart = this.xAxis;
                        chart.addPlotLine({
                            value: chart.toValue(event.x),
                            color: '#' + (Math.random() * 0xEEEEEE << 0).toString(16),
                            width: 2,
                            id: 'vertLine',
                            zIndex: 9999,
                            label: {
                                text: label
                            }
                        });
                    }
                }
            }
        }
    },

演示:http://jsfiddle.net/3AqM7/5/