fix(graph): adding satuan in sumbu Y

This commit is contained in:
Desy Ayurianti 2024-11-29 14:09:05 +07:00
parent ae43ca880c
commit d6e7c7696c

View File

@ -312,7 +312,6 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang
chart.data.datasets.forEach((dataset: any) => { chart.data.datasets.forEach((dataset: any) => {
dataset.hidden = dataset.label !== this.parameterDisplayNames[parameter]; dataset.hidden = dataset.label !== this.parameterDisplayNames[parameter];
}); });
chart.update(); chart.update();
} }
} }
@ -364,8 +363,6 @@ export class GraphComponent implements OnInit, AfterViewInit, OnDestroy, OnChang
.filter(parameter => { .filter(parameter => {
if (selectedOption === 'npk') { if (selectedOption === 'npk') {
return ['soilphosphorus', 'soilnitrogen', 'soilpotassium'].includes(parameter); return ['soilphosphorus', 'soilnitrogen', 'soilpotassium'].includes(parameter);
} else if (selectedOption === 'others') {
return !['soilphosphorus', 'soilnitrogen', 'soilpotassium'].includes(parameter);
} else if (selectedOption === 'temperature') { } else if (selectedOption === 'temperature') {
return ['soiltemperature'].includes(parameter); return ['soiltemperature'].includes(parameter);
} else if (selectedOption === 'humidity') { } 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']; const days = ['Sun', 'Mon', 'Tues', 'Wed', 'Thrus', 'Fri', 'Sat'];
return days[date.getDay()]; return days[date.getDay()];
} }
};
}