Javascript 为什么我的数据集不使用Chart.js显示在折线图上?

Javascript 为什么我的数据集不使用Chart.js显示在折线图上?,javascript,chart.js,Javascript,Chart.js,我正在尝试使用chart.js在网页上显示一个折线图,显示过去5天特定客户端在apple store和google play store中的下载次数。数据正确显示,但未正确标记X轴: var downloadsChartData = { labels: ["4 Days", "3 Days", "2 Days", "Yesterday", "Today"], datasets: [{ label: "Google Play", fill: fals

我正在尝试使用chart.js在网页上显示一个折线图,显示过去5天特定客户端在apple store和google play store中的下载次数。数据正确显示,但未正确标记X轴:

var downloadsChartData = {
    labels: ["4 Days", "3 Days", "2 Days", "Yesterday", "Today"],
    datasets: [{
        label: "Google Play",
        fill: false,
        lineTension: 0,
        backgroundColor: "rgba(0, 230, 115, 1)",
        borderColor: "rgba(0, 230, 115, 1)",
        borderCapStyle: 'butt',
        borderJoinStyle: 'miter',
        borderWidth: 2,
        pointBorderColor: "rgba(150, 75, 75, 1)",
        pointBorderWidth: 3,
        pointRadius: 6,
        pointHoverRadius: 9,
        pointStyle: 'triangle',
        data: [{
            x: 1,
            y: 2
        }, {
            x: 2,
            y: 0
        }, {
            x: 3,
            y: 3
        }, {
            x: 4,
            y: 1
        }, {
            x: 5,
            y: 1
        }]
    }, {
        label: "iOS",
        fill: false,
        lineTension: 0,
        backgroundColor: "rgba(26, 117, 255, 1)",
        borderColor: "rgba(26, 117, 225, 1)",
        borderCapStyle: 'butt',
        borderJoinStyle: 'miter',
        borderWidth: 2,
        pointBorderColor: "rgba(150, 75, 75, 1)",
        pointBorderWidth: 3,
        pointRadius: 6,
        pointHoverRadius: 9,
        data: [{
            x: 1,
            y: 4
        }, {
            x: 2,
            y: 2
        }, {
            x: 3,
            y: 0
        }, {
            x: 4,
            y: 1
        }, {
            x: 5,
            y: 4
        }]
    }]
};

var downloadsChartOptions = {
    title: {
        display: true,
        text: 'Downloads on Google Play and App Store',
        fontSize: 30
    },
    scales: {
        xAxes: [{
            scaleLabel: {
                display: true,
                abelString: 'Date',
                fontSize: 20
            },
            type: 'linear',
            position: 'bottom',
            gridLines: {
                display: false
            }
        }],
        yAxes: [{
            scaleLabel: {
                display: true,
                labelString: 'Downloads',
                fontSize: 20
            }
        }]
    }
};

var downloadsChart = document.getElementById('downloadsChart').getContext('2d');
new Chart(downloadsChart, {
    type: 'line',
    data: downloadsChartData,
    options: downloadsChartOptions
});
我尝试将数据字段切换为一个值数组,以便Chart.js能够识别我在downloadsChartData中定义的标签:

但是,当我进行此更改时,图表不仅不能正确标记X轴,而且完全停止在折线图上显示数据


有人能指出我做错了什么吗?文档在这方面没有太大帮助。

文档在这一点上不是很清楚,但是对于绘制非数字数据,例如X轴表示日期的情况,您不能将X轴设置为线性刻度。换言之,如果使用线性比例设置轴,它将绘制数据的数字表示,因此不会绘制标签

我从下载的SchartOptions中删除了类型:“linear”,它解决了这个问题:

var downloadsChartOptions = {
    title: {
        display: true,
        text: 'Downloads on Google Play and App Store',
        fontSize: 30
    },
    scales: {
        xAxes: [{
            scaleLabel: {
                display: true,
                labelString: 'Date',
                fontSize: 20
            },
            //type: 'linear',
            position: 'bottom',
            gridLines: {
                display: false
            }
        }],
        yAxes: [{
            scaleLabel: {
                display: true,
                labelString: 'Downloads',
                fontSize: 20
            }
        }]
    }
};
var downloadsChartOptions = {
    title: {
        display: true,
        text: 'Downloads on Google Play and App Store',
        fontSize: 30
    },
    scales: {
        xAxes: [{
            scaleLabel: {
                display: true,
                labelString: 'Date',
                fontSize: 20
            },
            //type: 'linear',
            position: 'bottom',
            gridLines: {
                display: false
            }
        }],
        yAxes: [{
            scaleLabel: {
                display: true,
                labelString: 'Downloads',
                fontSize: 20
            }
        }]
    }
};