Make x label horizontal in ChartJS

后端 未结 2 786
终归单人心
终归单人心 2021-02-19 10:29

\"enter

Drawing a line chart with ChartJS 1.0.1 as above. As it shows, the label in the x-

相关标签:
2条回答
  • 2021-02-19 10:31

    try fix the function calculateXLabelRotation in chart.js

    calculateXLabelRotation : function(){
        ...
            //↓↓↓
            this.xLabelRotation = 0;
            //↑↑↑
            if (this.xLabelRotation > 0){
                this.endPoint -= Math.sin(toRadians(this.xLabelRotation))*originalLabelWidth + 3;
            }
        ...
    },
    
    0 讨论(0)
  • 2021-02-19 10:52

    If you are using chart.js 2.x, just set maxRotation: 0 and minRotation: 0 in ticks options. If you want them vertical, set maxRotation: 90 and minRotation: 90 instead. And if you want to all x-labels, you may want to set autoSkip: false. The following is an example.

    var myChart = new Chart(ctx, {
      type: 'bar',
      data: chartData,
      options: {
        scales: {
          xAxes: [{
            ticks: {
              autoSkip: false,
              maxRotation: 0,
              minRotation: 0
            }
          }]
        }
      }
    });
    

    example of 0 degree

    example of 90 degree

    0 讨论(0)
提交回复
热议问题