feat: Zoom- und Panning-Funktion für LoopMeasurementChart hinzugefügt

- chartjs-plugin-zoom importiert und in Chart.js registriert
- Zoom per Mausrad und Pinch-Gesten auf Touch-Geräten aktiviert
- Panning (horizontal scrollen) über Dragging hinzugefügt
- Chart-Logik und bestehende Datenverarbeitung beibehalten
This commit is contained in:
ISA
2025-02-21 08:24:30 +01:00
parent 2e4e56869a
commit 73cba877bc
2 changed files with 20 additions and 2 deletions

View File

@@ -3,6 +3,9 @@ import React, { useEffect, useRef } from "react";
import { useSelector } from "react-redux";
import Chart from "chart.js/auto";
import "chartjs-adapter-moment";
import zoomPlugin from "chartjs-plugin-zoom"; // Zoom-Plugin importieren
Chart.register(zoomPlugin); // Plugin registrieren
const LoopMeasurementChart = () => {
const chartRef = useRef<HTMLCanvasElement>(null);
@@ -139,7 +142,7 @@ const LoopMeasurementChart = () => {
autoSkip: false,
maxRotation: 45,
minRotation: 45,
callback: function (value, index, values) {
callback: function (value) {
const date = new Date(value);
return `${date.getDate().toString().padStart(2, "0")}.${(
date.getMonth() + 1
@@ -179,6 +182,21 @@ const LoopMeasurementChart = () => {
},
},
},
zoom: {
pan: {
enabled: true,
mode: "x", // Nur horizontal scrollen
},
zoom: {
wheel: {
enabled: true,
},
pinch: {
enabled: true,
},
mode: "x", // Nur horizontal zoomen
},
},
},
},
});