How can I get arrows at the end of x-axis and y-axis using highcharts.js?

1.6k views Asked by At

I want to get some arrows like the picture above

1

There are 1 answers

0
morganfree On BEST ANSWER

You can render you own shapes and lay them on top of axis lines. Rendering custom shapes can be achieved via renderer.

You can also extend Highcharts in a way that the method responsible for rendering an axis line will be changed.

A simplified extension could look like this:

  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 for filling the arrows:

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

example: http://jsfiddle.net/z2aagpeu/