Chart
uiable/chartFreeComponent
Chart component.
Live preview
live · rendered by the registry
Rendered by uiable on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://uiable.com/r/chart.jsonSource
1"use client";23import { CSSProperties, ComponentProps, ComponentType, ReactNode, createContext, useContext, useId, useMemo } from "react";45import * as RechartsPrimitive from "recharts";6import type { TooltipValueType } from "recharts";78import { cn } from "@/lib/utils";910// Format: { THEME_NAME: CSS_SELECTOR }11const THEMES = { light: "", dark: ".dark" } as const;1213const INITIAL_DIMENSION = { width: 320, height: 200 } as const;14type TooltipNameType = number | string;1516export type ChartConfig = Record<17 string,18 {19 label?: ReactNode;20 icon?: ComponentType;21 } & (22 | { color?: string; theme?: never }23 | { color?: never; theme: Record<keyof typeof THEMES, string> }24 )25>;2627type ChartContextProps = {28 config: ChartConfig;29};3031const ChartContext = createContext<ChartContextProps | null>(null);3233function useChart() {34 const context = useContext(ChartContext);3536 if (!context) {37 throw new Error("useChart must be used within a <ChartContainer />");38 }3940 return context;41}4243function ChartContainer({44 id,45 className,46 children,47 config,48 initialDimension = INITIAL_DIMENSION,49 ...props50}: ComponentProps<"div"> & {51 config: ChartConfig;52 children: ComponentProps<53 typeof RechartsPrimitive.ResponsiveContainer54 >["children"];55 initialDimension?: {56 width: number;57 height: number;58 };59}) {60 const uniqueId = useId();61 const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`;6263 return (64 <ChartContext.Provider value={{ config }}>65 <div66 data-slot="chart"67 data-chart={chartId}68 className={cn(69 "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",70 className71 )}72 {...props}73 >74 <ChartStyle id={chartId} config={config} />75 <RechartsPrimitive.ResponsiveContainer76// … truncated
What it pulls in
npm packages
Files it writes
More from uiable
All 712 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | uiable | Components | Free | 2 deps | |
| Alertalert | uiable | Components | Free | 1 dep | |
| Alert Dialogalert-dialog | uiable | Components | Free | 1 dep | |
| Aspect Ratioaspect-ratio | uiable | Components | Free | no deps | |
| Attachmentattachment | uiable | Components | Free | 2 deps | |
| Avataravatar | uiable | Components | Free | 1 dep | |
| Badgebadge | uiable | Components | Free | 2 deps | |
| Breadcrumbbreadcrumb | uiable | Components | Free | 2 deps |
