Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChartJS should be updated to 3.x to improve speed and bundle size #5809

Closed
1 task
JasonTheAdams opened this issue Apr 27, 2021 · 5 comments
Closed
1 task
Labels
Stale type: enhancement An improvement to existing user-facing functionality

Comments

@JasonTheAdams
Copy link
Contributor

Details

We use ChartJS for our reporting and are using ChartJS 2.x. It does a good job, but is absolutely massive and bloats the bundle size (~450kb). This also slows things down. About a month ago ChartJS 3.x came out which supports Tree Shaking. This is really the reason it was so huge.

Updating to ChartJS 3.x will help reduce the bundle size and overall speed.

Additional Context

Migration Guide: https://www.chartjs.org/docs/latest/getting-started/v3-migration.html

Acceptance Criteria

  • Reporting uses ChartJS 3.x
@JasonTheAdams JasonTheAdams added the type: enhancement An improvement to existing user-facing functionality label Apr 27, 2021
@kjohnson kjohnson self-assigned this May 12, 2021
@kjohnson
Copy link
Member

kjohnson commented May 12, 2021

Important Note: chartjs-plugin-crosshair is not compatible with Chart.JS 3.x - there is some community movement working on that upgrade, but the transition is not complete.

See AbelHeinsbroek/chartjs-plugin-crosshair#65

@kjohnson
Copy link
Member

@JasonTheAdams This is close enough, right? @DevinWalker won't notice a difference 😅

ChartJS 2.x ChartJS 3.x
Screenshot_2021-05-13 Donation Reports ‹ WordPress — WordPress(1) Screenshot_2021-05-13 Donation Reports ‹ WordPress — WordPress

@kjohnson
Copy link
Member

kjohnson commented May 13, 2021

There is a lot to dig through, so I don't think I'll be able to complete this upgrade before the next cycle.

That said, here are my notes on what I was able to upgrade:

  • Importing from chart.js now returns a spread of objects, not just the ChartJS class.
    • import { Chart as ChartJS } from 'chart.js'
  • Line tension needs to be specified in components/chart/utils/index::formatData(), as the default value is now 0.
    • tension: 0.4,
  • Tree shaking requires that controllers, elements, scales, and plugins are imported and registered as needed.
    • Chart.register(...registerables)
  • Time scales require importing the date library and adapter.
    • import 'chartjs-adapter-moment';

Also, I wasn't able to get the fill to work - in the example I was able to add a fill: true property/value alongside tension, but that did not seem to work locally.

@kjohnson kjohnson removed their assignment May 13, 2021
@github-actions
Copy link

This issue is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 14 additional days.

@github-actions github-actions bot added the Stale label Nov 16, 2022
@github-actions
Copy link

github-actions bot commented Dec 1, 2022

This issue was closed because it has been stalled for an additional 14 days with no activity.

@github-actions github-actions bot closed this as completed Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Stale type: enhancement An improvement to existing user-facing functionality
Projects
None yet
Development

No branches or pull requests

2 participants