[英]How do I change the colors on Y-Axis for values above, below zero? Chart.js 2.6
[英]How do I disable Label Text on Y-Axis but keep the gridlines in Chart.js 2.6?
使用Chart.js 2.6嘗試將圖形配置為在Y軸上具有網格線但沒有標簽。 這是我的配置選項:
var wowOptions = {
scaleBeginAtZero: false,
responsive: true,
maintainAspectRatio: false,
scaleStartValue: -50,
legend: {
display: false
},
scales: {
xAxes: [{
display: true,
gridLines: {
display: false,
offsetGridLines: true,
zeroLineColor: "red"
},
ticks: {
stepSize: 4,
autoSkip: true
}
}],
yAxes: [{
display: false,
gridLines: {
display: true,
offsetGridLines: false,
drawOnChartArea: true,
drawBorder: false
}
}]
}
當我設置display:false時,它會禁用Y軸上的網格線和標簽:
當我為yAxes設置display:true時,我看到gridLines和標簽:
我試圖松開標簽-50,0,50,100,但保留gridLines。 有沒有辦法做到這一點?
謝謝,格里夫
要設置display: false
為y軸本身,而你需要設置它y軸的刻度,是這樣的...
options: {
scales: {
yAxes: [{
ticks: {
display: false
}
}]
},
...
}
ᴡᴏʀᴋɪɴɢᴡᴏʀᴋɪɴɢxᴀᴍᴘʟᴇ⧩
var ctx = document.getElementById("canvas").getContext('2d'); var myChart = new Chart(ctx, { type: 'bar', data: { labels: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'], datasets: [{ label: '# of Votes', data: [12, 19, 3, 5, 2, 5] }] }, options: { scales: { yAxes: [{ ticks: { display: false } }] } } });
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script> <canvas id="canvas"></canvas>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.