我只是ChartJS的新手,enter image description here
我有3个问题:
1.如何使Y轴仅是整数?我应该在哪里添加它?
2.如何关闭标题为“我的大写字母”的标题?我试图将其设置为null但不起作用?
3.如何关闭背景网格?看起来很奇怪
这是我的代码:
var columnChart = document.getElementById("columnChart").getContext('2d');
var myChart = new Chart(columnChart, {
type: 'bar',
data: {
labels: columnChartLabel,
datasets: [ {
label: 'My Open Case',
data: columnChartNumber,
backgroundColor: "rgba(255,153,0,1)"
}]
}
});
最佳答案
如何使Y轴仅是整数?我应该在哪里添加它?
通过将图表选项中的刻度的stepSize
属性设置为1
,可以使Y轴仅是整数。
options: {
scales: {
yAxes: [{
ticks: {
stepSize: 1
}
}]
}
}
见tick configuration options
如何关闭“我的打开的箱子”标题?
您可以通过将图例的
display
属性设置为false
来关闭标题(也称为图例)。options: {
legend: {
display: false
}
}
见legend configuration
如何关闭背景网格?
您可以通过将x和y轴的gridLines的
display
属性设置为false
来关闭背景网格。options: {
scales: {
xAxes: [{
gridLines: {
display: false
}
}],
yAxes: [{
gridLines: {
display: false
}
}]
}
}
见grid line configuration
ᴡᴏʀᴋɪɴɢ ᴇxᴀᴍᴘʟᴇ ᴏɴ ᴊꜱꜰɪᴅᴅʟᴇ
关于javascript - 如何使ChartJS中的y轴仅是整数缩放?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44057477/