水平'限制'Chart.js中的行

Horizontal 'limit' line in Chart.js

本文关键字:限制 水平 Chart js      更新时间:2023-11-11

是否可以在chart.js中的现有图表中添加水平线?

这里的示例字符代码:

// the canvas
<canvas id="myChart" width="800" height="200"></canvas>
// the js
var ctx = document.getElementById("myChart").getContext("2d");
var myNewChart = new Chart(ctx).Bar(data);

我想添加一条水平标记线(例如,在y=100处,如上图中的小提琴)

是的,您实际上可以做到这一点。你想要水平标记线,所以你需要在你的y轴中添加这个代码

plotLines: [{
            color: '#FF0000',
            width: 2,
            value: .50 * 200 // The marker value will be 100
                             // Or you can just set its value to 100
}]