[Chartjs]-Charts.js: Moment is not defined (using chart.bundle.min.js)

4πŸ‘

βœ…

It looks to me like Moment for some reason is not available in the bundle I have tried your code in JSFiddle and there is an error, however is load in Moment.js serpatley it works great.

Maybe use Chart.js and Moment.js and not the bundle, if you are worried about http requests you could always compress and bundle them yourself?

0πŸ‘

I looked at the documentation of charts.js :

When providing data for the time scale, Chart.js supports all of the formats that Moment.js accepts. See Moment.js docs for details.

So, you should use Chart.js api like this :

var chart = new Chart(ctx, {
type: 'line',
data: data,
options: {
scales: {
xAxes: [{
type: 'time',
time: {
displayFormats: {
quarter: 'MMM YYYY'
}
}
}]
}
}
})

not moment().add()

Leave a comment