AutoSkip:False不适用于时间xAxes标签

时间:2019-02-10 05:48:20

标签: chart.js

我有一个条形图,它每秒钟自动跳过xAxes标签。我需要显示所有标签,但是设置AutoSkip:False无效。 下面是我的代码,我从中删除了一些额外的数据集。

        var myChart2 = new Chart(document.getElementById("ch2"), {
        type: 'bar',
        data: {
            datasets: [
                {
                    label: 'Budget',
                    data: [<data here>]
                }
            ]
        },
        options: {
            tooltips: {
                callbacks: {
                    label: function (tooltipItem, data) {
                        return '$' + tooltipItem.yLabel;
                    }
                }
            },
            scales: {
                yAxes: [{
                    ticks: {
                        beginAtZero: true,
                        callback: function (value, index, values) {
                            return '$' + (value >= 1000000  ? value/1000000+'M' : value);
                        }
                    },
                    stacked: true
                }],
                xAxes: [{
                    type: "time",
                    ticks: {
                        autoSkip: false    // Not working
                    },
                    time: {
                        unit: 'month',
                        format: 'DD MMM YYYY',
                        tooltipFormat: 'MMM YYYY',
                        displayFormats: {
                            month: 'MMM'
                        }
                    },
                    offset: true,
                    gridLines: {
                        display: false,
                        offsetGridLines: true
                    }
                }]
            }
        }
    });

Current output

1 个答案:

答案 0 :(得分:0)

就我而言,我需要设置source: date。您将在xAxi上获得所有日期步骤。顺便说一下,尝试source: auto,它将尝试设置最佳步数(不是全部)。在这里https://www.chartjs.org/docs/latest/axes/cartesian/time.html#ticks-source