chartjs / chartjs-adapter-date-fns

date-fns adapter for Chart.js
MIT License
100 stars 35 forks source link

TypeError: 3 arguments required, but only 2 present #6

Closed kyleabens closed 4 years ago

kyleabens commented 4 years ago

I use chart.js and just found out that I can also use date-fns with it by installing this adapter. I install it and imported it as instructed...

import { Chart } from 'chart.js';
import 'chartjs-adapter-date-fns';

But now I receive the following error:

TypeError: 3 arguments required, but only 2 present
    at Module.parse (index.js:350)
    at DateAdapter.parse (chartjs-adapter-date-fns.js:37)
    at toTimestamp (Chart.js:12736)
    at parse (Chart.js:12763)
    at ChartElement.determineDataLimits (Chart.js:13056)
    at ChartElement.update (Chart.js:10310)
    at ChartElement.update (Chart.js:13027)
    at getMinimumBoxSize (Chart.js:6368)
    at Object.each (Chart.js:1801)
    at Object.update (Chart.js:6382)
    at resolvePromise (zone.js:852)
    at resolvePromise (zone.js:809)
    at zone.js:913
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:423)
    at Object.onInvokeTask (core.js:25999)
    at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:422)
    at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:195)
    at drainMicroTaskQueue (zone.js:601)

I use date-fns 2.4.1. This could be an issue since there were some breaking changes when upgrading to v2 and this error seems to be a result of the new parse function that I guess requires a 3rd argument https://date-fns.org/v2.4.1/docs/parse

With that being said I suppose this is more a feature request to upgrade the adapter to handle date-fns v2

kyleabens commented 4 years ago

Just noticed #4 and after installing 1.0.0-alpha1 the error has been resolved but now there are no labels being displayed on the x axis. No errors are logged so I'm not sure why.

kyleabens commented 4 years ago

Nevermind that was an issue on my end and I was also able to add a custom webpack config file so I could remove moment from the bundle.

darylteo commented 4 years ago

For anyone coming here for the same issue, I "fixed" this "properly" by creating a copy of index.js into my project.

parse is now parseISO just rename that.

If you're using ts, you'll need to @ts-ignore the import statement of _adapters, and add explicit any to all variables.

Then all Y and D date format strings have to be lower cased, to match the unicode specification.

https://gist.github.com/darylteo/083e926336f6a0eda589618ddc814f79

nurudeendisguise commented 2 years ago

@darylteo, renaming parse to parseISO during imports works for me.

I was using parse with the date-fns library so the issue above came up.

Thanks