BlockDex

Components

Registries

Free blocks

Method

BlockDex

Components

Registries

Free blocks

Method

Open API

BlockDex

Components

Registries

Free blocks

Method

Open API

Components/9ui/chart

chart

9ui/chart
FreeComponent

9ui publishes no description for this item.

Live preview

live · rendered by the registry
Rendered by 9ui on their own page — this is the component running, not a screenshot of it.

Install it

npx shadcn@latest add https://9ui.dev/r/chart.json

Source

ui/chart.tsx9ui.dev/r/chart.json · first 6 KB
1"use client"
2
3import * as React from "react"
4import * as RechartsPrimitive from "recharts"
5
6import { cn } from "@/lib/utils"
7
8const THEMES = { light: "", dark: ".dark" } as const
9
10export type ChartConfig = {
11 [k in string]: {
12 label?: React.ReactNode
13 icon?: React.ComponentType
14 } & (
15 | { color?: string; theme?: never }
16 | { color?: never; theme: Record<keyof typeof THEMES, string> }
17 )
18}
19
20type ChartContextProps = {
21 config: ChartConfig
22}
23
24const ChartContext = React.createContext<ChartContextProps | null>(null)
25
26function useChart() {
27 const context = React.useContext(ChartContext)
28
29 if (!context) {
30 throw new Error("useChart must be used within a <ChartContainer />")
31 }
32
33 return context
34}
35
36function ChartContainer({
37 id,
38 className,
39 children,
40 config,
41 ...props
42}: React.ComponentProps<"div"> & {
43 config: ChartConfig
44 children: React.ComponentProps<
45 typeof RechartsPrimitive.ResponsiveContainer
46 >["children"]
47}) {
48 const uniqueId = React.useId()
49 const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
50
51 return (
52 <ChartContext.Provider value={{ config }}>
53 <div
54 data-slot="chart"
55 data-chart={chartId}
56 className={cn(
57 "[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
58 className
59 )}
60 {...props}
61 >
62 <ChartStyle id={chartId} config={config} />
63 <RechartsPrimitive.ResponsiveContainer>
64 {children}
65 </RechartsPrimitive.ResponsiveContainer>
66 </div>
67 </ChartContext.Provider>
68 )
69}
70
71const ChartStyle = ({ id, config }: { id: string; config: ChartConfig }) => {
72 const colorConfig = Object.entries(config).filter(
73 ([, config]) => config.theme || config.color
74 )
75
76 if (!colorConfig.length) {
77 return null
78 }
79
80 return (
81 <style
82 dangerouslySetInnerHTML={{
83 __html: Object.entries(THEMES)
84 .map(
85 ([theme, prefix]) => `
86${prefix} [data-chart=${id}] {
87${colorConfig
88 .map(([key, itemConfig]) => {
89// … truncated

What it pulls in

npm packages

  • recharts

Files it writes

  • src/components/ui/chart.tsx

Facts

Registry
9ui
Type
registry:ui
Access
Free
Files written
1
Licence
MIT
First indexed
2026-08-03
Last confirmed
yesterday

Go to the source

Docs on 9ui 9ui.dev borabaloglu/9ui on GitHub Raw registry item This item as JSON

More from 9ui

All 56 items
Same registry, same kind — the ones you would have found next
ComponentRegistryKindAccessInstallsCommand
accordionaccordion9uiComponentsFreeno deps
alertalert9uiComponentsFreeno deps
alert-dialogalert-dialog9uiComponentsFreeno deps
aspect-ratioaspect-ratio9uiComponentsFreeno deps
autocompleteautocomplete9uiComponentsFreeno deps
avataravatar9uiComponentsFreeno deps
badgebadge9uiComponentsFreeno deps
breadcrumbsbreadcrumbs9uiComponentsFreeno deps
BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex

BlockDex

Built by

Kynth Studio

Index

Components
Registries
Method
Open API

Guides

shadcn component libraries
Best shadcn registries
Free shadcn blocks

Reference

Corpus counts
Crawl health
hello@kynth.studio
Privacy
Terms

BlockDex