Holiday Notice: Support will be provided on a limited scale from December 24th, 2024, to January 2nd, 2025. Happy holidays and a wonderful New Year!


Topic: Angular line graph updating data

wibar pro asked 6 years ago


HiI'm trying to make it possible to change the data being displayed, but when I copy new data to the datasets variable it seems to remeber the size of the previous set e.i I start by displaying two graphs then i want to show just one.I can see that in the chart.directive this.chart.data.datasets has a length of 2 while newDataVales has a length of 1Chart.directive.ts:
Start your code here private updateChartData(newDataValues: number[] | any[]): void { if (Array.isArray(newDataValues[0].data)) { this.chart.data.datasets.forEach((dataset: any, i: number) => { dataset.data = newDataValues[i].data;if (newDataValues[i].label) { dataset.label = newDataValues[i].label; } }); } else { this.chart.data.datasets[0].data = newDataValues; } }
What am i doing wrong?

Damian Gemza staff answered 6 years ago


Hello majnor, I'm not sure if understood you in right way: If you want to remove some data set after something, you could always set this concrete data set as empty object: Just add those lines to your existing MDB Chart project and see difference:
ngAfterViewInit() {

setTimeout(() => {

this.chartDatasets= [

{ data: [12, 12, 12, 12, 126, 12, 12], label: 'Second' },

{ data: [], label: '' },

];

}, 3000);

}
Best Regards, Damian

wibar pro commented 6 years ago

Thx for the quick answer. From your answer it sounds like you cannot change the number of dataset, which is what i was trying to do, is this understood correctly? But it is possible to replace on of the datasets with a empty one, right? Regards, Maja

Damian Gemza staff commented 6 years ago

Yes, exactly. If you need to remove some datasets, you have to set it as empty one. Best Regards, Damian


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: Yes
  • Provided link: No
Tags