Skip to content

Commit fc646d8

Browse files
authored
feat(ux): Add a wrapper around generateLegend (#390)
As this is used quite often this wrapper function will improve the UX of generating a legend
1 parent 23ff90d commit fc646d8

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

docs/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,27 @@ There are some basic props defined in the BaseCharts. Because you `extend()` the
7575
| chart-id | id of the canvas |
7676
| css-classes | String with css classes for the surrounding div |
7777
| styles | Object with css styles for the surrounding div container |
78+
| plugins | Array with chartjs plugins |
79+
80+
## Legend Generation
81+
82+
`vue-chartjs` provides a small helper to generate a HTML legend.
83+
84+
```js
85+
import { Line } from 'vue-chartjs'
86+
87+
export default {
88+
extends: Line,
89+
props: ['datasets', 'options']
90+
data: () => ({
91+
htmlLegend: null
92+
})
93+
mounted () {
94+
this.renderChart(this.datasets, this.options)
95+
this.htmlLegend = this.generateLegend()
96+
}
97+
}
98+
```
7899

79100
## Examples
80101

src/BaseCharts.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export function generateChart (chartId, chartType) {
6262
addPlugin (plugin) {
6363
this.$data._plugins.push(plugin)
6464
},
65+
generateLegend () {
66+
if (this.$data._chart) {
67+
return this.$data._chart.generateLegend()
68+
}
69+
},
6570
renderChart (data, options) {
6671
if (this.$data._chart) this.$data._chart.destroy()
6772
this.$data._chart = new Chart(

0 commit comments

Comments
 (0)