如何使xAxis(时间表)仅显示最近12个月?

时间:2018-12-20 11:41:34

标签: charts

因此,通常有两个问题。抱歉,如果它们太简单了,我只是一个初学者。

  1. xAxis是时间刻度。目前,它仅显示月份的名称。客户要求我重新制作它,以便显示从2017年12月开始的一年的最后12个月。有没有办法做到这一点?

  2. 我必须用所有数据制作一张桌子。 chart.js中是否有一个函数可以做到这一点?

这是我的代码:

var MONTHS = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Nevember", "December"];
var config = {
    type: 'line',
    data: {
        labels: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "Nevember", "December"],
        datasets: [{
            label: "Sales",
            backgroundColor: window.chartColors.red,
            borderColor: window.chartColors.red,
            data: [

                12,
                20,
                32,
                31,
                56,
                58,

            ],
            fill: false,
        }]
    },
    options:
    {
        responsive: true,
        title:{
            display:true,
            text:'Growth'
        },
        tooltips: {
            mode: 'index',
            intersect: false,
        },
        hover: {
            mode: 'nearest',
            intersect: true
        },
        scales: {
            xAxes: [{
                display: true,
                scaleLabel: {
                    display: true,
                    labelString: 'Month'
                }
            }],
            yAxes: [{
                display: true,
                scaleLabel: {
                display: true,
                labelString: 'Growth'
            },
            ticks:{
                min: 0,
                max: 100,
                beginAtZero: true, 
                stepSize: 10
            }
            }]
        }
    }
};

window.onload = function() {
    var ctx = document.getElementById("chart-0").getContext("2d");
    window.myLine = new Chart(ctx, config);
};

0 个答案:

没有答案