Chart does not update on this.$data._chart.update()
See original GitHub issueExpected Behavior
Chart should update on this.$data._chart.update()
Actual Behavior
Chart does not update.
Am I missing something? dataPoints
is reactive and receives new values which the watcher successfully spots and trigger this.$data._chart.update()
but nothing happens.
<script lang="ts">
import { Component, Mixins, Prop, Watch } from 'vue-property-decorator'
import { Line } from 'vue-chartjs'
import { ChartOptions } from 'chart.js'
@Component({
components: {}
})
export default class ChartLineNonReactive extends Mixins(Line) {
@Prop({ default: () => [] }) dataPoints!: number[]
@Prop() scaleMin!: number
@Prop() scaleMax!: number
@Prop() reverse?: boolean
$refs!: {
canvas: any
}
gradient: CanvasGradient | null = null
get chartData() {
return {
labels: this.dataPoints.map((d, i) => i.toString()),
datasets: [
{
data: this.dataPoints,
backgroundColor: 'transparent',
borderWidth: 4,
borderColor: this.gradient!,
pointBorderWidth: 2
}
]
}
}
get options(): ChartOptions {
return {
responsive: true,
maintainAspectRatio: false,
layout: { padding: 10 },
legend: { display: false },
scales: {
display: false,
xAxes: [{
display: false,
ticks: {}
}],
yAxes:
[{
ticks: {
min: this.scaleMin,
max: this.scaleMax
},
display: false
}]
}
}
}
mounted() {
this.gradient = this.$refs.canvas.getContext('2d').createLinearGradient(0, 0, 0, this.$refs.canvas.height)
const positive = '#4CD287'
const warning = '#FFBE60'
const negative = '#FF8062'
this.gradient!.addColorStop(this.reverse ? 0 : 1, negative)
this.gradient!.addColorStop(0.5, warning)
this.gradient!.addColorStop(this.reverse ? 1 : 0, positive)
this.renderChart(
this.chartData,
this.options
)
}
@Watch('chartData')
changed(newVal: any, oldVal: any) {
this.$data._chart.update()
}
}
</script>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Can't update chart - Stack Overflow
Therefore, try to change your updateConfigByMutating from... function updateConfigByMutating() { chart.options.plugins.title.text = 'new title'; ...
Read more >Updating Charts - Chart.js
It's pretty common to want to update charts after they've been created. When the chart data or options are changed, Chart.js will animate...
Read more >Charts not updating when data is updated
Charts not updating when data is updated. Hello,. I have built an Excel dashboard template that has 46 charts referencing cells in a...
Read more >Overview – Updating chart options - CanvasJS.com
Tutorial on Updating Chart Data and Options Dynamically | CanvasJS JavaScript Charts. ... though such an update rate will not be required in...
Read more >Updating charts | AnyLogic Help
Automatic update · Select the chart in the graphical editor by clicking it. · Go to the Properties. · In the Data update...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is indeed weird.
Can you check if instead of calling
update()
callingthis.renderChart(this.chartData,this.options)
solves this?How are you getting your data? Are you using an api?
I have encountered the same issue. with
this.chartOptions
and my own watcher (as advised by the docs) triggeringthis.$data._chart.update()
it does not update the chart.My temporary solution was to disable animation and just re-render the chart on every update. Not great, or performant but it is working.
Any idea when this will be fixed?