[Chartjs]-Chart.js How to align x-ticks?

1👍

GitHub user etimberg answered this:

removing source: ‘labels’ and setting unitStepSize: 0.5 achieves what you’re looking for. https://codepen.io/anon/pen/ZrQjXr

var data = {
    labels: ["2012-02-02 12:03:11", "2012-02-02 12:12:11", "2012-02-02 13:10:11", "2012-02-02 14:22:11"],
    datasets: [
        {
            label: "My First dataset",
            type: 'line',
            fillColor: "rgba(220,220,220,0.2)",
            strokeColor: "rgba(220,220,220,1)",
            pointColor: "rgba(220,220,220,1)",
            pointStrokeColor: "#fff",
            pointHighlightFill: "#fff",
            pointHighlightStroke: "rgba(220,220,220,1)",
            data: [65, 59, 80, 81]
        },
    ]
};

var options = {
    scales: {
        xAxes: [{
            type: 'time',
            time: {
                unit: 'hour',
                unitStepSize: 0.5,
                displayFormats: {
                    'hour': 'HH:mm'
                },
            },
            ticks:{
                maxTicksLimit: 20,
            },
        }],
        yAxes: [{
            scaleLabel: {
                display: true,
                labelString: 'Loading'
            },
        }],
    },

};;

var ctx = document.getElementById("myChart").getContext("2d");
var myLineChart = new Chart(ctx, {
    type: 'line',
    options: options,
    data: data
})

Leave a comment