简体   繁体   中英

Chartjs not showing all data points

I have a dataset with 3 points in it, but only two are being shown on the chart 图形

The code to create this graph is

var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
type: 'line',
data: {
    datasets: [{
        label: 'Submission',
        data: [{
            t: new Date("April 1, 2018"),
            y: 2
        }, {
            t: new Date("April 10, 2018"),
            y: 1
        }, {
            t: new Date("April 27, 2018"),
            y: 1
        }],
        backgroundColor: ["rgba(90, 150, 200, 0.6)"]
    }]
},
options: {
    scales: {
        yAxes: [{
            ticks: {
                beginAtZero: true
            }
        }]
    }
}
});

Clearly there are three data points but it seems to only show the 2 on the chart. How can this be fixed?

I fixed this by adding labels for each data point. 在此处输入图片说明

var ctx = document.getElementById("myChart");
var myChart = new Chart(ctx, {
    type: 'line',
    data: {
        labels: ["April 1, 2018", "April 10, 2018", "April 27, 2018", ],
        datasets: [{
            label: 'Submission',
            data: [{
                t: new Date("April 1, 2018"),
                y: 2
            }, {
                t: new Date("April 10, 2018"),
                y: 1
            }, {
                t: new Date("April 27, 2018"),
                y: 1
            }, {
                t: new Date(),
                y: 0
            }],
            backgroundColor: ["rgba(90, 150, 200, 0.6)"]
        }]
    },
    options: {
        scales: {
            yAxes: [{
                ticks: {
                    beginAtZero: true
                }
            }]
        }
    }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM