export const title = "Pie chart components" export const description = "Powerful and customizable React pie chart components built for modern applications and websites. These pie charts are built using Recharts and styled with Tailwind CSS." export const links = { github: "https://github.com/untitleduico/react/tree/main/components/application/charts", recharts: "https://recharts.org/en-US/api/PieChart", } import * as PieCharts from "@/components/application/charts/pie-charts.story.tsx"; ## Installation You can add this charts component using our CLI or manually: ```bash npx untitledui@latest add charts-base ``` As our pie charts component is built with [Recharts](https://recharts.org/en-US/), you'll need to install the dependencies: ```bash npm install recharts ``` Copy the files below into your project: Great! Now you can start using the pie charts components in your project by just copy/pasting our examples below. ## Pie chart examples Below are examples and variations of this pie chart component: ### Pie chart xxl {{ tocOnly:true }} ### Pie chart xs {{ tocOnly:true }} ### Pie chart sm {{ tocOnly:true }} ### Pie chart md {{ tocOnly:true }} ### Pie chart lg {{ tocOnly:true }} ## API reference ` reads `dataKey=\"value\"` for the slice size and `nameKey=\"name\"` for the label shown in the legend and tooltip. The optional `className` sets the slice color, as described below.", }, { question: "How do I color the slices?", answer: "Set a text color class on each data entry via `className`, such as `text-utility-brand-600` or `text-utility-neutral-200`, because the `` is rendered with `fill=\"currentColor\"`. The same `className` is picked up by `ChartLegendContent`, which paints the legend swatch with `bg-current`, so the legend and the chart stay in sync automatically.", }, { question: "What sizes are available for pie charts?", answer: "The pie charts are copy-paste examples rather than exported components: what you install is `charts-base.tsx`, and the five sizes on this page live in `pie-charts.demo.tsx`. `PieChartXxs`, `PieChartXs`, `PieChartSm`, `PieChartMd` and `PieChartLg` differ only in the `ResponsiveContainer` height (120, 160, 200, 240 and 280), its `max-w-*` class, and the `innerRadius`/`outerRadius` pair on the `` (30/60, 40/80, 50/100, 60/120 and 70/140). Copy the closest one and adjust those numbers for any size in between.", }, { question: "How do I render a solid pie instead of a donut?", answer: "Set `innerRadius={0}` on the ``. The examples ship as donuts because `innerRadius` is half of `outerRadius`; the hole is purely that prop, so there is nothing else to change.", }, { question: "How do I customize the tooltip?", answer: "The chart passes `} />`, where `ChartTooltipContent` comes from `charts-base.tsx`. Whenever a single data point is hovered its value becomes the tooltip title, with or without the flag — `isPieChart` only changes where the supporting line underneath is read from, using the hovered slice's `name` instead of the axis label. It also accepts Recharts' `formatter` and `labelFormatter`, so pass those through the `` to format currency or percentages.", }, { question: "Can I move or restyle the legend?", answer: "Yes. The legend is a standard Recharts `` rendered with `content={ChartLegendContent}`, so placement props go on the `` itself — the examples use `verticalAlign=\"top\" align=\"right\" layout=\"vertical\"`. Recharts passes them down, and `ChartLegendContent` reads `layout` to switch between a stacked column and an inline row, then `align` to justify the items within it. It also accepts `reversed` to flip the item order and a `className`.", }, { question: "Are pie charts responsive, and do they animate?", answer: "Each chart is wrapped in a Recharts `ResponsiveContainer` with a fixed `height` and `initialDimension={{ width: 1, height: 1 }}`, so it fills the width of its parent — the examples cap that with a class such as `max-w-96`. Animation is off by default because the `` sets `isAnimationActive={false}`; remove that prop to re-enable Recharts' entry animation.", }, ]} />