如何使用 highcharts.js 获得 x 轴和 y 轴末端的箭头?
How can I get arrows at the end of x-axis and y-axis using highcharts.js?
我想要像上图这样的箭头
您可以渲染自己的形状并将它们放置在轴线之上。渲染自定义形状可以通过 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;
}
我想要像上图这样的箭头
您可以渲染自己的形状并将它们放置在轴线之上。渲染自定义形状可以通过 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;
}