Custom Label Pie Chart
Display categorical data with fully customizable label rendering and no connecting lines. Perfect for React applications requiring advanced label control with Next.js integration and TypeScript support.
Powered by
Installation
npx shadcn@latest add https://www.shadcn.io/registry/pie-chart-04.json
npx shadcn@latest add https://www.shadcn.io/registry/pie-chart-04.json
pnpm dlx shadcn@latest add https://www.shadcn.io/registry/pie-chart-04.json
bunx shadcn@latest add https://www.shadcn.io/registry/pie-chart-04.json
Features
- Custom label rendering with full control over text positioning and styling
- No label lines removing connecting lines between labels and segments
- Theme-aware text color using HSL CSS variables for proper contrast
- Advanced positioning with precise control over label placement
- TypeScript support with complete type definitions for custom label functions
- shadcn/ui integration using Chart and tooltip components without background
Use Cases
This free open source React component works well for:
- Custom label designs - Create unique label styles beyond default rendering built with Next.js
- Clean presentations - Display data without visual clutter from label lines using TypeScript and Tailwind CSS
- Branded visualizations - Apply specific styling requirements for corporate designs
- Advanced dashboards - Implement sophisticated label positioning and formatting
API Reference
ChartPieLabelCustom
Prop | Type | Default | Description |
---|---|---|---|
className | string | - | Additional CSS classes for the container |
Chart Configuration
The component uses the same browser data configuration:
const chartConfig = {
visitors: {
label: "Visitors",
},
chrome: {
label: "Chrome",
color: "var(--chart-1)",
},
// ... additional segments
} satisfies ChartConfig
Custom Label Implementation
The key feature is the custom label function with labelLine={false}
:
<Pie
data={chartData}
dataKey="visitors"
labelLine={false}
label={({ payload, ...props }) => {
return (
<text
cx={props.cx}
cy={props.cy}
x={props.x}
y={props.y}
textAnchor={props.textAnchor}
dominantBaseline={props.dominantBaseline}
fill="hsla(var(--foreground))"
>
{payload.visitors}
</text>
)
}}
nameKey="browser"
/>
Implementation Notes
- Custom label function receives position props and payload data
- Uses
hsla(var(--foreground))
for theme-aware text color labelLine={false}
removes connecting lines for cleaner appearance- Full control over text positioning using cx, cy, x, y coordinates
- Perfect for implementing custom label formatting or styling
- Maintains all standard pie chart interactivity and tooltips
Labeled Pie Chart
Display categorical data with visible segment labels showing values directly on the chart. Perfect for React applications requiring clear data visualization with Next.js integration and TypeScript support.
Label List Pie Chart
Display categorical data with formatted labels showing browser names directly on segments. Perfect for React applications requiring enhanced label presentation with Next.js integration and TypeScript support.