簡體   English   中英

如何在Y軸上禁用標簽文本但是在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM