可以在图表js中设置垂直线的高度吗?

例如这个例子:https://jsfiddle.net/caj89x6L/
{
type: 'line',
id: 'vline' + index,
mode: 'vertical',
scaleID: 'x-axis-0',
value: date,
**endValue: 3.5, ??
height: 3.5,** ??
borderColor: 'green',
borderWidth: 1,
label: {
enabled: true,
position: "center",
content: amount[index]
}}
我可以在某个地方设置一个高度属性吗?endValue窗口不工作
发布于 2019-07-07 05:47:40
嘿,我不知道这是否仍然对你有帮助,但是我写了一个plugin for ChartJS,它完全按照你的要求做了。您可以根据自己的需要调整repo中的源代码。下面是相关的代码片段:
/**
* Draw the line height annotation to the highest data point on the chart.
* @param {int} x horizontal coordinate on canvas
* @param {int} bottomY bottom Y dimension of the chart
* @param {float} highestDataY highest possible Y value on the chart, taking padding and border offsets into consideration.
*/
drawLineHeightAnnotation(x, bottomY, highestDataY) {
let ctx = this.ctx;
let options = this.options;
ctx.save();
ctx.beginPath();
if (!options.noDash) {
ctx.setLineDash([10, 10]);
}
ctx.moveTo(x, highestDataY);
ctx.lineTo(x, bottomY);
ctx.lineWidth = options.lineWeight ? options.lineWeight : 1.5;
ctx.strokeStyle = options.color ? options.color : "#000";
ctx.stroke();
ctx.restore();
}https://stackoverflow.com/questions/54983206
复制相似问题