I am struggling with transforming the expense data into a positive number in my bar chart. The data consists of both income and expenses, and I want to display them as positive numbers for easier comparison. I attempted using Math.abs(this.barData[1]) in ngOnInit, but encountered the error: Argument of type '(number | ScatterDataPoint | BubbleDataPoint)[]' is not assignable to parameter of type 'number'.
Any help would be greatly appreciated!
barLabel = ["13.03.2022"];
barData = [[645.54], [- 114.24]];
@Input() barData!: (number | ScatterDataPoint | BubbleDataPoint)[][];
@Input() barLabel!: string[];
public barChartType: ChartType = "bar";
public barChartData: ChartConfiguration["data"];
defaultBarChartData: Partial<ChartConfiguration['data']>;
ngOnInit(): void {
this.defaultBarChartData = {
labels: this.barLabel,
datasets: [
{
data: this.barData[0],
label: "Income",
backgroundColor: "#3ABD32",
},
{
data: this.barData[1],
label: "Expense",
backgroundColor: "#E02A45",
},
],
};
if (
this.barData !== undefined &&
this.barLabels !== undefined &&
Array.isArray(this.barData) &&
this.barData.length > 0 &&
Array.isArray(this.barLabels) &&
this.barLabels.length > 0
)
{
this.barChartData = {
...this.defaultBarChartData,
...{ labels: [" "] },
} as ChartConfiguration['data'];
this.barChartData.datasets[0].data = this.barData[0];
} else {
throw new Error('Charts must have their data and labels inputs defined.');
}
}
public barChartOptions: ChartConfiguration["options"] = {...}