【问题标题】:How do you revert xAxes with Chart.js?如何使用 Chart.js 恢复 xAxes?
【发布时间】:2019-06-27 11:53:28
【问题描述】:

由于某种原因,我图表的 xAxes 从最新数据到最旧日期。我显然想要相反/正常的方式。如何还原 xAxes? .. 或者只是 xAxes 与日期正常运行。

我的图表在这里:https://www.betscout.com/tips(点击统计标签) 我已经尝试过这个选项:https://jsfiddle.net/marineboudeau/4awme3fp/3 - 但它不起作用,即使在提供的示例中也不行(当我将 reverse: true 替换为 reverse: false 时没有任何变化。)

我可以通过这种方式轻松地反转 yAxes,那么为什么不使用 xAxes?

这是我的一些 JS 代码:

    let chart = document.getElementById('chart');
    let myLineChart = new Chart(chart, {
        type: 'line',
        data: {
            labels: grades,
            datasets: [{
                    data: numbers,
                    label: 'Total profit',
                    fill: false,
                    borderColor: '#3771a3'
      }]
        },
        options: {
            scales: {
                yAxes: [{
                    gridLines: {
                        display: true,
                        color: "rgba(55, 113, 163, 0.18)"
                    },

                    ticks: {
                        beginAtZero: true,
                    }
      }],
                xAxes: [{
                    gridLines: {
                        display: true,
                        color: "rgba(55, 113, 163, 0.18)"
                    },

                    ticks: {
                        display: true,
                        reverse: true,
                        fontSize: 12
                    }
            }]
            }
        }
    });
}

【问题讨论】:

    标签: javascript chart.js


    【解决方案1】:

    我认为它仍然是 discussed 为什么它不起作用,你可以做 numbers.reverse()grades.reverse() 直到它修复。 fiddle

    【讨论】:

      猜你喜欢
      • 2023-02-14
      • 1970-01-01
      • 1970-01-01
      • 2018-02-03
      • 2020-05-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多