From 17957e118b8368acce5e33ddabb0d35988d2f9aa Mon Sep 17 00:00:00 2001 From: "py1u.dev" Date: Sat, 10 Aug 2024 16:56:28 -0700 Subject: [PATCH 1/4] add distribution labels --- .../admin/services/statistics/Chart.jsx | 34 +++++++++++-------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/components/admin/services/statistics/Chart.jsx b/src/components/admin/services/statistics/Chart.jsx index 42c2314fa..16768d8a8 100644 --- a/src/components/admin/services/statistics/Chart.jsx +++ b/src/components/admin/services/statistics/Chart.jsx @@ -3,7 +3,6 @@ import * as React from "react"; import { Label, Pie, PieChart } from "recharts"; import { ROLES } from "@/data/admin/Statistics"; - import { Card, CardContent } from "@/components/ui/card"; import { ChartContainer, @@ -12,22 +11,22 @@ import { } from "@/components/ui/chart"; const Chart = ({ title, data }) => { - const chartData = Object.entries(data).map(([type, value]) => ({ - type: ROLES[type].label, - value: value, - className: ROLES[type].className, - fill: ROLES[type].fill, - })); - - const chartConfig = Object.entries(data).map(([type, value]) => { - const label = ROLES[type].label; + const chartData = Object.entries(data) + .filter(([type]) => ROLES[type]) + .map(([type, value]) => ({ + type: ROLES[type].label, + value: value, + className: ROLES[type].className, + fill: ROLES[type].fill, + })); - return { + const chartConfig = Object.entries(data) + .filter(([type]) => ROLES[type]) + .map(([type, value]) => ({ label: { - label: label, + label: ROLES[type].label, }, - }; - }); + })); const total = React.useMemo(() => { return chartData.reduce((acc, curr) => acc + curr.value, 0); @@ -35,6 +34,13 @@ const Chart = ({ title, data }) => { return ( +
+ {chartData.map((entry, index) => ( +
+ {`${entry.type}: ${entry.value}`} +
+ ))} +
Date: Thu, 12 Sep 2024 17:12:30 -0700 Subject: [PATCH 2/4] update: distribution labels with numbers added to chart --- .../admin/services/statistics/Chart.jsx | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/components/admin/services/statistics/Chart.jsx b/src/components/admin/services/statistics/Chart.jsx index 16768d8a8..0f02fdce5 100644 --- a/src/components/admin/services/statistics/Chart.jsx +++ b/src/components/admin/services/statistics/Chart.jsx @@ -32,19 +32,28 @@ const Chart = ({ title, data }) => { return chartData.reduce((acc, curr) => acc + curr.value, 0); }, [chartData]); + const CustomLabel = ({ x, y, value }) => { + return ( + + {value > 0 ? value : ""} + + ); + }; + return ( -
- {chartData.map((entry, index) => ( -
- {`${entry.type}: ${entry.value}`} -
- ))} -
- + { data={chartData} dataKey="value" nameKey="type" - innerRadius={60} + innerRadius={70} strokeWidth={5} + label={} >