You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/getting-started/integration.md
+72-76Lines changed: 72 additions & 76 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,89 +13,77 @@ Chart.js can be integrated with plain JavaScript or with different module loader
13
13
14
14
## Bundlers (Webpack, Rollup, etc.)
15
15
16
-
Chart.js 3 is tree-shakeable, so it is necessary to import and register the controllers, elements, scales and plugins you are going to use.
16
+
Chart.js is tree-shakeable, so it is necessary to import and register the controllers, elements, scales and plugins you are going to use.
17
17
18
-
For all available imports see the example below.
18
+
### Quick start
19
19
20
-
```javascript
21
-
import {
22
-
Chart,
23
-
ArcElement,
24
-
LineElement,
25
-
BarElement,
26
-
PointElement,
27
-
BarController,
28
-
BubbleController,
29
-
DoughnutController,
30
-
LineController,
31
-
PieController,
32
-
PolarAreaController,
33
-
RadarController,
34
-
ScatterController,
35
-
CategoryScale,
36
-
LinearScale,
37
-
LogarithmicScale,
38
-
RadialLinearScale,
39
-
TimeScale,
40
-
TimeSeriesScale,
41
-
Decimation,
42
-
Filler,
43
-
Legend,
44
-
Title,
45
-
Tooltip,
46
-
SubTitle
47
-
} from'chart.js';
48
-
49
-
Chart.register(
50
-
ArcElement,
51
-
LineElement,
52
-
BarElement,
53
-
PointElement,
54
-
BarController,
55
-
BubbleController,
56
-
DoughnutController,
57
-
LineController,
58
-
PieController,
59
-
PolarAreaController,
60
-
RadarController,
61
-
ScatterController,
62
-
CategoryScale,
63
-
LinearScale,
64
-
LogarithmicScale,
65
-
RadialLinearScale,
66
-
TimeScale,
67
-
TimeSeriesScale,
68
-
Decimation,
69
-
Filler,
70
-
Legend,
71
-
Title,
72
-
Tooltip,
73
-
SubTitle
74
-
);
75
-
76
-
constmyChart=newChart(ctx, {...});
77
-
```
78
-
79
-
A short registration format is also available to quickly register everything.
80
-
81
-
```javascript
82
-
import { Chart, registerables } from'chart.js';
83
-
Chart.register(...registerables);
84
-
```
85
-
86
-
And finally there is a separate path to do just the above for you, in one line:
20
+
If you don't care about the bundle size, you can use the `auto` package ensuring all features are available:
87
21
88
22
```javascript
89
23
importChartfrom'chart.js/auto';
90
24
```
91
25
92
-
## CommonJS
93
-
94
-
Because Chart.js is an ESM library, in CommonJS modules you should use a dynamic `import`:
95
-
96
-
```javascript
97
-
const { Chart } =awaitimport('chart.js');
98
-
```
26
+
### Bundle optimization
27
+
28
+
When optimizing the bundle, you need to import and register the components that are needed in your application.
29
+
30
+
The options are categorized into controllers, elements, plugins, scales. You can pick and choose many of these, e.g. if you are not going to use tooltips, don't import and register the `Tooltip` plugin. But each type of chart has its own bare-minimum requirements (typically the type's controller, element(s) used by that controller and scale(s)):
@@ -122,6 +110,14 @@ const chart = new Chart(ctx, {
122
110
});
123
111
```
124
112
113
+
## CommonJS
114
+
115
+
Because Chart.js is an ESM library, in CommonJS modules you should use a dynamic `import`:
116
+
117
+
```javascript
118
+
const { Chart } =awaitimport('chart.js');
119
+
```
120
+
125
121
## Require JS
126
122
127
123
**Important:** RequireJS can load only [AMD modules](https://requirejs.org/docs/whyamd.html), so be sure to require one of the UMD builds instead (i.e. `dist/chart.umd.js`).
0 commit comments