ChartJS禁用图表区域外的网格线

时间:2019-01-14 10:23:42

标签: chart.js

我试图隐藏在图表区域之外绘制的网格线,所以基本上像下面的选项一样,但对于图表区域之外的

gridLines: {
  drawOnChartArea: false,
},

exmpl

1 个答案:

答案 0 :(得分:1)

大概您希望禁用通过drawTicks属性可以实现的刻度线:

new Chart(document.getElementById('canvas'), {
  type: 'bar',
  data: {
    labels: ['a', 'b', 'c'],
    datasets: [{
      label: 'series1',
      data: [1, 2, 4]
    }]
  },
  options: {
    scales: {
      xAxes: [{
        gridLines: {
          drawTicks: false
        },
        ticks: {
          padding: 10
        }
      }],
      yAxes: [{
        gridLines: {
          drawTicks: false
        },
        ticks: {
          beginAtZero: true,
          padding: 10
        }
      }]
    }
  }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.3/Chart.min.js"></script>
<canvas id="canvas">

gridLines:
  drawTicks: false;
}

有关更多信息,请参考documentation