Chartjs-Chart.js – scaleType='date' not working

0👍

First of all, since the documentation is messy, I’m not surprised you didn’t get how to create a time-scale chart. The actual call is the following :

window.myScatterxx = Chart.Scatter(ctx, {
    data: chartData,
    options: {
        title: {
            display: true,
            text: "it is now working",
            fontSize: 36
        },
        scales: {
            xAxes: [{
                // This is the important part
                type: "time",
            }]
        }
    },
});

Now you have the correct syntax, you’d need to import the correct library as well. As I can see in the piece of code you gave, you imported Chart.min.js, but you need more since you know work with the time element.

You can either :


Finally, I also noticed in your code you had a problem displaying tooltips for the red dataset. It is because you defined its color as Red. Change it to red and tooltips will work again :

datasets: [{
    borderColor: 'red',
    label: 'Capital R in borderColor, tooltips now work',
    data: [
        // ...
    ]
}]

You can see all these fixes live in this jsFiddle, and here is the final result :

enter image description here

Leave a comment