I am using Chart.js with my Ionic 3 Angular app. All works fine, except I am unable to refresh the data for the bar that actually changed.
Here is the code:
ionViewDidLoad(){
this.barChart = new Chart(this.barCanvas.nativeElement,
{
type: 'bar',
data: {
labels: ["Safeway", "CVS", "Walgreens", "Bon Appetit"],
datasets: [{
label: "Pepsi",
backgroundColor: "#002F6F",
data: this.pepsiData
}, {
label: "Coke",
backgroundColor: "#F50000",
data: this.cockData
}, {
label: "V8",
backgroundColor: "orange",
data: [83,19,32,34]
}]
},
options: {
title: {
display: true,
text: 'Brands'
}
}
});
}
A separate button update the data for pepsiData array as:
this.pepsiData[3] = 80;
But this does not refresh the particular bar. The ugly solution I have now is to redraw the entire chart, which looks like a bad solution.
this.barChart.update()