Radial Chart
A composable radial bar chart built with SVG and D3 scales.
0
30
50
70
180 (half)
270
360 (full)
#Installation
bunx --bun bun add @barefootjs/chart#Usage
Browser Visitors
January - June 2024
1"use client"23import type { ChartConfig } from "@barefootjs/chart"4import {5 ChartContainer,6 RadialChart,7 RadialBar,8} from "@/components/ui/chart"910const chartConfig: ChartConfig = {11 safari: { label: "Safari", color: "hsl(221 83% 53%)" },12 chrome: { label: "Chrome", color: "hsl(142 76% 36%)" },13 firefox: { label: "Firefox", color: "hsl(38 92% 50%)" },14 edge: { label: "Edge", color: "hsl(280 65% 60%)" },15 other: { label: "Other", color: "hsl(340 75% 55%)" },16}1718const chartData = [19 { browser: "safari", visitors: 200, fill: "var(--color-safari)" },20 { browser: "chrome", visitors: 275, fill: "var(--color-chrome)" },21 { browser: "firefox", visitors: 187, fill: "var(--color-firefox)" },22 { browser: "edge", visitors: 173, fill: "var(--color-edge)" },23 { browser: "other", visitors: 90, fill: "var(--color-other)" },24]2526export function MyRadialChart() {27 return (28 <ChartContainer config={chartConfig} className="w-full">29 <RadialChart30 data={chartData}31 innerRadius={50}32 outerRadius={110}33 >34 <RadialBar dataKey="visitors" />35 </RadialChart>36 </ChartContainer>37 )38}#Examples
#Basic
1"use client"23import type { ChartConfig } from "@barefootjs/chart"45const chartConfig: ChartConfig = {6 safari: { label: "Safari", color: "hsl(221 83% 53%)" },7 chrome: { label: "Chrome", color: "hsl(142 76% 36%)" },8 // ...9}1011const chartData = [12 { browser: "safari", visitors: 200, fill: "var(--color-safari)" },13 { browser: "chrome", visitors: 275, fill: "var(--color-chrome)" },14 // ...15]1617export function RadialChartBasicDemo() {18 return (19 <ChartContainer config={chartConfig} className="w-full">20 <RadialChart data={chartData} innerRadius={50} outerRadius={110}>21 <RadialBar dataKey="visitors" />22 </RadialChart>23 </ChartContainer>24 )25}#Label
Total Visitors
With center label
1"use client"23import {4 ChartContainer,5 RadialChart,6 RadialBar,7 RadialChartLabel,8} from "@/components/ui/chart"910export function RadialChartLabelDemo() {11 const total = chartData.reduce((sum, d) => sum + d.visitors, 0)1213 return (14 <ChartContainer config={chartConfig} className="w-full">15 <RadialChart data={chartData} innerRadius={60} outerRadius={110}>16 <RadialBar dataKey="visitors" />17 <RadialChartLabel>18 <tspan className="text-3xl font-bold">{total}</tspan>19 <tspan className="text-xs">Visitors</tspan>20 </RadialChartLabel>21 </RadialChart>22 </ChartContainer>23 )24}#Half Circle
Half Circle
Custom start and end angle
1"use client"23export function RadialChartHalfDemo() {4 return (5 <ChartContainer config={chartConfig} className="w-full">6 <RadialChart7 data={chartData}8 startAngle={180}9 endAngle={0}10 innerRadius={50}11 outerRadius={110}12 >13 <RadialBar dataKey="visitors" />14 </RadialChart>15 </ChartContainer>16 )17}#Interactive
Show:
1"use client"23import { createSignal } from "@barefootjs/dom"45export function RadialChartInteractiveDemo() {6 const [showAll, setShowAll] = createSignal(true)78 return (9 <div>10 <div className="flex gap-2 mb-4">11 <button onClick={() => setShowAll(true)}>12 All Browsers13 </button>14 <button onClick={() => setShowAll(false)}>15 Top 316 </button>17 </div>18 <ChartContainer config={chartConfig} className="w-full">19 <RadialChart20 data={showAll() ? fullData : topThree}21 innerRadius={50}22 outerRadius={110}23 >24 <RadialBar dataKey="visitors" />25 </RadialChart>26 </ChartContainer>27 </div>28 )29}#API Reference
RadialChart
| Prop | Type | Default | Description |
|---|---|---|---|
| data | Record<string, unknown>[] | - | Array of data objects. Each object represents one ring in the radial chart. |
| innerRadius | number | 40% of max | Inner radius of the radial chart in pixels. |
| outerRadius | number | auto | Outer radius of the radial chart in pixels. |
| startAngle | number | 0 | Start angle in degrees (0 = top, clockwise). |
| endAngle | number | 360 | End angle in degrees. |
ChartContainer
| Prop | Type | Default | Description |
|---|---|---|---|
| config | ChartConfig | - | Maps each data key to a label and color. Sets CSS variables for theming. |
| className | string | - | Additional CSS class names for the container element. |
RadialBar
| Prop | Type | Default | Description |
|---|---|---|---|
| dataKey | string | - | The key in the data objects to use for arc values. |
| fill | string | currentColor | Fill color for the arcs. Each data item can override with its own fill property. |
RadialChartLabel
| Prop | Type | Default | Description |
|---|---|---|---|
| children | ReactNode | - | Content to display in the center of the radial chart. |