Im using the charts wrapper for chart.js provided by http://www.primefaces.org/primeng/#/chart
This works fine when i give the data attribute a static array of numbers however when i use a function that returns a value (also array of numbers) its not rendering This is because their implementation doesn't listen to changes automatically in fact in their docs they state that refresh should be manual
update(chart: UIChart) {
this.data = //reload
chart.refresh();
}
my question is how to reference the chart: UIChart from the controller so i can call its refresh method when i need to here is my current implementation (not drawing since data is empty)
constructor(private stationService : StationComplianceService) { }
ngOnInit() {
this.getStationTypes();
}
// ngAfterViewInit(chart: UIChart) {
// this.drawGraph(this.processStationType(this.graphData)); not working
// }
update(chart: UIChart) {
chart.refresh();
}
drawGraph(graphData){
this.data = {
labels: ['Up Devices', 'Down Devices'],
datasets: [
{
data: graphData,
backgroundColor: [
"#4dd0e1",
"#4fc3f7"
],
hoverBackgroundColor: [
"#00acc1",
"#039be5"
]
}]
};
}
getStationTypes(){
this.stationService.subscribeToComplianceService()
.subscribe(
graphData => {
this.graphData = graphData;
this.drawGraph(this.processStationType(graphData)); etc etc
UPDATE I managed to get a reference of the chart by using
@ViewChild
('upDownChart') chart: UIChart;
So i was hoping that by calling this.chart.refresh() at the end of the drawGraph function it would work but its not strangely i have refactored the update (invoked by a click on the ui)
update() {
this.chart.refresh();
}
and it is working