Skip to content

Commit

Permalink
Merge branch 'develop' into feature/events
Browse files Browse the repository at this point in the history
* develop:
  feat(ux): Add a wrapper around generateLegend (#390)
  • Loading branch information
apertureless committed Aug 4, 2018
2 parents 896cfd6 + fc646d8 commit ffbb63b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,27 @@ There are some basic props defined in the BaseCharts. Because you `extend()` the
| chart-id | id of the canvas |
| css-classes | String with css classes for the surrounding div |
| styles | Object with css styles for the surrounding div container |
| plugins | Array with chartjs plugins |

## Legend Generation

`vue-chartjs` provides a small helper to generate a HTML legend.

```js
import { Line } from 'vue-chartjs'

export default {
extends: Line,
props: ['datasets', 'options']
data: () => ({
htmlLegend: null
})
mounted () {
this.renderChart(this.datasets, this.options)
this.htmlLegend = this.generateLegend()
}
}
```

## Examples

Expand Down
5 changes: 5 additions & 0 deletions src/BaseCharts.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export function generateChart (chartId, chartType) {
addPlugin (plugin) {
this.$data._plugins.push(plugin)
},
generateLegend () {
if (this.$data._chart) {
return this.$data._chart.generateLegend()
}
},
renderChart (data, options) {
if (this.$data._chart) this.$data._chart.destroy()
this.$data._chart = new Chart(
Expand Down

0 comments on commit ffbb63b

Please sign in to comment.