Chart Js Change Label orientation on x-Axis for Line Charts

后端 未结 4 1044
南方客
南方客 2020-12-08 18:48

I am using chart.js.

Similar to this Question, I would like to rotate my x-axis labels 90 degrees. Currently my labels are rotated about 80 degrees with default sett

4条回答
  •  我在风中等你
    2020-12-08 19:36

    for x axis use this

     options: {
          legend: {
            display: false
          },
          scales: {
            xAxes: [
              {
              ticks: {
                    autoSkip: false,
                    maxRotation: 0,
                    minRotation: 0
                }
              }
            ]
          }
        }
    

    and can filter the label with a for loop:

          arrayLabels.forEach((date, i) => {
        let label = "";
        if (i % step == 0 && fecha) {
          label = moment(date, "DD/MM").format("DD MMM");
        }
        labels.push(label);
      });
       chartOptions.data.labels = labels;
    

提交回复
热议问题