New contributions to the library are welcome, but we ask that you please follow these guidelines:
- Before opening a PR for major additions or changes, please discuss the expected API and/or implementation by filing an issue or asking about it in the Chart.js Discord #dev channel. This will save you development time by getting feedback upfront and make reviews faster by giving the maintainers more context and details.
- Consider whether your changes are useful for all users, or if creating a Chart.js plugin would be more appropriate.
- Check that your code will pass tests and
eslintcode standards.pnpm testwill run both the linter and tests for you. - Add unit tests and document new functionality (in the
test/anddocs/directories respectively). - Avoid breaking changes unless there is an upcoming major release, which is infrequent. We encourage people to write plugins for the most new advanced features, and care a lot about backward compatibility.
- We strongly prefer new methods to be added as private whenever possible. A method can be made private either by making a top-level
functionoutside of a class or by prefixing it with_and adding@privateJSDoc if inside a class. Public APIs take considerable time to review and become locked once implemented as we have limited ability to change them without breaking backward compatibility. Private APIs allow the flexibility to address unforeseen cases.
Active committers and contributors are invited to introduce themselves and request commit access to this project. We have a very active Discord community that you can join here. If you think you can help, we'd love to have you!
Firstly, we need to ensure development dependencies are installed. With Node.js (22.12 or later, 24, or 26 and later) and pnpm installed, after cloning the Chart.js repo to a local directory, and navigating to that directory in the command line, we can run the following:
> pnpm install
> pnpm exec playwright install chromium firefoxThis will install the local development dependencies for Chart.js, and once, the browsers the Vitest specs run in.
The following commands are now available from the repository root:
> pnpm run build // build dist files in ./dist
> pnpm run autobuild // build and watch for source changes
> pnpm run dev // run the Karma specs in Chrome and watch for source and test changes
> pnpm run dev:ff // the same in Firefox
> pnpm run dev:vitest // run the Vitest specs in Chromium and watch for source and test changes
> pnpm run lint // perform code linting (ESLint, tsc)
> pnpm test // perform code linting and run all tests with coverage
> pnpm run test-ci-karma // run the Karma specs once, in Chrome and Firefox
> pnpm run test-ci-vitest // run the Vitest specs once, in Chromium and Firefox
> pnpm run test-ci-umd // run the smoke suite against dist/chart.umd.min.js, in Chromium and FirefoxThe test suite is moving from Karma and Jasmine to Vitest browser mode. Until that is done, both run, and the name of a spec file decides which one: test/specs/*.tests.js runs under Karma, test/specs/*.spec.js under Vitest. Vitest specs run against the source in src/ with no build step, and use Vitest's API (vi.spyOn, expect.objectContaining, ...) instead of Jasmine's.
A small smoke suite in test/umd checks the built bundle instead of the source: that dist/chart.umd.min.js loads, has the whole Chart namespace and renders a few of the image fixtures. Its config is vitest.umd.config.js. It, and the packages in test/integration, use the files in dist, so run pnpm run build before pnpm test or pnpm run test-ci, and again after changing the source; without a build the smoke suite stops and says so.
pnpm run dev, pnpm run dev:ff, pnpm run dev:vitest, pnpm run test-ci-karma and pnpm run test-ci-vitest can be appended with a string that is used to match the spec filenames. For example: pnpm run dev plugin will start Karma in watch mode for test/specs/**/*plugin*.tests.js, and pnpm run dev:vitest plugin will do the same with Vitest for the *.spec.js files whose path contains plugin. pnpm test takes no such string.
All image-based tests run under Vitest from the one file test/specs/fixtures.spec.js, so a file name does not select them. Filter by test name with -t instead. Each fixture test is named after its path under test/fixtures without the extension (scale.time/ticks-round), in a group named after its top-level directory. -t takes a regular expression and runs every test whose full name contains a match, so -t scale.time runs scale.timeseries too. Include the slash to select one directory: pnpm run dev:vitest fixtures -t "scale\.time/" runs the fixtures in test/fixtures/scale.time and its subdirectories, and -t "controller\.bar/stacking/" only those in test/fixtures/controller.bar/stacking. End with $ to select one fixture: -t "scale\.time/ticks-round$".
Vitest runs the tests in a random order and prints the seed it used (Running tests with seed "..."). To repeat an order, pass the seed: pnpm run test-ci-vitest --sequence.seed=<seed>.
We use Vuepress to manage the docs which are contained as Markdown files in the docs directory. You can run the doc server locally using these commands:
> pnpm run docs:devSome display-related functionality is difficult to test via typical unit tests. For this reason, we introduced image-based tests (#3988 and #5777) to assert that a chart is drawn pixel-for-pixel matching an expected image.
Generated charts in image-based tests should be as minimal as possible and focus only on the tested feature to prevent failure if another feature breaks (e.g. disable the title and legend when testing scales).
Every config file under test/fixtures is a test: test/specs/fixtures.spec.js finds them all and compares each rendered chart with the PNG of the same name, in Chromium and Firefox. No spec needs a line for it. You can create a new image-based test by following the steps below:
- Create a JS file (example) or JSON file (example) that defines chart config and generation options. A JS file sets
module.exports, as the existing ones do; it can use the globalsChart,momentandtriggerMouseEvent. - Add this file in
test/fixtures/{area}/{feature-name}.json(or.js), where{area}is an existing directory or a new one. - Run
pnpm run fixtures:update -t "{area}/{feature-name}$". It renders the selected fixtures in Chromium and writes the PNG of each one whose image is missing or differs, printing each file it writes. Without-tit does this for every fixture. (-ttakes a regular expression, as described under Building and Testing; the$keeps it from also selecting{feature-name}-something.) - Look at the written
test/fixtures/{area}/{feature-name}.png: it should show the feature and nothing it does not test, with no tooltip or hover effect. - Run
pnpm run test-ci-vitest fixtures -t "{area}/{feature-name}$": the test should pass in both browsers. - Verify test relevancy by changing the feature values slightly in the config file: the test should then fail.
Only pnpm run fixtures:update writes images; every other run compares, and a fixture without a PNG fails with a message naming it. Run the update for a fixture whose image you mean to change, and look at each PNG it rewrites before committing it.
Tests should pass in both browsers. In general, we've hidden all text in image tests since it's quite difficult to get them to pass between different browsers. As a result, it is recommended to hide all scales in image-based tests. It is also recommended to disable animations. If tests still do not pass, adjust tolerance (the accepted ratio of differing pixels) and/or threshold (how different a pixel must be to count) at the beginning of the config file, keeping them as low as possible.
When a test fails, the actual, expected and difference images are logged to the browser console, where the Vitest UI (pnpm run dev:vitest) shows them. If you'd like to see the images of a test that passes, set "debug": true in the config file: the test then always fails and logs them. Remove it before committing.
Please report these on the GitHub page - at github.com/chartjs/Chart.js. Please do not use issues for support requests. For help using Chart.js, please take a look at the chart.js tag on Stack Overflow.
Well-structured, detailed bug reports are hugely valuable for the project.
Guidelines for reporting bugs:
- Check the issue search to see if it has already been reported
- Isolate the problem to a simple test case
- Please include a demonstration of the bug on a website such as JS Bin, JS Fiddle, or Codepen. (Template). If filing a bug against
master, you may reference the latest code via https://www.chartjs.org/dist/master/chart.umd.min.js (changing the filename to point at the file you need as appropriate). Do not rely on these files for production purposes as they may be removed at any time.
Please provide any additional details associated with the bug, if it's browser or screen density specific, or only happens with a certain configuration or data.