Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Simple adapter for time axes

Open mnlipp opened this issue 2 years ago • 3 comments

Feature Proposal

Having rather simple use cases and reading these articles "Do you really need a date library?" I was wondering whether it wasn't possible to write an adapter for basic needs using Intl.DateTimeFormat only.

Possible Implementation

Here is my code. It might serve as a starter for a default adapter that needs to be replaced with a date library based adapter only if more sophisticated parsing/formatting functions are required.

mnlipp avatar Apr 22 '22 18:04 mnlipp

I think the date-fns adapter is about as barebones as can be. I believe date-fns only using standards under the hood

etimberg avatar Apr 22 '22 21:04 etimberg

Afaik date-fns doesn't use Intl.DateTimeFormat and support for l10n has to be configured for each language. Besides, it seems to be rather big.

But I don't insist on this in any way. My code solves my problem and I was only thinking that it would be nice for chart.js to be usable without a mandatory dependency for using the time axes.

mnlipp avatar Apr 23 '22 09:04 mnlipp

Guys, I've taken your code and adapted it a bit so that it's now a usable adapter: the project is here: https://github.com/gcollin/chartjs-adapter-date-std

Now if you npm install chartjs-adapter-date-std register once the adapter (it's not automatically done) with _adapters._date.override( StdDateAdapter.chartJsStandardAdapter()); then you get working time axis adapter with no dependencies.

gcollin avatar Sep 07 '22 22:09 gcollin