Mixins don't seem to trigger a refresh of the chart
See original GitHub issueExpected Behavior
Adding a label and value to the dataset should add the item to the chart
Actual Behavior
Adding a label and value to the data doesn’t change the chart. The chart only gets redrawn when I resize the browser
Line chart:
import { Line, mixins } from 'vue-chartjs'
export default Line.extend({
props: ["options", "chartData"],
mixins: [mixins.reactiveProp],
mounted () {
this.renderChart(this.chartData,this.options);
this._chart.update();
},
})
Component:
<template>
<div class="charts">
<div class="col-md-12">
<line-chart :chart-data="chartData" :options="chartOptions"></line-chart>
<md-button @click.native="addData">add data</md-button>
</div>
</div>
</template>
<style scoped>
</style>
<script>
import lineChart from './chartOverviewTimeline.js';
export default {
name: 'chartDashboard',
components : {
lineChart
},
data: function () {
return {
chartData : {},
chartOptions : {mainAspectRatio : false}
}
},
mounted(){
this.prepareChartData();
},
methods: {
addData: function(){
for(let i = 0 ; i < 1; i ++){
this.chartData.labels.push(100 + i);
this.chartData.datasets[0].data.push(Math.random() * 100);
}
},
prepareChartData(){
this.chartOptions = {
maintainAspectRatio:false,
scaleShowHorizontalLines : true,
scales: {
xAxes: [{
stacked: false
}],
yAxes: [{
stacked: false,
gridLines:{
display: true
}
}]
}
};
this.chartData = {
labels:[],
datasets:[
{
label: 'Sensor 1',
backgroundColor: '#734375',
data: [],
fill: false,
lineTension: 0
}]
};
for(let i = 0 ; i < 5; i++){
this.chartData.labels.push(i);
this.chartData.datasets[0].data.push(Math.random() * 100);
}
}
}
}
</script>
I would expect that the addData function triggers a change in the prop and therefor a redraw in the chart.
Vue chartjs version 2.3.7
Issue Analytics
- State:
- Created 7 years ago
- Comments:19 (7 by maintainers)
Top Results From Across the Web
Vue Chart.js - Chart is not updating when data is changing
js to draw some charts. Each time I call the function generateChart() , the chart is not updated automatically. When I check the...
Read more >Change: Don't use Vue Mixins (#32) · Issues - GitLab
Most places that use mixins don't use all the props they provide. Mixins become a dumping ground for 'shared code', which results in...
Read more >Using Mixins in Vue.js - CSS-Tricks
A mixin allows you to encapsulate one piece of functionality so that you can use it in different components throughout the application. If ......
Read more >Mixins — OctoPrint master documentation
Plugin mixins are the heart of OctoPrint's plugin system. They are special base classes which are to be subclassed and extended to add...
Read more >Using mixins with class-based views - Django documentation
Every built in view which needs context data, such as for rendering a template (including TemplateResponseMixin above), should call get_context_data() passing ...
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
Here’s my method, which IMO is the easiest solution, for parent to child component data.
First, assign your chart component a ref on the parent component. i.e.
<radar-chart ref="radarChart" :data="radarChartData"></radar-chart>
In your chart component, I remove all reactive mixing stuff. Not needed. Then I created the following methods:
Finally, in your parent, create a method along of the lines of this to update your data:
I did like below and it is working reactively that way 😃