要消除/减少网格线,您可以将ticks
的maxTicksLimit
属性设置为数字(网格线数量- 约),如下所示:
scale: {
ticks: {
maxTicksLimit: 3
}
}
奖励:如果您希望删除所有网格线,将 maxTicksLimit
设为 0
并不能起作用。相反,请在图表选项中添加以下内容:
gridLines: {
display: false
}
display
属性设置为false
,如下所示:scale: {
ticks: {
display: false
}
}
工作示例 ⧩
let ctx = document.querySelector('#canvas').getContext('2d');
let chart = new Chart(ctx, {
type: 'radar',
data: {
labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul'],
datasets: [{
label: 'RADAR 1',
data: [3, 1, 6, 4, 7, 5, 4],
backgroundColor: 'rgba(0,119,204,0.2)',
borderColor: 'rgba(0,119,204, 0.5)'
}, {
label: 'RADAR 2',
data: [4, 2, 3, 6, 1, 7, 5],
backgroundColor: 'rgba(255, 0, 0 ,0.2)',
borderColor: 'rgba(255, 0, 0 ,0.5)'
}]
},
options: {
scale: {
ticks: {
display: false,
maxTicksLimit: 3
}
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="canvas"></canvas>