Skip to content

Commit

Permalink
docs: add guide for migration from vue-chart-3 (apertureless#856)
Browse files Browse the repository at this point in the history
  • Loading branch information
thabarbados committed May 19, 2022
1 parent 604c584 commit abce7dd
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -224,7 +224,8 @@ export default {

- [Reactivity](https://vue-chartjs.org/guide/#updating-charts)
- [Access to Chart instance](https://vue-chartjs.org/guide/#access-to-chart-instance)
- [Migration to v4](https://vue-chartjs.org/migration-to-v4/)
- [Migration from v3 to v4](https://vue-chartjs.org/migration-guides/#migration-from-v3-to-v4/)
- [Migration from vue-chart-3](https://vue-chartjs.org/migration-guides/#migration-from-vue-chart-3/)
- [API](https://vue-chartjs.org/api/)
- [Examples](https://vue-chartjs.org/examples/)

Expand Down
6 changes: 3 additions & 3 deletions website/src/.vitepress/config.ts
Expand Up @@ -19,9 +19,9 @@ export default defineConfig({
nav: [
{ text: 'Guide', link: '/guide/', activeMatch: '^/guide/' },
{
text: 'Migration to V4',
link: '/migration-to-v4/',
activeMatch: '^/migration-to-v4/'
text: 'Migration guides',
link: '/migration-guides/',
activeMatch: '^/migration-guides/'
},
{
text: 'API',
Expand Down
4 changes: 2 additions & 2 deletions website/src/guide/index.md
Expand Up @@ -259,7 +259,7 @@ Also you can get access to **updateChart** function
this.$refs.bar.updateChart()
```

### Events
## Events

Charts will emit events if the data changes. You can listen to them in the chart component. The following events are available:

Expand All @@ -268,7 +268,7 @@ Charts will emit events if the data changes. You can listen to them in the chart
- `chart:updated` - if the update handler performs an update instead of a re-render
- `labels:updated` - if new labels were set

### chartjs-plugin-annotation
## chartjs-plugin-annotation

When using [chartjs-plugin-annotation](https://www.chartjs.org/chartjs-plugin-annotation/latest/) and **Vue 2** simultaneously, you will not be able to place multiple reactive charts on one page.

Expand Down
@@ -1,10 +1,10 @@
# Migration to v4
## Migration from v3 to v4

With v4, this library introduces a number of breaking changes. In order to improve performance, offer new features, and improve maintainability, it was necessary to break backwards compatibility, but we aimed to do so only when worth the benefit.

v4 is fully compatible with Chart.js v3.

## Tree-shaking
### Tree-shaking

v4 of this library, [just like Chart.js v3](https://www.chartjs.org/docs/latest/getting-started/v3-migration.html#setup-and-installation), is tree-shakable. It means that you need to import and register the controllers, elements, scales, and plugins you want to use.

Expand Down Expand Up @@ -43,7 +43,7 @@ import { Chart as ChartJS, Title, Tooltip, Legend, ArcElement, CategoryScale } f
ChartJS.register(Title, Tooltip, Legend, ArcElement, CategoryScale)
```

## Changing the creation of Charts
### Changing the creation of Charts

In v3, you needed to import the component, and then either use extends or mixins and add it.

Expand Down Expand Up @@ -121,7 +121,7 @@ export default {
</script>
```

## New reactivity system
### New reactivity system

v3 does not update or re-render the chart if new data is passed. You needed to use `reactiveProp` and `reactiveData` mixins for that.

Expand Down Expand Up @@ -165,3 +165,54 @@ export default {
}
</script>
```

## Migration from vue-chart-3

### Uninstall vue-chart-3

```bash
pnpm rm vue-chart-3
# or
yarn remove vue-chart-3
# or
npm uninstall vue-chart-3
```

### Install vue-chartjs

```bash
pnpm add vue-chartjs
# or
yarn add vue-chartjs
# or
npm i vue-chartjs
```

### Change component import path

For Vue 3 projects:

```javascript
import { /* component */ } from 'vue-chartjs'
```

For Vue 2 projects:

```javascript
import { /* component */ } from 'vue-chartjs/legacy'
```

### Rename components

- BarChart to Bar
- DoughnutChart to Doughnut
- LineChart to Line
- PieChart to Pie
- PolarAreaChart to PolarArea
- RadarChart to Radar
- BubbleChart to Bubble
- ScatterChart to Scatter

### Rename props

- options to chartOptions

0 comments on commit abce7dd

Please sign in to comment.