Dezimalstellen in den Tooltips von Chart.js anzeigen

This commit is contained in:
ISA
2025-02-21 06:44:22 +01:00
parent 53b04a72b3
commit e9bd0856c3
2 changed files with 34 additions and 10 deletions

View File

@@ -64,7 +64,7 @@ const LoopMeasurementChart = () => {
processedData.some((entry) => entry.m !== undefined)
) {
datasets.push({
label: "Messwert Mittelwert (m)",
label: "Messwert Mittelwert",
data: processedData.map((entry) => ({
x: entry.timestampMs,
y: entry.m ?? NaN, // Falls `m` nicht existiert, wird `NaN` gesetzt
@@ -81,7 +81,7 @@ const LoopMeasurementChart = () => {
processedData.some((entry) => entry.g !== undefined)
) {
datasets.push({
label: "Messwert Durchschnitt (g)",
label: "Messwert Durchschnitt",
data: processedData.map((entry) => ({
x: entry.timestampMs,
y: entry.g ?? NaN, // Falls `g` nicht existiert, wird `NaN` gesetzt
@@ -123,12 +123,12 @@ const LoopMeasurementChart = () => {
x: {
type: "time",
time: {
unit: "minute", // Stelle sicher, dass jede Minute angezeigt wird
tooltipFormat: "dd.MM.yyyy HH:mm", // Tooltip zeigt Datum & Uhrzeit
unit: "minute",
tooltipFormat: "dd.MM.yyyy HH:mm",
displayFormats: {
minute: "dd.MM.yyyy HH:mm", // Zeigt bei jedem Tick Datum & Uhrzeit
hour: "dd.MM.yyyy HH:mm", // Falls stündliche Werte vorliegen
day: "dd.MM.yyyy", // Falls tägliche Werte angezeigt werden
minute: "dd.MM.yyyy HH:mm",
hour: "dd.MM.yyyy HH:mm",
day: "dd.MM.yyyy",
},
},
title: {
@@ -136,8 +136,8 @@ const LoopMeasurementChart = () => {
text: "Zeit (Datum & Uhrzeit)",
},
ticks: {
autoSkip: false, // Keine Ticks auslassen
maxRotation: 45, // Falls nötig, dreht die Labels für bessere Lesbarkeit
autoSkip: false,
maxRotation: 45,
minRotation: 45,
callback: function (value, index, values) {
const date = new Date(value);
@@ -155,6 +155,30 @@ const LoopMeasurementChart = () => {
},
},
},
y: {
ticks: {
callback: function (value) {
return value.toFixed(2); // Y-Achse Werte mit zwei Dezimalstellen anzeigen
},
},
},
},
plugins: {
tooltip: {
callbacks: {
label: function (tooltipItem) {
let label = tooltipItem.dataset.label || "";
if (label) {
label += ": ";
}
if (tooltipItem.raw !== null) {
label +=
parseFloat(tooltipItem.raw.y).toFixed(2) + " kOhm"; // Dezimalstellen im Tooltip
}
return label;
},
},
},
},
},
});

View File

@@ -6,5 +6,5 @@
2: Patch oder Hotfix (Bugfixes oder kleine Änderungen).
*/
const webVersion = "1.6.72";
const webVersion = "1.6.73";
export default webVersion;