Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy multiple annotations #910

Merged
merged 3 commits into from Sep 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 6 additions & 5 deletions legacy/src/Charts.js
Expand Up @@ -26,7 +26,7 @@ import {
const ANNOTATION_PLUGIN_KEY = 'annotation'

export function generateChart(chartId, chartType, chartController) {
let _chartRef = null
let _chartRef = {}

return {
props: {
Expand Down Expand Up @@ -69,7 +69,8 @@ export function generateChart(chartId, chartType, chartController) {
},
data() {
return {
_chart: null
_chart: null,
_id: Math.random().toString(36).substring(2),
}
},
computed: {
Expand All @@ -84,7 +85,7 @@ export function generateChart(chartId, chartType, chartController) {
ChartJS.register(chartController)
},
mounted() {
_chartRef = { current: null }
_chartRef[this.$data._id] = null

if ('datasets' in this.chartData && this.chartData.datasets.length > 0) {
chartCreate(this.renderChart, this.chartData, this.chartOptions)
Expand Down Expand Up @@ -185,11 +186,11 @@ export function generateChart(chartId, chartType, chartController) {
chartUpdate(currentChart)
},
getCurrentChart() {
return this.hasAnnotationPlugin ? _chartRef.current : this.$data._chart
return this.hasAnnotationPlugin ? _chartRef[this.$data._id] : this.$data._chart
},
setCurrentChart(chart) {
this.hasAnnotationPlugin
? (_chartRef.current = chart)
? (_chartRef[this.$data._id] = chart)
: (this.$data._chart = chart)
}
},
Expand Down
4 changes: 0 additions & 4 deletions website/src/guide/index.md
Expand Up @@ -321,10 +321,6 @@ 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

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.

## Examples

### Chart with props
Expand Down