Hiding labels on y axis in Chart.js

后端 未结 9 1139
再見小時候
再見小時候 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:42

    This will hide labels in Y-Axis: (but not X-Axis)

        scaleShowLabels: false,
    
    0 讨论(0)
  • 2020-12-30 19:44
    Chart.defaults.scale.ticks.display = false;
    
    0 讨论(0)
  • 2020-12-30 19:49

    Solved it with overriding y-axis labels width

    Chart.Scale.prototype.buildYLabels = function () {
      this.yLabelWidth = 0;
    };
    
    0 讨论(0)
  • 2020-12-30 19:51

    you can use the scaleShowLabels option

    • http://www.chartjs.org/docs/#line-chart-chart-options
    0 讨论(0)
  • 2020-12-30 19:57

    To hide just the labels, in the latest version (2.3.0) of Charts.js, you disable ticks like so:

    options: {
        scales: {
            yAxes: [{
                ticks: {
                    display: false
                }
            }]
        }
    }
    
    0 讨论(0)
  • 2020-12-30 19:58

    For version 2, you can do this with the Scales option in the global configuration.

      var ctx = document.getElementById("log");
      var chart = new Chart(ctx, {
          type: 'line',
          options: {
            scales: {
              xAxes: [{
                display: false
              }],
              yAxes: [{
                display: false
              }],
            }
          },
          data: {
            labels: ['Item 1', 'Item 2', 'Item 3'],
            datasets: [{
                fill: false,
                borderWidth: 1,
                data: [10, 20, 30]
            }]
          }
        });
    
    0 讨论(0)
提交回复
热议问题