chart
draco-china-github/chartFreeComponent
shadcn/ui publishes no description for this item.
Install it
npx shadcn@latest add https://raw.githubusercontent.com/draco-china/shadcn-pro/main/apps/docs/public/r/styles/radix-sera/chart.jsonSource
1"use client"23import * as React from "react"4import * as RechartsPrimitive from "recharts"5import type { TooltipValueType } from "recharts"67import { cn } from "@/registry/radix-sera/lib/utils"89// Format: { THEME_NAME: CSS_SELECTOR }10const THEMES = { light: "", dark: ".dark" } as const1112const INITIAL_DIMENSION = { width: 320, height: 200 } as const13type TooltipNameType = number | string1415export type ChartConfig = Record<16 string,17 {18 label?: React.ReactNode19 icon?: React.ComponentType20 } & (21 | { color?: string; theme?: never }22 | { color?: never; theme: Record<keyof typeof THEMES, string> }23 )24>2526type ChartContextProps = {27 config: ChartConfig28}2930const ChartContext = React.createContext<ChartContextProps | null>(null)3132function useChart() {33 const context = React.useContext(ChartContext)3435 if (!context) {36 throw new Error("useChart must be used within a <ChartContainer />")37 }3839 return context40}4142function ChartContainer({43 id,44 className,45 children,46 config,47 initialDimension = INITIAL_DIMENSION,48 ...props49}: React.ComponentProps<"div"> & {50 config: ChartConfig51 children: React.ComponentProps<52 typeof RechartsPrimitive.ResponsiveContainer53 >["children"]54 initialDimension?: {55 width: number56 height: number57 }58}) {59 const uniqueId = React.useId()60 const chartId = `chart-${id ?? uniqueId.replace(/:/g, "")}`6162 return (63 <ChartContext.Provider value={{ config }}>64 <div65 data-slot="chart"66 data-chart={chartId}67 className={cn(68 "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",69 className70 )}71 {...props}72 >73 <ChartStyle id={chartId} config={config} />74 <RechartsPrimitive.ResponsiveContainer75 initialDimension={initialDimension}76 >77 {children}78 </RechartsPrimitive.ResponsiveContainer>79 </div>80// … truncated
What it pulls in
npm packages
Files it writes
More from shadcn/ui
All 201 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| accordionaccordion | shadcn/ui | Components | Free | no deps | |
| alertalert | shadcn/ui | Components | Free | no deps | |
| alert-dialogalert-dialog | shadcn/ui | Components | Free | no deps | |
| aspect-ratioaspect-ratio | shadcn/ui | Components | Free | no deps | |
| avataravatar | shadcn/ui | Components | Free | no deps | |
| badgebadge | shadcn/ui | Components | Free | no deps | |
| breadcrumbbreadcrumb | shadcn/ui | Components | Free | no deps | |
| buttonbutton | shadcn/ui | Components | Free | no deps |
