From 668bcb7a25afdc7babe5e4c60fd841560539c689 Mon Sep 17 00:00:00 2001
From: hamster1963 <1410514192@qq.com>
Date: Wed, 9 Oct 2024 18:00:02 +0800
Subject: [PATCH] fix: chart config
---
.../(main)/ClientComponents/NetworkChart.tsx | 21 +++++++------------
1 file changed, 7 insertions(+), 14 deletions(-)
diff --git a/app/[locale]/(main)/ClientComponents/NetworkChart.tsx b/app/[locale]/(main)/ClientComponents/NetworkChart.tsx
index f31fec1..c77d00b 100644
--- a/app/[locale]/(main)/ClientComponents/NetworkChart.tsx
+++ b/app/[locale]/(main)/ClientComponents/NetworkChart.tsx
@@ -49,22 +49,10 @@ export function NetworkChartClient({ server_id }: { server_id: number }) {
const chartDataKey = Object.keys(data);
- const generateChartConfig = chartDataKey.reduce((config, key, index) => {
- return {
- ...config,
- [key]: {
- label: key,
- color: `hsl(var(--chart-${(index % 5) + 1}))`,
- },
- };
- }, {} as ChartConfig);
-
- const chartConfig = { ...initChartConfig, ...generateChartConfig };
-
return (
);
@@ -87,6 +75,11 @@ export function NetworkChart({
keyof typeof chartConfig
>(chartDataKey[0]);
+ const getColorByIndex = (chart: string) => {
+ const index = chartDataKey.indexOf(chart);
+ return `hsl(var(--chart-${(index % 5) + 1}))`;
+ };
+
return (
@@ -178,7 +171,7 @@ export function NetworkChart({
type="linear"
dot={false}
dataKey="avg_delay"
- stroke={`var(--color-${activeChart})`}
+ stroke={getColorByIndex(activeChart)}
/>