score:4
Billy Jean final note worked for me PIECHART.JS:
import {
Pie,
mixins
} from 'vue-chartjs'
const {
reactiveProp
} = mixins
export default Pie.extend({
mixins: [reactiveProp],
props: ['options'],
watch: {
'options': {
handler(newOption, oldOption) {
this._chart.destroy()
this.renderChart(this.chartData, this.options)
},
deep: true
}
},
mounted() {
this.renderChart(this.chartData, {responsive: true, maintainAspectRadio:
false})
}
})
This is in my view.vue File:
let datasets = []
let colorlist = [ '#4e5fa4', '#5e5fa4', '#6e5fa4',
'#7e5fa4', '#8e5fa4', '#a08be4', '#b08bd4']
datasets.push({
label: this.data_by_city_label,
data: this.data_by_city_data,
fill: false,
backgroundColor: colorlist,
pointBorderWidth: 1,
borderWidth: 1,
pointRadius: 0
})
this.CityDatac = Object.assign({}, this.datasets, {labels: this.data_by_city_label, datasets: datasets})
With this i can send my data to the PIECHART js and generated in my view.vue as so:
<pie-chart-city :chartData="CityDatac" :width="300" :height="250"></pie-chart-city>
Hope that helps anyone in VUE.js -> Vue-chartjs.js
score:0
The code posted by Alexis Poo points me in the right direction.
In my case, I need to modify the watch
object a little bit.
When trying to destroy the chart by calling this._chart.destroy()
when option changed, I received an error message: cannot read property 'destroy' of undefined
.
To fix the issue, I have to do this.$data._chart.destroy()
instead.
Hope it helps.
score:7
One way that works is to add a watcher to the chart,
props: ['chartData', 'options'],
mounted () {
this.renderChart(this.chartData, this.options)
},
watch: {
'chartData' (to, from) {
this.renderChart(this.chartData, this.options)
}
},
See example CodePen
Edit - watcher not working
The difference between your code and the working CodePen is that CodePen mutates the variable passed into the chart, therefore it's watcher reacts.
Your code mutates the .datasets
property of the variable - there's a known issue with this ref: Mixins don't seem to trigger a refresh of the chart #44.
Try replacing
this.datacollection.datasets = [];
this.datacollection.labels = [];
with this (both places)
this.datacollection = { datasets: [], labels: [] };
Source: stackoverflow.com
Related Query
- vue.js vue-chartjs chart not updating when chartData replaced, updated etc
- colors are not updated when updating chart
- ng-charts not updating labels when chart data is updated at same time
- Vue ChartJS is not updating
- Bar Chart Not Stacking When Using ChartJs
- vue-chart.js / vuex: Chart not updating when vuex state changes
- Chartjs does not render chart when set responsive option to true
- Chartjs backgroundColor for line chart does not appear in Vue app
- chartJS pie chart not updating after axios GET
- ChartJS Bar Chart not respecting disabled legend when using cdn
- ChartJs does not render chart when binding canvas id in Angular
- My Chartjs is not updating after setstate full code attached Reactjs Update
- 'require is not defined' error when attempting to use chartjs in javascript code
- updating chartjs pie chart by using .keypress() not working
- When updating Chart.js chart the data is updated but canvas is emptied
- Chartjs Bar Chart showing old data when hovering
- ReferenceError: Chart is not defined - chartjs
- show label in tooltip but not in x axis for chartjs line chart
- Uncaught TypeError: Chart is not a constructor when using Chart.js
- Chartjs not rendering chart and no error thrown
- Pie chart is not getting rendered in ChartJS
- chartjs not following height when parent's height is 200px
- Remove gap when updating ChartJS
- chartjs update() not updating
- Chartjs (Non Vue) Not Rendering Graph Chart inside V-if/V-show
- React setState() not updating state when button clicked
- ChartJS "half donut" chart not displaying properly
- ChartJS - radar chart options not working
- Bubble Chart in Chartjs not working
- Chart.js chart does not display when inside an ngIf.
More Query from same tag
- Chartsjs only showing two data points
- ChartJs 2 How to remove numbers from the doughnut chart on loading
- Line chart disable interpolation
- charts.js show dates 1 year
- ChartJS: how to make a bar chart with a horizontal guideline:
- Chart.JS TypeError: this.scale is undefined
- Meteor and ChartJS dynamically create a chart
- PHP MySQL: count views per month for jQuery charts
- Trying to set scale ticks beginAtZero using Chart.js is unsuccessful, why?
- Connecting points between missing data in chart.js
- Two tone colours in chart.js pie chart
- How to customize Title position with ChartJS
- Give '%' on Bar Chart Datalabel Chartjs
- Django - update dictionary with missing date values, set to 0
- CakePhp3 - Showing values on ChartJs
- pie chart in php with mysql data using chart.js
- how can i remove the grid lines in chartJs
- How to use radial CanvasGradients with Chart.js's doughnut chart?
- Getting "Uncaught TypeError: Cannot read properties of undefined (reading 'map')" when using Chartjs inside react axios method
- ChartJS line chart x = y not rendering astraight line
- How to change the cursor to a pointer when I hover over a bar in a ChartJS bar chart?
- How do I make a pie chart showing number of people in an age group with JSON and ChartJS?
- Dropdown component not having effect in Chromium browser
- How to set y axis to the max dataset value in Chartjs?
- Chartjs backgroundColor for line chart does not appear in Vue app
- Adding Image inside Linechart points in ChartJs
- Chart.js - Line Chart format data to Lacs/Crores
- How to filter dropdown based on the choice of another dropdown in JS?
- Line Charts color all greyed out (ng2-charts)
- 404 Not Found Error when trying to display a chart with Chart.js