0

我正在使用高图表。我想制作一个如下图所示的图表。需要标记从系列 1 最高点绘制的线连接到系列 2 的点(如下图所示)。

找不到任何有用的资源。任何线索将不胜感激。提前致谢。在此处输入图像描述

能够实现这一点,但不完全是我想要的。您可以使用下面的代码片段:

(小提琴链接

Highcharts.chart('container', {
    xAxis: {
        plotLines: [{
            color: 'red',
            width: 2,
            value: Date.UTC(2010, 0, 4)
        }],
        tickInterval: 24 * 3600 * 1000, // one day
        type: 'datetime'
    },

    series: [{
        data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4],
        pointStart: Date.UTC(2010, 0, 1),
        pointInterval: 24 * 3600 * 1000
    }, {
        data: [39.9, 91.5, 196.4, 159.2, 164.0, 180.0, 188.6, 187.5, 246.4],
        pointStart: Date.UTC(2010, 0, 1),
        pointInterval: 24 * 3600 * 1000
    }]
});
<script src="https://code.highcharts.com/highcharts.js"></script>

<div id="container" style="height: 400px"></div>

编辑:我能够在一定程度上实现它,正如 Gaurav 所回答的那样。在这里检查。

4

1 回答 1

1

正如评论中提到的,您可以使用 Highcharts SVGRenderer 类来绘制一条线。您可以使用诸如 Highcharts 的加载事件之类的东西,您可以在其中使用 SVGRenderer 创建路径线。

chart: {
     events: {
        load: function () {
                console.log(this.chart); // This will get tou the chart reference where in you can find the coordinates of the point from where you want to draw the line
var x1 = this.series[0].data[this.series[0].data.length - 1].plotX + this.plotLeft;
var y1 = this.series[0].data[this.series[0].data.length - 1].plotY + this.plotTop;
            var label = this.renderer.path(['M', x1,y1,'L', 550, y1])//M 75 223.5 L 593 223.5
        .attr({
                'stroke-dasharray': '2,2',
            'stroke-width': 2,
            stroke: 'red'
        })
        .add();
        var label = this.renderer.path(['M', 550, this.plotTop + this.plotHeight,'L', 550, y1])//M 75 223.5 L 593 223.5
        .attr({
                'stroke-dasharray': '2,2',
            'stroke-width': 2,
            stroke: 'red'
        })
        .add();


        }
    }
}

x 坐标 550,我是随机选择的,但如果您知道 x 点,那么您就是这样做的。这是新的小提琴链接。希望能帮助到你

于 2018-02-14T09:29:36.320 回答