Chart.js-如何在左右绘制X和Y轴线
我使用Chart.js V2库绘制图表。
我试图设置零行,但行不通。
我需要在下面的屏幕截图上绘制两行。是否可以使用一些Cinfiguration选项来绘制?
var options = {
type: 'scatter',
data: {
datasets: [{
data: [{
x: 20,
y: 1
},
{
x: 21,
y: 1.1
},
{
x: 23,
y: 1.4
},
],
}]
},
options: {
legend: false,
scales: {
yAxes: [{
ticks: {
min: 1,
max: 2,
display: false,
},
gridLines: {
color: 'transparent',
display: true,
zeroLineColor: 'red'
},
}],
xAxes: [{
ticks: {
min: 1,
max: 99,
},
gridLines: {
color: 'transparent',
display: true,
zeroLineColor: 'red'
},
}]
}
}
}
var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
<canvas id="chartJSContainer" width="600" height="400"></canvas>
</body>
这是一个有代码的小提琴: https://jsfiddle.net/c4wotrx1/4/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要在
xaxes
和yaxes
上启用Gridlines
,但请禁用drawonchartarea
:You'll need to enable the
gridLines
on bothxAxes
andyAxes
, but disable thedrawOnchartArea
:在下面尝试,您需要保留线条,但将其隐藏在图表区域中。
您可以通过drawonchartarea:false,请参阅此
希望这会有所帮助。
try below, you need to keep the lines but hide them in the chart area.
This you can do by drawOnChartArea: false, see this documentation
hope this helps.