mirror of
https://github.com/chartjs/Chart.js.git
synced 2024-10-08 13:19:07 +02:00
df3c73cc5e
Remove default of using chartjs-adapter-moment
49 lines
1.3 KiB
Markdown
49 lines
1.3 KiB
Markdown
# Integration
|
|
|
|
Chart.js can be integrated with plain JavaScript or with different module loaders. The examples below show how to load Chart.js in different systems.
|
|
|
|
## Script Tag
|
|
|
|
```html
|
|
<script src="path/to/chartjs/dist/Chart.js"></script>
|
|
<script>
|
|
var myChart = new Chart(ctx, {...});
|
|
</script>
|
|
```
|
|
|
|
## Common JS
|
|
|
|
```javascript
|
|
var Chart = require('chart.js');
|
|
var myChart = new Chart(ctx, {...});
|
|
```
|
|
|
|
## Bundlers (Webpack, Rollup, etc.)
|
|
|
|
```javascript
|
|
import Chart from 'chart.js';
|
|
var myChart = new Chart(ctx, {...});
|
|
```
|
|
|
|
## Require JS
|
|
|
|
**Important:** RequireJS [can **not** load CommonJS module as is](https://requirejs.org/docs/commonjs.html#intro), so be sure to require one of the UMD builds instead (i.e. `dist/Chart.js`, `dist/Chart.min.js`, etc.).
|
|
|
|
```javascript
|
|
require(['path/to/chartjs/dist/Chart.min.js'], function(Chart){
|
|
var myChart = new Chart(ctx, {...});
|
|
});
|
|
```
|
|
|
|
**Note:** in order to use the time scale, you need to make sure [one of the available date adapters](https://github.com/chartjs/awesome#adapters) and corresponding date library are fully loaded **after** requiring Chart.js. For this you can use nested requires:
|
|
|
|
```javascript
|
|
require(['chartjs'], function(Chart) {
|
|
require(['moment'], function() {
|
|
require(['chartjs-adapter-moment'], function() {
|
|
new Chart(ctx, {...});
|
|
});
|
|
});
|
|
});
|
|
```
|