gpt4 book ai didi

javascript - 带箭头的 highcharts 单线

转载 作者:行者123 更新时间:2023-12-03 02:53:57 29 4
gpt4 key购买 nike

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

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

或者像这样(其中/假设是一个箭头:)):

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

我尝试对此进行了一些尝试,但没有任何结果,而且我找不到任何好的例子。有什么好的 Highcharts 吗?

http://jsfiddle.net/o6cxfn5s/

最佳答案

请参阅此现场演示: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));

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

<小时/>

有关包装的文档页面:https://www.highcharts.com/docs/extending-highcharts/extending-highcharts

关于javascript - 带箭头的 highcharts 单线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47721140/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com