## File: README.md
# vue-chartjs
**vue-chartjs** is a wrapper for [Chart.js](https://github.com/chartjs/Chart.js) in Vue. You can easily create reuseable chart components.
Supports Chart.js v4.
[](https://badge.fury.io/js/vue-chartjs)
[](https://codecov.io/gh/apertureless/vue-chartjs)
[](https://github.com/apertureless/vue-chartjs/actions)
[](http://packagequality.com/#?package=vue-chartjs)
[](https://www.npmjs.com/package/vue-chartjs)
[](https://gitter.im/vue-chartjs/Lobby)
[](https://github.com/apertureless/vue-chartjs/blob/master/LICENSE.txt)
[](https://cdnjs.com/libraries/vue-chartjs)
[](https://snyk.io/test/github/apertureless/vue-chartjs)
[](https://www.paypal.me/apertureless/50eur)
[](https://ko-fi.com/C0C1WP7C)
[QuickStart](#quickstart)
•
[Docs](#docs)
•
[Stack Overflow](https://stackoverflow.com/questions/tagged/vue-chartjs)
## Quickstart
Install this library with peer dependencies:
```bash
pnpm add vue-chartjs chart.js
# or
yarn add vue-chartjs chart.js
# or
npm i vue-chartjs chart.js
```
Then, import and use individual components:
```vue
```
Need an API to fetch data? Consider [Cube](https://cube.dev/?ref=eco-vue-chartjs), an open-source API for data apps.
[](https://cube.dev/?ref=eco-vue-chartjs)
## Docs
- [Reactivity](https://vue-chartjs.org/guide/#updating-charts)
- [Access to Chart instance](https://vue-chartjs.org/guide/#access-to-chart-instance)
- [Accessibility](https://vue-chartjs.org/guide/#accessibility)
- [Migration from v4 to v5](https://vue-chartjs.org/migration-guides/#migration-from-v4-to-v5/)
- [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/)
## Build Setup
``` bash
# install dependencies
pnpm install
# build for production with minification
pnpm build
# run unit tests
pnpm test:unit
# run all tests
pnpm test
```
## Contributing
1. Fork it ( https://github.com/apertureless/vue-chartjs/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## License
This software is distributed under [MIT license](LICENSE.txt).
[](https://www.buymeacoffee.com/xcqjaytbl)
---
## File: website/src/de/guide/examples.md
# Examples
## Chart with props
Your goal should be to create reusable chart components. For this purpose, you should utilize Vue.js props to pass in chart options and chart data. This way, the parent component itself does not hold an opinion about fetching data and is only for presentation.
```vue
```
## Chart with local data
You can handle your chart data directly in your parent component.
```vue
```
## Chart with API data
A common pattern is to use an API to retrieve your data. However, there are some things to keep in mind. The most common problem is that you mount your chart component directly and pass in data from an asynchronous API call. The problem with this approach is that Chart.js tries to render your chart and access the chart data synchronously, so your chart mounts before the API data arrives.
To prevent this, a simple `v-if` is the best solution.
Create your chart component with a data prop and options prop, so we can pass in our data and options from a container component.
```vue
```
## Chart with dynamic styles
You can set `responsive: true` and pass in a styles object which gets applied as inline styles to the outer ``. This way, you can change the height and width of the outer container dynamically, which is not the default behaviour of Chart.js. It is best to use computed properties for this.
::: warning
You need to set `position: relative`
:::
```vue
```
## Custom / New Charts
Sometimes you need to extend the default Chart.js charts. There are a lot of [examples](http://www.chartjs.org/docs/latest/developers/charts.html) on how to extend and modify the default charts. Or, you can create your own chart type.
In `vue-chartjs`, you can do this pretty much the same way:
```js
// 1. Import Chart.js so you can use the global Chart object
import { Chart } from 'chart.js'
// 2. Import the `createTypedChart()` method to create the vue component.
import { createTypedChart } from 'vue-chartjs'
// 3. Import needed controller from Chart.js
import { LineController } from 'chart.js'
// 3. Extend one of the default charts
// http://www.chartjs.org/docs/latest/developers/charts.html
class LineWithLineController extends LineController { /* custom magic here */}
// 4. Generate the vue-chartjs component
// The first argument is the chart-id, the second the chart type, third is the custom controller
const CustomLine = createTypedChart('line', LineWithLineController)
// 5. Extend the CustomLine Component just like you do with the default vue-chartjs charts.
export default {
components: { CustomLine }
}
```
## Resources
Here are some resources, such as tutorials, on how to use `vue-chartjs`:
- [Using vue-chartjs with WordPress](https://medium.com/@apertureless/wordpress-vue-and-chart-js-6b61493e289f)
- [Create stunning Charts with Vue and Chart.js](https://hackernoon.com/creating-stunning-charts-with-vue-js-and-chart-js-28af584adc0a)
- [Let’s Build a Web App with Vue, Chart.js and an API Part I](https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44)
- [Let’s Build a Web App with Vue, Chart.js and an API Part II](https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-part-ii-39781b1d5acf)
- [Build a realtime chart with VueJS and Pusher](https://blog.pusher.com/build-realtime-chart-with-vuejs-pusher/)
---
## File: website/src/de/guide/index.md
# Getting Started
**vue-chartjs** is a wrapper for [Chart.js](https://github.com/chartjs/Chart.js) in Vue. You can easily create reuseable chart components.
Supports Chart.js v4.
## Introduction
`vue-chartjs` lets you use Chart.js without much hassle inside Vue. It's perfect for people who need simple charts up and running as fast as possible.
It abstracts the basic logic but exposes the Chart.js object to give you maximal flexibility.
:::tip Need an API to fetch data?
Please consider [Cube](https://cube.dev/?ref=eco-vue-chartjs), an open-source API for data apps.
:::
## Installation
You can install `vue-chartjs` over `yarn` or `npm` or `pnpm`. However, you also need to add `chart.js` as a dependency to your project because `Chart.js` is a peerDependency. This way you can have full control over the versioning of `Chart.js`.
```bash
pnpm add vue-chartjs chart.js
# or
yarn add vue-chartjs chart.js
# or
npm i vue-chartjs chart.js
```
## Integration
Every chart type that is available in Chart.js is exported as a named component and can be imported as such. These components are normal Vue components.
The idea behind vue-chartjs is to provide easy-to-use components, with maximal flexibility and extensibility.
## Creating your first Chart
First, you need to import the base chart.
```javascript
import { Bar } from 'vue-chartjs'
```
Check out the official [Chart.js docs](http://www.chartjs.org/docs/latest/#creating-a-chart) to see the object structure you need to provide.
Just create your own component.
**BarChart.vue**
```vue
```
Use it in your vue app:
**App.vue**
```vue
```
## Updating Charts
Since v4 charts have data change watcher and options change watcher by default. Wrapper will update or re-render the chart if new data or new options is passed. Mixins have been removed.
```vue
```
You may get Vue's `Target is readonly` warnings when you are updating your `chartData`.
If your `chartData` is a `read-only` reactive value, you can override this warning by using a clone:
```vue
```
Unless you have a writable computed `chartData`, you won't be able to use the newer `structuredClone`, as you'll likely hit the `Write operation failed: computed value is readonly` error.
You don't need to use a clone if your `chartData` is a [writable computed value](https://vuejs.org/guide/essentials/computed#writable-computed).
## Access to Chart instance
You can get access to chart instance via template refs.
```vue
```
In Vue3 projects:
```javascript
const chartInstance = this.$refs.bar.chart
```
## Accessibility
To make your charts accessible to all users, you should label your charts.
Please refer also to the official [Chart.js Accessibility notes](https://www.chartjs.org/docs/latest/general/accessibility.html).
### `aria-label`
You can directly label a chart by passing an `aria-label` prop.
```vue
```
### `aria-describedby`
You can reference to a describing element such as a table which describes the data by using the `aria-describedby` property.
```vue
| 2022 | 2023 | 2024 |
| --- | --- | --- |
| 987 | 1209 | 825 |
```
### Fallback-Content
In case the Browser is not able to render the `canvas` element, you should consider providing fallback content by using the Slot of each component.
```vue
Chart couldn't be loaded.
```
---
## File: website/src/guide/examples.md
# Examples
## Chart with props
Your goal should be to create reusable chart components. For this purpose, you should utilize Vue.js props to pass in chart options and chart data. This way, the parent component itself does not hold an opinion about fetching data and is only for presentation.
```vue
```
## Chart with local data
You can handle your chart data directly in your parent component.
```vue
```
## Chart with API data
A common pattern is to use an API to retrieve your data. However, there are some things to keep in mind. The most common problem is that you mount your chart component directly and pass in data from an asynchronous API call. The problem with this approach is that Chart.js tries to render your chart and access the chart data synchronously, so your chart mounts before the API data arrives.
To prevent this, a simple `v-if` is the best solution.
Create your chart component with a data prop and options prop, so we can pass in our data and options from a container component.
```vue
```
## Chart with dynamic styles
You can set `responsive: true` and pass in a styles object which gets applied as inline styles to the outer ``. This way, you can change the height and width of the outer container dynamically, which is not the default behaviour of Chart.js. It is best to use computed properties for this.
::: warning
You need to set `position: relative`
:::
```vue
```
## Custom / New Charts
Sometimes you need to extend the default Chart.js charts. There are a lot of [examples](http://www.chartjs.org/docs/latest/developers/charts.html) on how to extend and modify the default charts. Or, you can create your own chart type.
In `vue-chartjs`, you can do this pretty much the same way:
```js
// 1. Import Chart.js so you can use the global Chart object
import { Chart } from 'chart.js'
// 2. Import the `createTypedChart()` method to create the vue component.
import { createTypedChart } from 'vue-chartjs'
// 3. Import needed controller from Chart.js
import { LineController } from 'chart.js'
// 3. Extend one of the default charts
// http://www.chartjs.org/docs/latest/developers/charts.html
class LineWithLineController extends LineController { /* custom magic here */}
// 4. Generate the vue-chartjs component
// The first argument is the chart-id, the second the chart type, third is the custom controller
const CustomLine = createTypedChart('line', LineWithLineController)
// 5. Extend the CustomLine Component just like you do with the default vue-chartjs charts.
export default {
components: { CustomLine }
}
```
## Resources
Here are some resources, such as tutorials, on how to use `vue-chartjs`:
- [Using vue-chartjs with WordPress](https://medium.com/@apertureless/wordpress-vue-and-chart-js-6b61493e289f)
- [Create stunning Charts with Vue and Chart.js](https://hackernoon.com/creating-stunning-charts-with-vue-js-and-chart-js-28af584adc0a)
- [Let’s Build a Web App with Vue, Chart.js and an API Part I](https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-544eb81c4b44)
- [Let’s Build a Web App with Vue, Chart.js and an API Part II](https://hackernoon.com/lets-build-a-web-app-with-vue-chart-js-and-an-api-part-ii-39781b1d5acf)
- [Build a realtime chart with VueJS and Pusher](https://blog.pusher.com/build-realtime-chart-with-vuejs-pusher/)
---
## File: website/src/guide/index.md
# Getting Started
**vue-chartjs** is a wrapper for [Chart.js](https://github.com/chartjs/Chart.js) in Vue. You can easily create reuseable chart components.
Supports Chart.js v4.
## Introduction
`vue-chartjs` lets you use Chart.js without much hassle inside Vue. It's perfect for people who need simple charts up and running as fast as possible.
It abstracts the basic logic but exposes the Chart.js object to give you maximal flexibility.
:::tip Need an API to fetch data?
Please consider [Cube](https://cube.dev/?ref=eco-vue-chartjs), an open-source API for data apps.
:::
## Installation
You can install `vue-chartjs` over `yarn` or `npm` or `pnpm`. However, you also need to add `chart.js` as a dependency to your project because `Chart.js` is a peerDependency. This way you can have full control over the versioning of `Chart.js`.
```bash
pnpm add vue-chartjs chart.js
# or
yarn add vue-chartjs chart.js
# or
npm i vue-chartjs chart.js
```
## Integration
Every chart type that is available in Chart.js is exported as a named component and can be imported as such. These components are normal Vue components.
The idea behind vue-chartjs is to provide easy-to-use components, with maximal flexibility and extensibility.
## Creating your first Chart
First, you need to import the base chart.
```javascript
import { Bar } from 'vue-chartjs'
```
Check out the official [Chart.js docs](http://www.chartjs.org/docs/latest/#creating-a-chart) to see the object structure you need to provide.
Just create your own component.
**BarChart.vue**
```vue
```
Use it in your vue app:
**App.vue**
```vue
```
## Updating Charts
Since v4 charts have data change watcher and options change watcher by default. Wrapper will update or re-render the chart if new data or new options is passed. Mixins have been removed.
```vue
```
You may get Vue's `Target is readonly` warnings when you are updating your `chartData`.
If your `chartData` is a `read-only` reactive value, you can override this warning by using a clone:
```vue
```
Unless you have a writable computed `chartData`, you won't be able to use the newer `structuredClone`, as you'll likely hit the `Write operation failed: computed value is readonly` error.
You don't need to use a clone if your `chartData` is a [writable computed value](https://vuejs.org/guide/essentials/computed#writable-computed).
## Access to Chart instance
You can get access to chart instance via template refs.
```vue
```
In Vue3 projects:
```javascript
const chartInstance = this.$refs.bar.chart
```
## Accessibility
To make your charts accessible to all users, you should label your charts.
Please refer also to the official [Chart.js Accessibility notes](https://www.chartjs.org/docs/latest/general/accessibility.html).
### `aria-label`
You can directly label a chart by passing an `aria-label` prop.
```vue
```
### `aria-describedby`
You can reference to a describing element such as a table which describes the data by using the `aria-describedby` property.
```vue
| 2022 | 2023 | 2024 |
| --- | --- | --- |
| 987 | 1209 | 825 |
```
### Fallback-Content
In case the Browser is not able to render the `canvas` element, you should consider providing fallback content by using the Slot of each component.
```vue
Chart couldn't be loaded.
```