date-fns adapter for Chart.js

Overview

chartjs-adapter-date-fns

release travis awesome

Overview

This adapter allows the use of date-fns with Chart.js.

Requires Chart.js 2.8.0 or later and date-fns 2.0.0 or later.

Note: once loaded, this adapter overrides the default date-adapter provided in Chart.js (as a side-effect).

Installation

npm

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

CDN

By default, https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns returns the latest (minified) version, however it's highly recommended to always specify a version in order to avoid breaking changes. This can be achieved by appending @{version} to the url:

<script src="https://cdn.jsdelivr.net/npm/chart.js/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-adapter-date-fns/dist/chartjs-adapter-date-fns.bundle.min.js"></script>

Read more about jsDeliver versioning on their website.

Configuration

Locale support via scale options

date-fns requires a date-fns locale object to be tagged on to each format() call, which requires the locale to be explicitly set via the adapters.date option: Chart.js documentation on adapters.date

For example:

// import date-fns locale:
import {de} from 'date-fns/locale';


// scale options:
{
    adapters: {
        date: {
            locale: de
        }
    }
}

Further, read the Chart.js documentation for other possible date/time related options. For example, the time scale time.* options can be overridden using the date-fns tokens.

Development

You first need to install node dependencies (requires Node.js):

> npm install

The following commands will then be available from the repository root:

> npm run build         // build dist files
> npm run lint          // perform code linting

License

chartjs-adapter-date-fns is available under the MIT license.

