Hiding labels on y axis in Chart.js

后端 未结 9 1140
再見小時候
再見小時候 2020-12-30 19:34

I need to hide labels in line chart drawn using library chart.js. I googled but no luck. Could that be hidden?

Thanks

相关标签:
9条回答
  • 2020-12-30 19:59

    This worked for me with Chartjs v2.4.0

    The idea is to set backDropColor to full transparent. 255,255,255 is white, but 0 sets it to transparent.

    Then the userCallback returns always an emptry string.

    The end result is hidden y-axis labels.

      ticks: {
        backdropColor : "rgba(255,255,255,0)",
        userCallback: function(value, index, values) {
          return "";
        }
      }
    
    0 讨论(0)
  • 2020-12-30 20:03
    options: {
        scales: {
            yAxes: [{
                gridLines: {
                  display: true,
                  color: 'rgba(219,219,219,0.3)',
                  zeroLineColor: 'rgba(219,219,219,0.3)',
                  drawBorder: false, // <---
                  lineWidth: 27,
                  zeroLineWidth: 1                 
                },
                ticks: {
                    beginAtZero: true,
                    display: true
                }
            }]
        }
    }
    
    0 讨论(0)
  • try this one

     var statDat = {
        labels: ["January", "February", "March", "April", "May", "June"],
        datasets: [
            {
                fillColor: "rgba(255, 152, 0, 0.30)",
                strokeColor: "#f26b5f",
                pointColor: "#f26b5f",
                pointBackgroundColor: "rgba(179,181,198,1)",
                pointBorderColor: "#00fff5",
                pointStrokeColor: "#f26b5f",
                data: [203, 156, 99, 251, 305, 247]
            }
        ]
    };
    
    var stats = document.getElementById('stats').getContext('2d');
    
    var options = {
        scaleShowLabels: false 
    };
    
    new Chart(stats).Line(statDat, options);
    
    0 讨论(0)
提交回复
热议问题