You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To be able to include Moment.js and Chart.js with RequireJS without using the bundle version of Chart.js to avoid that Moment.js has to be included twice and possibly in different versions.
Current Behavior
The example at https://jsfiddle.net/8m67zr8y/1/ shows that Chart.js cannot find Moment.js, although Moment.js is basically available.
The example at https://jsfiddle.net/8m67zr8y/ shows the current possibility. However, Moment.js is included twice in this case.
Possible Solution
Provide a configuration option to pass a reference to the Moment.js instance explicitly or try to include Moment.js in an AMD environment with require('moment') for example.
The problem is that the moment.js library doesn't expose the global window.moment function.
Adding the following will make it work. https://jsfiddle.net/8m67zr8y/3/
define('moment-adapter',['moment'],function(moment){// Set the global.window.moment=moment;returnmoment;});require(['jquery','moment-adapter','chartjs'],function($,moment,Chart){
So simple, so good. The problem is solved. But is there no way without the global Moment.js function? In the AMD context this seems a bit "dirty" from my point of view.
At the moment I think this is your only option using requirejs. Until Chart.js acquires the possibility of a pluggable time library. For now it is hard coded: scales/scale.time.js#L5
Expected Behavior
To be able to include Moment.js and Chart.js with RequireJS without using the bundle version of Chart.js to avoid that Moment.js has to be included twice and possibly in different versions.
Current Behavior
The example at https://jsfiddle.net/8m67zr8y/1/ shows that Chart.js cannot find Moment.js, although Moment.js is basically available.
The example at https://jsfiddle.net/8m67zr8y/ shows the current possibility. However, Moment.js is included twice in this case.
Possible Solution
Provide a configuration option to pass a reference to the Moment.js instance explicitly or try to include Moment.js in an AMD environment with
require('moment')
for example.Steps to Reproduce (for bugs)
See examples at https://jsfiddle.net/8m67zr8y/ and https://jsfiddle.net/8m67zr8y/1/
The text was updated successfully, but these errors were encountered: