Fix: Preserve chart state during zoom, pan, and date changes
- Added React.useMemo to memoize chartData and chartOptions to prevent unnecessary re-renders. - Ensured chart zoom and pan states are maintained during interactions. - Improved performance and user experience by avoiding chart
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import { useDispatch, useSelector } from "react-redux";
|
||||
import { RootState, AppDispatch } from "@/redux/store";
|
||||
import { Line, ChartJSOrUndefined } from "react-chartjs-2";
|
||||
import { Line } from "react-chartjs-2";
|
||||
import {
|
||||
Chart as ChartJS,
|
||||
LineElement,
|
||||
@@ -42,8 +42,18 @@ ChartJS.register(
|
||||
);
|
||||
|
||||
export default function AnalogInputsChart() {
|
||||
useEffect(() => {
|
||||
if (typeof window !== "undefined") {
|
||||
import("chartjs-plugin-zoom").then((zoom) => {
|
||||
if (!ChartJS.registry.plugins.get("zoom")) {
|
||||
ChartJS.register(zoom.default);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
const dispatch = useDispatch<AppDispatch>();
|
||||
const chartRef = useRef<ChartJSOrUndefined<"line"> | null>(null);
|
||||
const chartRef = useRef<any>(null);
|
||||
|
||||
// Redux Werte für Chart-Daten
|
||||
const { zeitraum, vonDatum, bisDatum, data, autoLoad, selectedId } =
|
||||
|
||||
Reference in New Issue
Block a user