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

sch*_*ger 8 html javascript chart.js

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

这里是示例char代码:

// 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);
Run Code Online (Sandbox Code Playgroud)

我想添加一个水平标记线(例如,y = 100,就像这个小提琴一样,用于高图)

小智 1

是的,你确实可以这样做。您需要水平标记线,因此需要在 y 轴内添加此代码

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