简体   繁体   English

如何在 highcharts 中的 map 上绘制有向路径?

[英]how to draw a directed path on a map in highcharts?

I am trying to implement highcharts maps with flight routes like this Highchart-maps with flight routes , what i want to achieve is, the routes needs to be shown something like this expected output .我正在尝试实现 highcharts 地图和这样的航线Highchart-maps with flight routes ,我想要实现的是,路线需要显示类似于预期的 output is there anyway to achieve this using highchart maps?无论如何使用highchart地图来实现这一点?

any suggestions would be appreciated, Thanks in advance.任何建议将不胜感激,在此先感谢。

function pointsToPath(from, to, invertArc) {
var arcPointX = (from.x + to.x) / (invertArc ? 2.4 : 1.9),
    arcPointY = (from.y + to.y) / (invertArc ? 2.4 : 1.9);
return 'M' + from.x + ',' + from.y + 'Q' + arcPointX + ' ' + arcPointY +
        ',' + to.x + ' ' + to.y;

} }

I'm not sure if your image and question are the same, but I assume you want to know how to draw a directed path .我不确定您的图像和问题是否相同,但我假设您想知道如何绘制有向路径 To achieve this I would use built-in SVG's markers .为了实现这一点,我将使用内置的 SVG标记 You can create markers in Highcharts too:您也可以在 Highcharts 中创建标记:

  chart: {
    events: {
      load: function () {
        this.renderer
          .definition({
            tagName: 'marker',
            id: 'markerArrow',
            refY: 5,
            refX: 9,
            markerWidth: 11,
            markerHeight: 11,
            orient: 'auto',
            children: [{
              tagName: 'path',
              d: 'M 0 0 L 10 5 L 0 10 Z',
              fill: Highcharts.getOptions().colors[3],
              'stroke-width': 1,
              stroke: '#000000'
            }]
          });
      }
    }
  },

Then, in CSS, connect paths with markers:然后,在 CSS 中,使用标记连接路径:

.highcharts-series-3 .highcharts-point {
  marker-end: url(#markerArrow)
}

And demo: https://jsfiddle.net/BlackLabel/xvhesL2n/和演示: https://jsfiddle.net/BlackLabel/xvhesL2n/

If you want to change the shape of a path, simply modify pointsToPath method.如果要改变路径的形状,只需修改pointsToPath方法即可。 In my demo above you can observe straight lines instead of arcs:在我上面的演示中,您可以观察直线而不是弧线:

function pointsToPath(from, to, invertArc) {
    return 'M' + from.x + ',' + from.y + 'L' + to.x + ',' + to.y;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM