代码之家  ›  专栏  ›  技术社区  ›  MrProgram

highcharts带箭头的单行

  •  0
  • MrProgram  · 技术社区  · 7 年前

    我想要一个图表,其中有一个单线箭头,如下所示:

    <-------X------------>
    1    2    3    4    5
    

    或者像这样(这里/应该是箭头:):

               \/
     -------------------------
     | 1 | 2 | 3 | 4 | 5 |
     -------------------------
    

    我试着对此进行了一些实验,但没有任何结果,我找不到任何好的例子。有什么好的图表吗?

    http://jsfiddle.net/o6cxfn5s/

    1 回复  |  直到 7 年前
        1
  •  1
  •   Kamil Kulig    7 年前

    请参阅此 现场演示 : http://jsfiddle.net/kkulig/u3qj6u74/

    它包含负责绘制图形的包装核心功能:

      (function(H) {
        H.wrap(H.Series.prototype, 'drawGraph', function(proceed) {
          // Now apply the original function with the original arguments, 
          // which are sliced off this function's arguments
          proceed.apply(this, Array.prototype.slice.call(arguments, 1));
    
          var arrowLength = 15,
            arrowWidth = 9,
            series = this,
            lastPoint = series.points[series.points.length - 1],
            nextLastPoint = series.points[series.points.length - 2],
            path = [];
    
    
          var angle = Math.atan((lastPoint.plotX - nextLastPoint.plotX) / (lastPoint.plotY - nextLastPoint.plotY));
    
          if (angle < 0) angle = Math.PI + angle;
    
          path.push('M', lastPoint.plotX, lastPoint.plotY);
    
          if (lastPoint.plotX > nextLastPoint.plotX) {
            path.push(
              'L',
              lastPoint.plotX + arrowWidth * Math.cos(angle),
              lastPoint.plotY - arrowWidth * Math.sin(angle));
            path.push(
              lastPoint.plotX + arrowLength * Math.sin(angle),
              lastPoint.plotY + arrowLength * Math.cos(angle));
            path.push(
              lastPoint.plotX - arrowWidth * Math.cos(angle),
              lastPoint.plotY + arrowWidth * Math.sin(angle),
              'Z');
          } else {
            path.push(
              'L',
              lastPoint.plotX - arrowWidth * Math.cos(angle),
              lastPoint.plotY + arrowWidth * Math.sin(angle));
            path.push(
              lastPoint.plotX - arrowLength * Math.sin(angle),
              lastPoint.plotY - arrowLength * Math.cos(angle));
            path.push(
              lastPoint.plotX + arrowWidth * Math.cos(angle),
              lastPoint.plotY - arrowWidth * Math.sin(angle),
              'Z');
          }
    
          if (series.arrow) {
            series.arrow.attr({
              d: path
            });
          } else {
            series.arrow = series.chart.renderer.path(path)
              .attr({
                fill: series.color
              })
              .add(series.group);
          }
        });
      }(Highcharts));
    

    您可以轻松地调整此代码,以便两端都有箭头。


    Dosc关于包装的页面 : https://www.highcharts.com/docs/extending-highcharts/extending-highcharts