-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
adfb08b
commit 3b7ebf6
Showing
6 changed files
with
74 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"use client"; | ||
|
||
import * as React from "react"; | ||
import { Pie, PieChart } from "recharts"; | ||
import { | ||
type ChartConfig, | ||
ChartContainer, | ||
ChartLegend, | ||
ChartLegendContent, | ||
ChartTooltip, | ||
ChartTooltipContent, | ||
} from "@/components/ui/chart"; | ||
|
||
interface Props { | ||
data: Record<string, number>; | ||
type: string; | ||
} | ||
|
||
interface ChartConfigItem { | ||
label: string; | ||
} | ||
|
||
export const DistributionPieChart = ({ data, type }: Props) => { | ||
const chartData = Object.entries(data) | ||
.filter(([_, value]) => value) | ||
.map(([key, value], index) => ({ | ||
label: key, | ||
value, | ||
fill: `hsl(var(--chart-${index + 1}))`, | ||
})); | ||
|
||
const chartConfig = { | ||
type: { | ||
label: type, | ||
}, | ||
...Object.keys(data).reduce<Record<string, ChartConfigItem>>( | ||
(acc, key, index) => { | ||
acc[key] = { label: key }; | ||
|
||
return acc; | ||
}, | ||
{}, | ||
), | ||
} satisfies ChartConfig; | ||
|
||
return ( | ||
<ChartContainer config={chartConfig} className="h-[300px] w-full"> | ||
<PieChart> | ||
<ChartTooltip | ||
content={<ChartTooltipContent labelKey="type" indicator="line" />} | ||
/> | ||
<Pie | ||
data={chartData} | ||
dataKey="value" | ||
nameKey="label" | ||
innerRadius={60} | ||
label | ||
/> | ||
<ChartLegend content={<ChartLegendContent />} className="flex-wrap" /> | ||
</PieChart> | ||
</ChartContainer> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters