Chart.js

Welcome to Chart.js!

Why Chart.js

Among many charting librariesChart.js - 图4 (opens new window) for JavaScript application developers, Chart.js is currently the most popular one according to GitHub starsChart.js - 图5 (opens new window) (~60,000) and npm downloadsChart.js - 图6 (opens new window) (~2,400,000 weekly).

Chart.js was created and announcedChart.js - 图7 (opens new window) in 2013 but has come a long way since then. It’s open-source, licensed under the very permissive MIT licenseChart.js - 图8 (opens new window), and maintained by an active community.

Features

Chart.js provides a set of frequently used chart types, plugins, and customization options. In addition to a reasonable set of built-in chart types, you can use additional community-maintained chart typesChart.js - 图9 (opens new window). On top of that, it’s possible to combine several chart types into a mixed chart (essentially, blending multiple chart types into one on the same canvas).

Chart.js is highly customizable with custom pluginsChart.js - 图10 (opens new window) to create annotations, zoom, or drag-and-drop functionalities to name a few things.

Defaults

Chart.js comes with a sound default configuration, making it very easy to start with and get an app that is ready for production. Chances are you will get a very appealing chart even if you don’t specify any options at all. For instance, Chart.js has animations turned on by default, so you can instantly bring attention to the story you’re telling with the data.

Integrations

Chart.js comes with built-in TypeScript typings and is compatible with all popular JavaScript frameworksChart.js - 图11 (opens new window) including ReactChart.js - 图12 (opens new window), VueChart.js - 图13 (opens new window), SvelteChart.js - 图14 (opens new window), and AngularChart.js - 图15 (opens new window). You can use Chart.js directly or leverage well-maintained wrapper packages that allow for a more native integration with your frameworks of choice.

Developer experience

Chart.js has very thorough documentation (yes, you’re reading it), API reference, and examples. Maintainers and community members eagerly engage in conversations on SlackChart.js - 图16 (opens new window), GitHub DiscussionsChart.js - 图17 (opens new window), and Stack OverflowChart.js - 图18 (opens new window) where more than 11,000 questions are tagged with chart.js.

Canvas rendering

Chart.js renders chart elements on an HTML5 canvas unlike several other, mostly D3.js-based, charting libraries that render as SVG. Canvas rendering makes Chart.js very performant, especially for large datasets and complex visualizations that would otherwise require thousands of SVG nodes in the DOM tree. At the same time, canvas rendering disallows CSS styling, so you will have to use built-in options for that, or create a custom plugin or chart type to render everything to your liking.

Performance

Chart.js is very well suited for large datasets. Such datasets can be efficiently ingested using the internal format so you can skip data parsing and normalization. Alternatively, data decimation can be configured to sample the dataset and reduce its size before rendering.

In the end, the canvas rendering that Chart.js uses reduces the toll on your DOM tree in comparison to SVG rendering. Also, tree-shaking support allows you to include minimal parts of Chart.js code into your bundle, reducing bundle size and page load time.

Community

Chart.js is actively developedChart.js - 图19 (opens new window) and maintained by the community. With minor releasesChart.js - 图20 (opens new window) on an approximately bi-monthly basis and major releases with breaking changes every couple of years, Chart.js keeps the balance between adding new features and making it a hassle to keep up with them.