【问题标题】:Chart.js : scaleStartValue from highest to lowestChart.js : scaleStartValue 从最高到最低
【发布时间】:2015-01-15 12:45:03
【问题描述】:

我正在使用 Chart.js 来呈现折线图,并且我希望我的数据以相反的方式绘制,即最大的数字显示在底部,最小的数字显示在顶部。我可以通过设置负 scaleSteps 来实现这一点,但 Y 轴上的实际标签会丢失。有没有办法也有这些标签。请在此处查看示例:http://jsfiddle.net/7z5e87he/

var myNewChart = new Chart(ctx).Line(data, {
        scaleShowGridLines: false,
        scaleOverride: true,
        scaleStartValue: 10,
        scaleStepWidth: 1,
        scaleSteps: -6,        
        responsive:true}); ;

谢谢..

【问题讨论】:

    标签: chart.js


    【解决方案1】:

    chartjs 中不支持反转 y 轴: https://github.com/nnnick/Chart.js/issues/579

    您可以通过反转数据集来伪造它(尽管轴标签不匹配):

    var inverted = [8, 8, 9, 7, 7, 7, 5, 4],
        max = Math.max.apply(Math, inverted);
    
    inverted.forEach(function(val, idx) {
        inverted[idx] = max - val;
    });
    

    小提琴:http://jsfiddle.net/az2u51gj/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-11
      • 2016-08-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多