Is it possible to load labels dynamically ? Is there a way to draw the chart on demand (once we get all the datas + labels) ?
The datas and labels are loaded together in async but only the data are shown, not the labels.
http://plnkr.co/edit/pK5KBaDrK6fwakc4WWrY?p=preview
Thanks for your help
I needed the same thing but it is not supported yet... meanwhile I have changed the chart.js file located in ng2-charts/charts/chart.js, method ngOnchanges line 23:
BaseChartDirective.prototype.ngOnChanges = function (changes) {
if (this.initFlag) {
// Check if the changes are in the data or datasets
if (changes.hasOwnProperty('labels') || changes.hasOwnProperty('data') || changes.hasOwnProperty('datasets')) { // I've changed this condition
if (changes['data']) {
this.updateChartData(changes['data'].currentValue);
}
else {
this.updateChartData(changes['datasets'].currentValue);
}
// I've added this
if (changes['labels']) {
this.updateChartLabels(changes['labels'].currentValue);
}
this.chart.update();
}
else {
// otherwise rebuild the chart
this.refresh();
}
}
};
Then I declared the "updateChartLabels" method below updateChartData() (it can be anywhere really):
BaseChartDirective.prototype.updateChartLabels = function (newLabelsValues) {
this.chart.data.labels = newLabelsValues;
};
I know you shouldn't be editing the generated chart.js file but this is just a workaround.
Hope this help.
Regards
I had this issue as well as couple others. Your workaround works like a charm for me! thanks didi3r!
@didi3r your solution worked nicely.
@didi3r this worked for me too
@didi3r The workaround is great and resolved my issue as well.
@didi3r Perfect, it resolved the issue for me too
@didi3r Thanks!
Closed by ef5d2f4
Most helpful comment
I needed the same thing but it is not supported yet... meanwhile I have changed the chart.js file located in ng2-charts/charts/chart.js, method ngOnchanges line 23:
Then I declared the "updateChartLabels" method below updateChartData() (it can be anywhere really):
I know you shouldn't be editing the generated chart.js file but this is just a workaround.
Hope this help.
Regards