From 5024d6c44a4f2585d0c0510da0c57a8cebd64f99 Mon Sep 17 00:00:00 2001 From: Rhys Lewis Date: Tue, 13 Aug 2024 08:25:19 +0100 Subject: [PATCH] Refactored graphLabel functionality --- src/components/common/chart/chart.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/components/common/chart/chart.ts b/src/components/common/chart/chart.ts index 87e1acbcc..d40619e65 100644 --- a/src/components/common/chart/chart.ts +++ b/src/components/common/chart/chart.ts @@ -412,9 +412,8 @@ export class ChartComponent implements OnInit, OnChanges { * @param {number[]} dataValues - An array of data values to be used for creating the graph labels. */ createGraphLabels(dataValues: number[]): void { - let tempGraphLabels: PointAnnotations[] = []; - for (let i = 0; i < dataValues.length; i++) { - tempGraphLabels.push({ + this.graphLabels = dataValues.map((dataValue, i) => { + return { //Position the annotation at the corresponding label on the x-axis x: this.labels[i], y: 0, @@ -425,7 +424,7 @@ export class ChartComponent implements OnInit, OnChanges { //create the label for the annotation label: { offsetY: -5, - text: dataValues[i].toString(), + text: dataValue.toString(), borderColor: '#FFFFFF', style: { padding: {top: -1, left: 3.5, right: 3.5}, @@ -436,8 +435,8 @@ export class ChartComponent implements OnInit, OnChanges { color: '#FFFFFF', }, }, - }); - } - this.graphLabels = tempGraphLabels; + } + }) + } }