Comments
  • Need update for date-fns 2.0

    Need update for date-fns 2.0

    Hello

    The adapter need an update for version 2.0 of date-fns Its explain here: https://github.com/date-fns/date-fns/blob/master/docs/unicodeTokens.md

    Old: https://github.com/chartjs/chartjs-adapter-date-fns/blob/46c3bb8f33891e5a9934e1ab41788d858f2f8c14/src/index.js#L15-L26

    New version

    var FORMATS = {
    	datetime: 'MMM d, yyyy, h:mm:ss a',
    	millisecond: 'h:mm:ss.SSS a',
    	second: 'h:mm:ss a',
    	minute: 'h:mm a',
    	hour: 'ha',
    	day: 'MMM d',
    	week: 'w',
    	month: 'MMM yyyy',
    	quarter: '[Q]Q - yyyy',
    	year: 'yyyy'
    };
    

    May be show the version of date-fns for backward compatibility

    opened by sebtiz13 12
  • fix: use tree-shakeable imports from date-fns

    fix: use tree-shakeable imports from date-fns

    Problem:

    • current plugin imports directly from date-fns which causes the entire lib to be bundled

    Solution:

    • updated the imports to target the actual modules which export the utility methods used

    Documentation:

    • https://date-fns.org/v2.9.0/docs/ECMAScript-Modules

    Benefits:

    • 2x bundle size reduction 221kb vs 486kb
    opened by vladjerca 7
  • date-fns is a hard dependency of this adapter

    date-fns is a hard dependency of this adapter

    This has the benefit of both correctly installing required packages for end-user, as a well as formalize which version of date-fns is supported or not.

    opened by PowerKiKi 6
  • Module not found: Error: Can't resolve './locale'

    Module not found: Error: Can't resolve './locale'

    I'm trying to use this with Chart.js in my Stencil web component project, which also uses date-fns (not moment.js).

    Per the instructions, here is what I added to the particular component.tsx file:

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

    Still, NG throws this warning: Module not found: Error: Can't resolve './locale' in '/Users/..../stencil/oia-collection/dist/esm/es5/build'

    Anything I missed?

    Btw I'm using date-fns v2 - not sure if that makes a difference as it indeed is different to date-fns in some areas, such as a new formats API (Unicode Technical Standard #35).

    Re. date-fns v2 support, I will open a new issue, perhaps I can contribute a PR - shouldn't be a big change.

    EDIT: The error is thrown on the Ionic project level, not during the Stencil build process.

    opened by olivermuc 6
  • TypeError: 3 arguments required, but only 2 present

    TypeError: 3 arguments required, but only 2 present

    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

    opened by kyleabens 4
  • Importing adapter to typescript file

    Importing adapter to typescript file

    Hii, I recently tried to install chartjs-adapter-date-fns using npm install date-fns chartjs-adapter-date-fns --save. But I am using React with typecript and it is giving me following error "Could not find declaration file for module". I tried to install the module with @types/ but the type version of the adapter is not available. Question: How do add this adapter to my .tsx file?

    opened by vaibhav135 3
  • Adds option to override default formats in adapter

    Adds option to override default formats in adapter

    I think it’s possible to change time.scale with this adapter, but not possible to change time.displayFormat using this adapter.

    For example, you can change time.unit to 'month' to use date-fns to display the month, but you cannot use time.displayFormats to change the display of month from the default of MMM yyyy to your custom string MMMM.

    This Pull Request adds an option to pass in formats to modify the default FORMATS object.

    If there’s a different way of doing that already, that’s fine too! I intentionally didn’t call it displayFormats as it seems confusing to have time.displayFormats and also adapters.data.displayFormats, but maybe it’s also confusing to have them not match.

    This does use Object.assign for convenience, which I think works fine based on Chart.js’ browser support. If that’s an issue, the option could override the whole object instead.

    opened by kennethormandy 2
  • Error: No

    Error: No "exports" main defined

    This error keeps popping up, Error: No "exports" main defined in C:\Users\info\3D Objects\4-Soft\investors\node_modules\chart.js\package.json

    My code looks like this and it works without date fns:

    import {
      Chart as ChartJS,
      CategoryScale,
      LinearScale,
      PointElement,
      LineElement,
      Title,
      Tooltip,
      Legend,
      Filler,
      TimeScale,
    } from "chart.js";
    
    ChartJS.register(
      CategoryScale,
      LinearScale,
      PointElement,
      LineElement,
      Title,
      Tooltip,
      Legend,
      Filler,
      TimeScale
    );
    
    import "chartjs-adapter-date-fns";
    import { Line } from "react-chartjs-2";
    

    if i remove the import the code works fine

    opened by Forsto2012 1
  • Bump qs and body-parser

    Bump qs and body-parser

    Bumps qs and body-parser. These dependencies needed to be updated together. Updates qs from 6.7.0 to 6.11.0

    Changelog

    Sourced from qs's changelog.

    6.11.0

    • [New] [Fix] stringify: revert 0e903c0; add commaRoundTrip option (#442)
    • [readme] fix version badge

    6.10.5

    • [Fix] stringify: with arrayFormat: comma, properly include an explicit [] on a single-item array (#434)

    6.10.4

    • [Fix] stringify: with arrayFormat: comma, include an explicit [] on a single-item array (#441)
    • [meta] use npmignore to autogenerate an npmignore file
    • [Dev Deps] update eslint, @ljharb/eslint-config, aud, has-symbol, object-inspect, tape

    6.10.3

    • [Fix] parse: ignore __proto__ keys (#428)
    • [Robustness] stringify: avoid relying on a global undefined (#427)
    • [actions] reuse common workflows
    • [Dev Deps] update eslint, @ljharb/eslint-config, object-inspect, tape

    6.10.2

    • [Fix] stringify: actually fix cyclic references (#426)
    • [Fix] stringify: avoid encoding arrayformat comma when encodeValuesOnly = true (#424)
    • [readme] remove travis badge; add github actions/codecov badges; update URLs
    • [Docs] add note and links for coercing primitive values (#408)
    • [actions] update codecov uploader
    • [actions] update workflows
    • [Tests] clean up stringify tests slightly
    • [Dev Deps] update eslint, @ljharb/eslint-config, aud, object-inspect, safe-publish-latest, tape

    6.10.1

    • [Fix] stringify: avoid exception on repeated object values (#402)

    6.10.0

    • [New] stringify: throw on cycles, instead of an infinite loop (#395, #394, #393)
    • [New] parse: add allowSparse option for collapsing arrays with missing indices (#312)
    • [meta] fix README.md (#399)
    • [meta] only run npm run dist in publish, not install
    • [Dev Deps] update eslint, @ljharb/eslint-config, aud, has-symbols, tape
    • [Tests] fix tests on node v0.6
    • [Tests] use ljharb/actions/node/install instead of ljharb/actions/node/run
    • [Tests] Revert "[meta] ignore eclint transitive audit warning"

    6.9.7

    • [Fix] parse: ignore __proto__ keys (#428)
    • [Fix] stringify: avoid encoding arrayformat comma when encodeValuesOnly = true (#424)
    • [Robustness] stringify: avoid relying on a global undefined (#427)
    • [readme] remove travis badge; add github actions/codecov badges; update URLs
    • [Docs] add note and links for coercing primitive values (#408)
    • [Tests] clean up stringify tests slightly
    • [meta] fix README.md (#399)
    • Revert "[meta] ignore eclint transitive audit warning"

    ... (truncated)

    Commits
    • 56763c1 v6.11.0
    • ddd3e29 [readme] fix version badge
    • c313472 [New] [Fix] stringify: revert 0e903c0; add commaRoundTrip option
    • 95bc018 v6.10.5
    • 0e903c0 [Fix] stringify: with arrayFormat: comma, properly include an explicit `[...
    • ba9703c v6.10.4
    • 4e44019 [Fix] stringify: with arrayFormat: comma, include an explicit [] on a s...
    • 113b990 [Dev Deps] update object-inspect
    • c77f38f [Dev Deps] update eslint, @ljharb/eslint-config, aud, has-symbol, tape
    • 2cf45b2 [meta] use npmignore to autogenerate an npmignore file
    • Additional commits viewable in compare view

    Updates body-parser from 1.19.0 to 1.20.1

    Release notes

    Sourced from body-parser's releases.

    1.20.0

    1.19.2

    1.19.1

    Changelog

    Sourced from body-parser's changelog.

    1.20.1 / 2022-10-06

    1.20.0 / 2022-04-02

    1.19.2 / 2022-02-15

    1.19.1 / 2021-12-10

    Commits

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump socket.io-parser from 4.0.4 to 4.0.5

    Bump socket.io-parser from 4.0.4 to 4.0.5

    Bumps socket.io-parser from 4.0.4 to 4.0.5.

    Release notes

    Sourced from socket.io-parser's releases.

    4.0.5

    Bug Fixes

    • check the format of the index of each attachment (b559f05)

    Links

    Changelog

    Sourced from socket.io-parser's changelog.

    4.0.5 (2022-06-27)

    Bug Fixes

    • check the format of the index of each attachment (b559f05)

    4.2.0 (2022-04-17)

    Features

    • allow the usage of custom replacer and reviver (#112) (b08bc1a)

    4.1.2 (2022-02-17)

    Bug Fixes

    • allow objects with a null prototype in binary packets (#114) (7f6b262)

    4.1.1 (2021-10-14)

    4.1.0 (2021-10-11)

    Features

    • provide an ESM build with and without debug (388c616)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Bump karma from 6.3.2 to 6.3.14

    Bump karma from 6.3.2 to 6.3.14

    Bumps karma from 6.3.2 to 6.3.14.

    Release notes

    Sourced from karma's releases.

    v6.3.14

    6.3.14 (2022-02-05)

    Bug Fixes

    • remove string template from client code (91d5acd)
    • warn when singleRun and autoWatch are false (69cfc76)
    • security: remove XSS vulnerability in returnUrl query param (839578c)

    v6.3.13

    6.3.13 (2022-01-31)

    Bug Fixes

    • deps: bump log4js to resolve security issue (5bf2df3), closes #3751

    v6.3.12

    6.3.12 (2022-01-24)

    Bug Fixes

    • remove depreciation warning from log4js (41bed33)

    v6.3.11

    6.3.11 (2022-01-13)

    Bug Fixes

    • deps: pin colors package to 1.4.0 due to security vulnerability (a5219c5)

    v6.3.10

    6.3.10 (2022-01-08)

    Bug Fixes

    • logger: create parent folders if they are missing (0d24bd9), closes #3734

    v6.3.9

    6.3.9 (2021-11-16)

    Bug Fixes

    • restartOnFileChange option not restarting the test run (92ffe60), closes #27 #3724

    ... (truncated)

    Changelog

    Sourced from karma's changelog.

    6.3.14 (2022-02-05)

    Bug Fixes

    • remove string template from client code (91d5acd)
    • warn when singleRun and autoWatch are false (69cfc76)
    • security: remove XSS vulnerability in returnUrl query param (839578c)

    6.3.13 (2022-01-31)

    Bug Fixes

    • deps: bump log4js to resolve security issue (5bf2df3), closes #3751

    6.3.12 (2022-01-24)

    Bug Fixes

    • remove depreciation warning from log4js (41bed33)

    6.3.11 (2022-01-13)

    Bug Fixes

    • deps: pin colors package to 1.4.0 due to security vulnerability (a5219c5)

    6.3.10 (2022-01-08)

    Bug Fixes

    • logger: create parent folders if they are missing (0d24bd9), closes #3734

    6.3.9 (2021-11-16)

    Bug Fixes

    • restartOnFileChange option not restarting the test run (92ffe60), closes #27 #3724

    6.3.8 (2021-11-07)

    Bug Fixes

    • reporter: warning if stack trace contains generated code invocation (4f23b14)

    ... (truncated)

    Commits
    • c97e562 chore(release): 6.3.14 [skip ci]
    • 91d5acd fix: remove string template from client code
    • 69cfc76 fix: warn when singleRun and autoWatch are false
    • 839578c fix(security): remove XSS vulnerability in returnUrl query param
    • db53785 chore(release): 6.3.13 [skip ci]
    • 5bf2df3 fix(deps): bump log4js to resolve security issue
    • 36ad678 chore(release): 6.3.12 [skip ci]
    • 41bed33 fix: remove depreciation warning from log4js
    • c985155 docs: create security.md
    • c96f0c5 chore(release): 6.3.11 [skip ci]
    • Additional commits viewable in compare view

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 1
  • Uncaught TypeError: Cannot read properties of undefined (reading '_adapters')

    Uncaught TypeError: Cannot read properties of undefined (reading '_adapters')

    chartjs-adapter-date-fns.bundle.js:6225 Uncaught TypeError: Cannot read properties of undefined (reading '_adapters') at chartjs-adapter-date-fns.bundle.js:6225:10 at chartjs-adapter-date-fns.bundle.js:4:76 at chartjs-adapter-date-fns.bundle.js:5:2 (anonymous) @ chartjs-adapter-date-fns.bundle.js:6225 (anonymous) @ chartjs-adapter-date-fns.bundle.js:4 (anonymous) @ chartjs-adapter-date-fns.bundle.js:5

    opened by Shriniket33 3
  • Don't require

    Don't require "Chart.js"

    In order to support npm aliases, please let us pass the Chart object to a register function of this plugin. This helps to use this plugin if the chart.js version in use is not installed via chart.js specifically but for example an npm alias or other means.

    opened by codeofsumit 0
  • Support timezone?

    Support timezone?

    Hi,

    This adapter doesn't allow to specify a timezone when parsing/formatting dates, since, unline Luxon, date-fns options don't support timezones. There is an official complementary library, date-fns-tz, that adds functions with timezone support:

    • zonedTimeToUtc - Given a date and any time zone, returns a Date with the equivalent UTC time
    • utcToZonedTime - Get a date/time representing local time in a given time zone from the UTC date
    • getTimezoneOffset - Gets the offset in milliseconds between the time zone and UTC time
    • format - Extends date-fns/format with full time zone support
    • toDate - Can be used to create a zoned Date from a string containing an offset or IANA time zone

    I wonder what is the best strategy to support timezones:

    • Create a chartjs-adapter-date-fns-tz adapter that extends this one,
    • Or add a timezone option in this adapter, then calling date-fns-tz functions (I guess we should then make the dependency optional)?

    Since there is no too much logic in date adapters (i.e we just pass options to the underlying library), creating a distinct adapter may be a cleaner option?

    opened by jledentu 2
  • First tick label is not being rendered

    First tick label is not being rendered

    version: 2.0.0

    Here is the relevant configuration snippet:

            adapters: {
              date: {
                locale: nl,
              },
            },
            type: 'time',
            time: {
              unit: 'month',
              displayFormats: {
                month: 'dd MMM yy',
              },
            },
    

    As you can see the first value is empty:

    image

    opened by kdekooter 5
  • Failed to use with Chart.js 3.0.2 and time x axis

    Failed to use with Chart.js 3.0.2 and time x axis

    Hi, I updated our project our project dependecies to

    chart.js@>=3.0.2, chart.js@^3.0.2:
      version "3.0.2"
      resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-3.0.2.tgz#5893b0548714445b5190cbda9ac307357a56a0c7"
      integrity sha512-DR0GmFSlxcFJp/w//ZmbxSduAkH/AqwxoiZxK97KHnWZf6gvsKWS3160WvNMMHYvzW9OXqGWjPjVh1Qu+xDabg==
    
    chartjs-adapter-date-fns@>=2.0.0:
      version "2.0.0"
      resolved "https://registry.yarnpkg.com/chartjs-adapter-date-fns/-/chartjs-adapter-date-fns-2.0.0.tgz#5e53b2f660b993698f936f509c86dddf9ed44c6b"
      integrity sha512-rmZINGLe+9IiiEB0kb57vH3UugAtYw33anRiw5kS2Tu87agpetDDoouquycWc9pRsKtQo5j+vLsYHyr8etAvFw==
    

    and have (testing) graph like

    async renderChart2() {
        var speedCanvas = document.querySelector("#chart-2 canvas")
    
        var speedData = {
          labels: ["2021-01-01T23:00:00.000Z", "2021-01-02T23:00:00.000Z", "2021-01-03T23:00:00.000Z", "2021-01-04T23:00:00.000Z", "2021-01-05T23:00:00.000Z", "2021-01-06T23:00:00.000Z", "2021-01-07T23:00:00.000Z"],
          datasets: [{
            label: "Car Speed",
            data: [0, 59, 75, 20, 20, 55, 40],
            lineTension: 0,
            fill: false,
            borderColor: 'orange',
            backgroundColor: 'transparent',
            pointBorderColor: 'orange',
            pointBackgroundColor: 'rgba(255,150,0,0.5)',
            borderDash: [5, 5],
            pointRadius: 5,
            pointHoverRadius: 10,
            pointHitRadius: 30,
            pointBorderWidth: 2,
            pointStyle: 'rectRounded'
          }]
        }
    
        var chartOptions = {
          responsive: true,
          legend: {
            display: true,
            position: 'top',
            labels: {
              boxWidth: 80,
              fontColor: 'black'
            }
          },
          scales: {
            x: {
              type: "time",
              grid: {
                display: false,
                color: "black"
              },
              title: {
                display: true,
                text: "Time in Seconds",
                color: "red"
              }
            },
            y: {
              grid: {
                color: "black",
                borderDash: [2, 5],
              },
              title: {
                display: true,
                text: "Speed in Miles per Hour",
                color: "green"
              }
            }
          }
        }
        const Chart = await this.chart()
    
        var lineChart = new Chart(speedCanvas, {
          type: 'line',
          data: speedData,
          options: chartOptions
        })
      }
    
      async chart() {
          const { Chart, registerables } = await import('chart.js')
          Chart.register(...registerables)
    
          return Chart
        }
    
    

    And when I set some axis to be type: "time" , rendering of graphs fails

    image

    I am not strong in JS, but I digg deep and it seems to me that this

    import { toDate, parse, parseISO, isValid, format, addYears, addQuarters, addMonths, addWeeks, addDays, addHours, addMinutes, addSeconds, addMilliseconds, differenceInYears, differenceInQuarters, differenceInMonths, differenceInWeeks, differenceInDays, differenceInHours, differenceInMinutes, differenceInSeconds, differenceInMilliseconds, startOfYear, startOfQuarter, startOfMonth, startOfWeek, startOfDay, startOfHour, startOfMinute, startOfSecond, endOfYear, endOfQuarter, endOfMonth, endOfWeek, endOfDay, endOfHour, endOfMinute, endOfSecond } from 'date-fns';
    
    ....
    
    _adapters._date.override({
    ....
      format: function(time, fmt) {
        return format(time, fmt, this.options);
      },
    
    

    do not call date-fns.format but itself again.

    When I did litlle rename and change call in chart.js _tickFormatFunction(time, index, ticks, format):

      xformat: function(time, fmt) {
        return format(time, fmt, this.options);
      },
    

    all went OK

    image

    opened by foton 2
Releases(v3.0.0)
Owner
Chart.js
Simple, clean and engaging charts for designers and developers
Chart.js
This adapter allows the use of Moment.js with Chart.js

chartjs-adapter-moment Overview This adapter allows the use of Moment.js with Chart.js. Moment.js is a very heavy library and thus not recommended for

Chart.js 26 Dec 27, 2022
Luxon adapter for Chart.js

chartjs-adapter-luxon Overview This adapter allows the use of Luxon with Chart.js. Luxon provides built-in support for time zones and internationaliza

Chart.js 26 Dec 20, 2022
A Simple Dashboard Chart in Laravel Nova using Chart JS

A Simple Dashboard Chart in Laravel Nova using Chart JS. Starting create your own dashboard with Chart JS Integration can save your time and help you maintain consistency across standard elements such as Bar, Stacked, Line, Area, Doughnut and Pie Chart.

Kuncoro Wicaksono 177 Jan 4, 2023
Chart.js plugin to defer initial chart updates

Chart.js plugin to defer initial chart updates until the user scrolls and the canvas appears inside the viewport, and thus trigger the initial chart a

Chart.js 97 Nov 9, 2022
Bar Funnel Chart extension for Chart.js

Chart.BarFunnel.js Provides a Bar Funnel Chart for use with Chart.js Documentation To create a Bar Funnel Chart, include Chart.BarFunnel.js after Char

Chart.js 58 Nov 24, 2022
TradeX-chart is a trade chart written in plain (vanilla) JavaScript with minimal dependencies

TradeX-chart is a trade chart written in plain (vanilla) JavaScript with minimal dependencies; use it with any framework or backend.

null 24 Dec 12, 2022
Redefined chart library built with React and D3

Recharts Introduction Recharts is a Redefined chart library built with React and D3. The main purpose of this library is to help you to write charts i

recharts 19.4k Jan 2, 2023
:bar_chart: A D3-based reusable chart library

c3 c3 is a D3-based reusable chart library that enables deeper integration of charts into web applications. Follow the link for more information: http

C3.js 9.2k Jan 2, 2023
GPL version of Javascript Gantt Chart

dhtmlxGantt Getting started | Features | Follow us | License | Useful links dhtmlxGantt is an open source JavaScript Gantt chart that helps you illust

null 952 Dec 29, 2022
🍞📊 Beautiful chart for data visualization.

?? ?? Spread your data on TOAST UI Chart. TOAST UI Chart is Beautiful Statistical Data Visualization library. ?? Packages The functionality of TOAST U

NHN 5.2k Jan 2, 2023
:bar_chart: Re-usable, easy interface JavaScript chart library based on D3.js

billboard.js is a re-usable, easy interface JavaScript chart library, based on D3 v4+. The name "billboard" comes from the famous billboard chart whic

NAVER 5.4k Jan 1, 2023
:bar_chart: A library of modular chart components built on D3

Plottable Plottable is a library of chart components for creating flexible, custom charts for websites. It is built on top of D3.js and provides highe

Palantir Technologies 2.9k Dec 31, 2022
Chart image and QR code web API

QuickChart QuickChart is a service that generates images of charts from a URL. Because these charts are simple images, they are very easy to embed in

Ian Webster 1.3k Dec 25, 2022
📈 A small, fast chart for time series, lines, areas, ohlc & bars

?? μPlot A small (~35 KB min), fast chart for time series, lines, areas, ohlc & bars (MIT Licensed) Introduction μPlot is a fast, memory-efficient Can

Leon Sorokin 7.5k Jan 7, 2023
TChart.js - simple and configurable Bar and Line Chart library in Javascript

TChart.js Simple and configurable Bar and Line Chart library in Javascript Description TChart.js is a canvas-based simple Javascript Bar and Line Char

null 4 Mar 3, 2021
🍞📊 Beautiful chart for data visualization.

?? ?? Spread your data on TOAST UI Chart. TOAST UI Chart is Beautiful Statistical Data Visualization library. ?? Packages The functionality of TOAST U

NHN 5.2k Jan 6, 2023
The power of Chart.js in Jupyter !

The power of Chart.js in Jupyter Notebooks Installation You can install ipychart from your terminal using pip or conda: # using pip $ pip install ipyc

Nicolas H 68 Dec 8, 2022
Chart.js bindings for OCaml

chartjs-ocaml: OCaml bindings for Chart.js This library provides OCaml bindings for the Chart.js charting library and some popular plugins. Following

Alex Yanin 13 Aug 20, 2022
Java library for use with Chart.js javascript library

Chart.java Chart.java enables integration with the excellent Chart.js library from within a Java application. Usage example In Java: BarDataset datase

Marceau Dewilde 102 Dec 16, 2022