From d6e7c7696c389515e947bb9681cc926cee97c3c0 Mon Sep 17 00:00:00 2001 From: Desy Ayurianti Date: Fri, 29 Nov 2024 14:09:05 +0700 Subject: [PATCH] fix(graph): adding satuan in sumbu Y --- .../dashboard/page/graph/graph.component.ts | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.ts b/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.ts index b83afba..2b03688 100644 --- a/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.ts +++ b/agrilink_vocpro/src/app/pages/dashboard/page/graph/graph.component.ts @@ -312,7 +312,6 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang chart.data.datasets.forEach((dataset: any) => { dataset.hidden = dataset.label !== this.parameterDisplayNames[parameter]; }); - chart.update(); } } @@ -364,8 +363,6 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang .filter(parameter => { if (selectedOption === 'npk') { return ['soilphosphorus', 'soilnitrogen', 'soilpotassium'].includes(parameter); - } else if (selectedOption === 'others') { - return !['soilphosphorus', 'soilnitrogen', 'soilpotassium'].includes(parameter); } else if (selectedOption === 'temperature') { return ['soiltemperature'].includes(parameter); } else if (selectedOption === 'humidity') { @@ -454,7 +451,22 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang } } }, - y: { grid: { display: false }, beginAtZero: true } + y: { + grid: { display: false }, + beginAtZero: true, + ticks: { + callback: (value: number | string) => { + if (this.activeButton === 'vicitemperature') { + return `${value} °C`; + } else if (this.activeButton === 'vicihumidity') { + return `${value} %`; + } else if (this.activeButton === 'viciluminosity') { + return `${value} lux`; + } + return value; + } + }, + } } } }); @@ -497,7 +509,25 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang } } }, - y: { grid: { display: false }, beginAtZero: true } + y: { + grid: { display: false }, + beginAtZero: true, + ticks:{ + callback: (value: number | string) => { + if(selectedOption === 'npk'){ + return `${value} mg/L`; + } else if(selectedOption === 'temperature'){ + return `${value} °C`; + } else if(selectedOption === 'humidity'){ + return `${value} %`; + } else if(selectedOption === 'conductivity'){ + return `${value} μS/cm`; + } else if(selectedOption === 'ph'){ + return `${value} pH`; + } return value; + } + }, + }, } } }); @@ -552,5 +582,5 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang const days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thrus', 'Fri', 'Sat']; return days[date.getDay()]; } - -} +}; +