如何使用highcharts.js在x轴和y轴的末端获得箭头?

时间:2016-12-20 18:59:47

标签: javascript highcharts bubble-chart

我想得到一些箭头,如上图

1 个答案:

答案 0 :(得分:2)

您可以渲染自己的形状并将它们放在轴线上。可以通过renderer来渲染自定义形状。

您还可以extend Highcharts以一种方式更改负责渲染轴线的方法。

简化的扩展名可能如下所示:

  Highcharts.wrap(Highcharts.Axis.prototype, 'getLinePath', function(p, lineWidth) {
var linePath = p.call(this, lineWidth);

if (this.options.arrowOnEnd) {
  var arrowFactor = 20,
    x,
    y,
    arrowPath,
    newPath;

  if (this.horiz) {
    x = linePath[4] = linePath[4] - arrowFactor;
    y = linePath[5];

    arrowPath = [
      'L', x - 0.35 * arrowFactor, y - 0.35 * arrowFactor,
      'L', x + 1 * arrowFactor, y,
      'L', x - 0.35 * arrowFactor, y + 0.35 * arrowFactor,
      'L', x, y
    ];
    newPath = linePath.concat(arrowPath);
  } else {
    x = linePath[1];
    y = linePath[2] = linePath[2]; // + arrowFactor;

    arrowPath = [
      'M', x, y,
      'L', x - 0.35 * arrowFactor, y + 0.35 * arrowFactor,
      'L', x, y - 1 * arrowFactor,
      'L', x + 0.35 * arrowFactor, y + 0.35 * arrowFactor,
      'L', x, y
    ];

    newPath = arrowPath.concat(linePath);
  }

  return newPath;
}

return linePath;
});

用于填充箭头的CSS:

.highcharts-axis-line {
  fill: black;
  stroke-linejoin: round;
}

示例:http://jsfiddle.net/z2aagpeu/