在Chart.js折线图上以scaleLabel(无刻度或标签)顺时针旋转90度

时间:2017-10-22 14:08:07

标签: javascript chart.js chart.js2 chartjs-2.6.0

如何在yAxis上顺时针旋转90度的scaleLabel?不是刻度线或标签,而是通常位于yAxis左侧的单个元素。在此示例中,包含字符串:labelString:'My Label'

 var options = {
  type: 'line',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [
        {
          label: '# of Votes',
          data: [12, 19, 3, 5, 2, 3],
        borderWidth: 1
        },  
            {
                label: '# of Points',
                data: [7, 11, 5, 8, 3, 7],
                borderWidth: 1
            }
        ]
  },
  options: {
    scales: {
        yAxes: [{
        scaleLabel:{
          display:true,
          labelString:'My Label'
        },
        ticks: {
                    reverse: false
        }
      }]
    }
  }
}

var ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);

我的jsfiddle:https://jsfiddle.net/aq57fxjp/

1 个答案:

答案 0 :(得分:0)

您可以通过注释掉

来获得所需的效果
rotation = isLeft ? -0.5 * Math.PI : 0.5 * Math.PI;

在源代码中。