Skip to content

Commit 3247a61

Browse files
committed
feat(docs): Update docs with custom chart example
1 parent 50e5644 commit 3247a61

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

docs/README.md

+32-32
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ export default {
9999
After you add your component you can use it:
100100

101101
```html
102-
<line-chart :data="{your data object}" :options="{your options}"></line-chart>
102+
<line-chart :data="chartData" :options="chartOptions"></line-chart>
103103
```
104104

105105
If you want to overwrite width and height:
106106

107107
```html
108108
<line-chart
109-
:data="{your data object}"
109+
:data="chartData"
110110
:options="{responsive: false, maintainAspectRatio: false}"
111111
:width="400"
112112
:height="200"
@@ -279,6 +279,36 @@ mounted () {
279279
})
280280
}
281281
```
282+
## Custom / New Charts
283+
284+
Sometimes you need to extend the default Chart.js charts. There are a lot of examples how to extend and modify the default charts. Or you want to create a own chart type.
285+
286+
In `vue-chartjs` you can do this pretty much the same way.
287+
288+
```js
289+
// 1. Import Chart.js so you can use the global Chart object
290+
import Chart from 'chart.js'
291+
// 2. Import the `generateChart()` method to create the vue component.
292+
import { generateChart } from 'vue-chartjs'
293+
294+
// 3. Extend on of the default charts
295+
// http://www.chartjs.org/docs/latest/developers/charts.html
296+
Chart.defaults.LineWithLine = Chart.defaults.line;
297+
Chart.controllers.LineWithLine = Chart.controllers.line.extend({ /* custom magic here */})
298+
299+
// 4. Generate the vue-chartjs component
300+
// First argument is the chart-id, second the chart type.
301+
const CustomLine = generateChart('custom-line', 'LineWithLine')
302+
303+
// 5. Extend the CustomLine Component just like you do with the default vue-chartjs charts.
304+
305+
export default {
306+
extends: CustomLine,
307+
mounted () {
308+
// ....
309+
}
310+
}
311+
```
282312

283313
## Available Charts
284314

@@ -318,36 +348,6 @@ This chart has a different data structure then the others. Right now the reactiv
318348

319349
![Scatter](assets/scatter.png)
320350

321-
322-
## Explanation of Different Builds
323-
There are three different entry points. It depends on your build setup. The dependencies are bundled or required as a peerDependency.
324-
325-
- Browser
326-
- Browserify / Webpack 1
327-
- Webpack 2
328-
329-
330-
| Build | Chart.js | Vue.js |
331-
|---|---|---|
332-
| vue-chartjs.full.js | Bundled | Bundled |
333-
| vue-chartjs.full.min.js | Bundled | Bundled |
334-
| vue-chartjs.js | peerDependency | peerDependency |
335-
| vue-chartjs.min.js | peerDependency | peerDependency |
336-
| es/index* | peerDependency | peerDependency |
337-
338-
### Browser
339-
You can use `vue-chartjs` directly in the browser without any build setup, like in this [codepen](https://codepen.io/apertureless/pen/vxWbqB?editors=1010). In this case, please use the `vue-chartjs.full.min.js` which is the minified version. It has Vue.js and Chart.js bundled into it and is bundled to a UMD module, so you only need that one file.
340-
341-
342-
### Browserify / Webpack 1
343-
344-
If you're using Gulp, Browserify or Webpack 1 the entry is `vue-chartjs.js` which is __transpiled__ and __bundled__ UMD Module.
345-
346-
However Vue.js and Chart.js are `peerDependencies` so you have to install them separately. In most projects you will have Vue.js already installed anyways. This way, you can have different versions of Vue.js and Chart.js then in this package.
347-
348-
### Webpack 2
349-
If you're using Webpack 2 it will automatically use the `jsnext:main` / `module` entry point, which is `es/index.js`. It is a __transpiled__ es version of the source and is not __bundled__ to a module. This way your tree shaking will work. Like in the bundled version, Vue.js and Chart.js are `peerDependencies` and need to be installed.
350-
351351
## Resources
352352

353353
You can find here some resources like tutorials on how to use `vue-chartjs`

0 commit comments

Comments
 (0)