question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rerender when data has changed

See original GitHub issue

Hi! I am using the next branch.

I was wondering how I can make my charts reactive to the data that I enter through the :data property.

So, what should I do to re-render/update a graph?

Edit: And I do know that the data has changed. I can see that through Vue Devtools. So the new data is reactiv to the inside of my chart component. But there graph does not update when the new data arrives.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:39 (12 by maintainers)

github_iconTop GitHub Comments

6reactions
Andkoocommented, Mar 24, 2017

just to let you know - this worked like a charm for me

import { Doughnut } from 'vue-chartjs'

export default Doughnut.extend({
  name: 'DoughnutChart',
  props: ['data', 'options'],
  mounted () {
    this.renderChart(this.data, this.options)
  },
  watch: {
    data: function () {
      this._chart.destroy()
      this.renderChart(this.data, this.options)
    }
  }
})
3reactions
andrewmartincommented, Dec 22, 2017

After a few hours of frustration, I finally figured this out. I am creating a chart that has a variable number of labels and fields.

I abandoned the seemingly buggy mixin , and just added my own listeners.

Just in case anyone else has any confusion, if you’re setting up following the examples, I ended up doing this:


Vue.component 'bar-graph',
  extends: VueChartJs.Bar
  props: [
    'chartInfo',
    'chartLabels',
  ]
  watch:
    chartInfo:
      handler: (to, from) ->
        this.$data._chart.destroy()
        this.renderChart(this.chartInfo, this.options)
    chartLabels:
      handler: (to, from) ->
        this.$data._chart.destroy()
        this.renderChart(this.chartInfo, this.options)
  mounted: ->
    chartOptions =
      responsive: true
      maintainAspectRatio: true
      tooltips:
        enabled: false
      scales:
        xAxes: [
          ticks:
            autoSkip: false,
            maxRotation: 0,
            minRotation: 90
        ]

    @renderChart this.chartInfo,
      chartOptions

You’ll note that this.$data._chart is the reference found when you are extending the chart.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I re-render a component when an object is changed in ...
Add a data attribute to each input. We can use that to update the input state when it changes. Remove the native DOM...
Read more >
React re-renders guide: everything, all at once - Developer way
Necessary re-render - re-render of a component that is the source of the changes, or a component that directly uses the new information....
Read more >
When does React re-render components? - Felix Gerschau
React re-render explained. React is known for providing a fast user experience by only updating the parts of the UI that have changed....
Read more >
Re-rendering Components in ReactJS - GeeksforGeeks
A second or subsequent render to update the state is called as re-rendering. React components automatically re-render whenever there is a change ......
Read more >
How to force a view to re-render when data has changed ...
I'm playing with the jokes app and when I have the app running in two different browsers, the one browser doesn't know of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found