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

Properly destroy chartjs objects #3

Merged
merged 3 commits into from Aug 19, 2016
Merged

Properly destroy chartjs objects #3

merged 3 commits into from Aug 19, 2016

Conversation

LinusBorg
Copy link
Contributor

Currently, the chartjs object is not properly destroyed (cleaning up event listeners etc) when the component is destroyed.

This pull request saves the chart instance on the component and adds a destroy() hook to the component that calls the chart instance's .destroy() method to ensure proper cleanup.

methods: {
    render (data, options = this.options) {
      this._chart = new Chart( // save instance on a property of the vm
        this.$els.canvas.getContext('2d'), {
          type: 'bar',
          data: data,
          options: options
        }
      )
      this._chart.generateLegend()
    }
  },
  beforeDestroy () {
    this._chart.destroy() //destroy chart when component is destroyed
  }

@apertureless apertureless merged commit ad7cabe into apertureless:develop Aug 19, 2016
@apertureless apertureless added this to the v1.0.3 milestone Aug 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants