javascript - Chartjs not showing all data points - Stack Overflow

I have a dataset with 3 points in it, but only two are being shown on the chartThe code to create this

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 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?

Share asked Apr 28, 2018 at 15:40 adammoyleadammoyle 3092 silver badges14 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

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
                }
            }]
        }
    }
});

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745044029a4607985.html

相关推荐

  • javascript - Chartjs not showing all data points - Stack Overflow

    I have a dataset with 3 points in it, but only two are being shown on the chartThe code to create this

    7小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信