Skip to content

Commit

Permalink
Update docs to work with Chart.js 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrunel committed Apr 13, 2021
1 parent f7123f2 commit 9a49bce
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 12 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@

Highly customizable [Chart.js](http://www.chartjs.org/) plugin that displays labels on data for any type of charts.

Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **>= 2.7.0 < 3.x.x**.

See [this discussion](https://github.com/chartjs/chartjs-plugin-datalabels/discussions/213) for compatibility with Chart.js 3.
Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **3.x**.

## Documentation

Expand Down
4 changes: 1 addition & 3 deletions docs/guide/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
Highly customizable [Chart.js](http://www.chartjs.org/) plugin that displays labels on data for any type of charts.

::: warning COMPATIBILITY NOTE
Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **>= 2.7.0 < 3.x.x**.

See [this discussion](https://github.com/chartjs/chartjs-plugin-datalabels/discussions/213) for compatibility with Chart.js 3.
Requires [Chart.js](https://github.com/chartjs/Chart.js/releases) **3.x**
:::

::: danger IMPORTANT
Expand Down
10 changes: 5 additions & 5 deletions docs/guide/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ This plugin can also be installed using [Bower](https://bower.io/).
By default, `https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels` returns the latest (minified) version, however it's [**highly recommended**](https://www.jsdelivr.com/features) to always specify a version in order to avoid breaking changes. This can be achieved by appending `@{version}` to the url:

```
https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@1.1.2 // exact version
https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@1 // latest 1.x.x
https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0 // exact version
https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2 // latest 2.x.x
```

Read more about jsDeliver versioning on their [website](http://www.jsdelivr.com/).
Expand All @@ -42,8 +42,8 @@ You can download the latest version of `chartjs-plugin-datalabels` from the [Git
### HTML

```html
<script src="https://cdn.jsdelivr.net/npm/chart.js@2.9.4/dist/Chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@0.7.0"></script>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.0.0/dist/chart.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-datalabels@2.0.0"></script>
```

::: warning IMPORTANT
Expand All @@ -67,7 +67,7 @@ Since version 1.x, this plugin **no longer registers itself automatically**. It

```javascript
// Register the plugin to all charts:
Chart.plugins.register(ChartDataLabels);
Chart.register(ChartDataLabels);
```

```javascript
Expand Down
38 changes: 38 additions & 0 deletions docs/guide/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,41 @@ declare module 'chartjs-plugin-datalabels' {
}
}
```

## Migrating to v2.0.0

### Breaking Changes

Make sure to also read the [Chart.js v3 migration guide](https://www.chartjs.org/docs/latest/getting-started/v3-migration.html) since you may be impacted by more general breaking changes due to this new Chart.js version.

#### Plugin registration

Chart.js v3 changed the way to register plugins and now requires to use `Chart.register(plugin)` instead of `Chart.plugins.register(plugin)`.

```js
import {Chart} from 'chart.js';
import ChartDataLabels from 'chartjs-plugin-datalabels';

Chart.register(ChartDataLabels);
```

See [Getting Started > Registration](getting-started.html#registration) for details.

#### Default options

The plugin default options are now accessible in `Chart.defaults.plugins.datalabels.*` instead of `Chart.defaults.global.plugins.datalabels.*` and can be modified using:

```js
Chart.defaults.set('plugins.datalabels', {
color: 'blue',
// ...
})
```

See [Getting Started > Configuration](getting-started.html#configuration) for details.

### Notes

#### Chart.js type declaration <Badge text="TS only"/>

Chart.js v3 now provides TypeScript type declaration files bundled in the npm package so it's **not** anymore required to install the `@types/chart.js` package.
2 changes: 1 addition & 1 deletion docs/guide/typescript.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# TypeScript

This plugin provides TypeScript type declaration files bundled in the npm package so that types of this plugin options are checked when building your TypeScript project. Note that you also need the `@types/chart.js` package, if not already installed:
This plugin provides TypeScript type declaration files bundled in the npm package so that types of this plugin options are checked when building your TypeScript project.

```sh
npm install --save-dev @types/chart.js
Expand Down

0 comments on commit 9a49bce

Please sign in to comment.