Chart
neon-ui/chartFreeComponent
shadcn chart primitives (Recharts container, tooltip, legend) themed to the Neon tokens.
Install it
npx shadcn@latest add https://ui.neon.com/r/chart.jsonSource
1import * as React from "react"2import * as RechartsPrimitive from "recharts"3import type { TooltipValueType } from "recharts"45import { cn } from "@/lib/utils"67// Format: { THEME_NAME: CSS_SELECTOR }8const THEMES = { light: "", dark: ".dark" } as const910const INITIAL_DIMENSION = { width: 320, height: 200 } as const11type TooltipNameType = number | string1213export type ChartConfig = Record<14 string,15 {16 label?: React.ReactNode17 icon?: React.ComponentType18 } & (19 | { color?: string; theme?: never }20 | { color?: never; theme: Record<keyof typeof THEMES, string> }21 )22>2324type ChartContextProps = {25 config: ChartConfig26}2728const ChartContext = React.createContext<ChartContextProps | null>(null)2930function useChart() {31 const context = React.useContext(ChartContext)3233 if (!context) {34 throw new Error("useChart must be used within a <ChartContainer />")35 }3637 return context38}3940function ChartContainer({41 id,42 className,43 children,44 config,45 initialDimension = INITIAL_DIMENSION,46 ...props47}: React.ComponentProps<"div"> & {48 config: ChartConfig49 children: React.ComponentProps<50 typeof RechartsPrimitive.ResponsiveContainer51 >["children"]52 initialDimension?: {53 width: number54 height: number55 }56}) {57 const uniqueId = React.useId()58 const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`5960 return (61 <ChartContext.Provider value={{ config }}>62 <div63 data-slot="chart"64 data-chart={chartId}65 className={cn(66 "flex aspect-video justify-center text-xs [&_.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-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.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 [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",67 className68 )}69 {...props}70 >71 <ChartStyle id={chartId} config={config} />72 <RechartsPrimitive.ResponsiveContainer73 initialDimension={initialDimension}74 >75 {children}76 </RechartsPrimitive.ResponsiveContainer>77 </div>78 </ChartContext.Provider>79 )80}81// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from neon-ui
All 77 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| ActivityFeedactivity-feed | neon-ui | Components | Free | 2 deps | |
| AgentChatagent-chat | neon-ui | Components | Free | 6 deps | |
| AnimatedWashanimated-wash | neon-ui | Components | Free | no deps · 2 files | |
| ApiKeyListapi-key-list | neon-ui | Components | Free | 2 deps | |
| AppCardapp-card | neon-ui | Components | Free | 2 deps | |
| AppCreatorapp-creator | neon-ui | Components | Free | 2 deps | |
| AuthFormauth-form | neon-ui | Components | Free | no deps | |
| AutoscaleChartautoscale-chart | neon-ui | Components | Free | 1 dep |
