Los gráficos forman una capa fina y componible sobre Recharts. Tú aportas sus primitivas; logic2b añade ChartContainer, el tipo ChartConfig que vincula cada serie con una etiqueta y un color, y ChartTooltip y ChartLegend compatibles con el tema. Los colores proceden de los tokens --chart-1…5, por lo que se adaptan automáticamente a los modos claro y oscuro.
Instalación
npx logic2b@next add chart¿Prefieres un gráfico ya preparado? Todos los ejemplos de esta página y de la galería de gráficos son elementos instalables del registro. Por ejemplo, npx logic2b@next add chart-area-01 copia el gráfico completo en components/charts/.
Uso
import { Area, AreaChart, CartesianGrid, XAxis } from "recharts"
import {
ChartConfig,
ChartContainer,
ChartTooltip,
ChartTooltipContent,
} from "@/components/ui/chart"
const chartData = [
{ month: "Enero", desktop: 186 },
{ month: "Febrero", desktop: 305 },
{ month: "Marzo", desktop: 237 },
]
const chartConfig = {
desktop: { label: "Escritorio", color: "var(--chart-1)" },
} satisfies ChartConfig
export function Example() {
return (
<ChartContainer config={chartConfig} className="h-[240px] w-full">
<AreaChart data={chartData}>
<CartesianGrid vertical={false} />
<XAxis dataKey="month" tickLine={false} axisLine={false} />
<ChartTooltip content={<ChartTooltipContent />} />
<Area dataKey="desktop" fill="var(--color-desktop)" stroke="var(--color-desktop)" />
</AreaChart>
</ChartContainer>
)
}
Cada clave de chartConfig se convierte en una variable CSS --color-<clave> dentro del contenedor. Usa var(--color-desktop) en vez de fijar un color manualmente.
Ejemplos
Barras
Líneas con varias series
Área apilada
Radar
Radial
Anillo
Playground interactivo
Edita las propiedades del componente y revisa el JSX exacto antes de copiarlo. La vista previa se carga solo cuando esta sección entra en pantalla.
<ChartContainer
className="h-64 w-full max-w-lg"
config={{ "visitors": { "label": "Visitors", "color": "var(--chart-1)" } }}
role="img"
aria-label="Monthly visitors from January to June 2026"
>
<BarChart
accessibilityLayer
data={[{ "month": "Jan", "visitors": 186 }, { "month": "Feb", "visitors": 305 }, { "month": "Mar", "visitors": 237 }, { "month": "Apr", "visitors": 273 }, { "month": "May", "visitors": 209 }, { "month": "Jun", "visitors": 314 }]}
margin={{ "left": 8, "right": 8 }}
>
<CartesianGrid />
<XAxis
dataKey="month"
tickMargin={10}
/>
<Bar
dataKey="visitors"
fill="var(--color-visitors)"
radius={6}
/>
</BarChart>
</ChartContainer>Referencia de API
Generada a partir de las exportaciones públicas de TypeScript en src/ui/chart.tsx. Las descripciones técnicas conservan el texto canónico del código fuente.
ChartConfig
Tipotype ChartConfig = { [k in string]: { label?: React.ReactNode icon?: React.ComponentType } & ( | { color?: string; theme?: never } | { color?: never; theme: Record<keyof typeof THEMES, string> } ) }ChartContainer
ComponenteProps: React.ComponentProps<"div"> & { config: ChartConfig children: React.ComponentProps< typeof RechartsPrimitive.ResponsiveContainer >["children"] }| Propiedad | Tipo | Obligatoria | Valor predeterminado | Descripción |
|---|---|---|---|---|
children | React.ComponentProps< typeof RechartsPrimitive.ResponsiveContainer >["children"] | Sí | — | — |
config | ChartConfig | Sí | — | — |
ChartTooltip
ComponenteAlias directo de RechartsPrimitive.Tooltip.
ChartTooltipContent
ComponenteProps: React.ComponentProps<typeof RechartsPrimitive.Tooltip> & React.ComponentProps<"div"> & { hideLabel?: boolean hideIndicator?: boolean indicator?: "line" | "dot" | "dashed" nameKey?: string labelKey?: string } & Omit< RechartsPrimitive.DefaultTooltipContentProps< TooltipValueType, TooltipNameType >, "accessibilityLayer" >| Propiedad | Tipo | Obligatoria | Valor predeterminado | Descripción |
|---|---|---|---|---|
indicator | "line" | "dot" | "dashed" | No | "dot" | — |
hideLabel | boolean | No | false | — |
hideIndicator | boolean | No | false | — |
nameKey | string | No | — | — |
labelKey | string | No | — | — |
ChartLegend
ComponenteAlias directo de RechartsPrimitive.Legend.
ChartLegendContent
ComponenteProps: React.ComponentProps<"div"> & { hideIcon?: boolean nameKey?: string } & RechartsPrimitive.DefaultLegendContentProps| Propiedad | Tipo | Obligatoria | Valor predeterminado | Descripción |
|---|---|---|---|---|
hideIcon | boolean | No | false | — |
verticalAlign | "top" | "bottom" | "middle" | No | "bottom" | Vertical alignment of the whole Legend container: - `bottom`: shows the Legend below chart, and chart height reduces automatically to make space for it. - `top`: shows the Legend above chart, and chart height reduces automatically. - `middle`: shows the Legend in the middle of chart, covering other content, and chart height remains unchanged. The exact behavior changes depending on `align` prop. |
nameKey | string | No | — | — |
ChartStyle
ComponenteProps: { id: string; config: ChartConfig }| Propiedad | Tipo | Obligatoria | Valor predeterminado | Descripción |
|---|---|---|---|---|
id | string | Sí | — | — |
config | ChartConfig | Sí | — | — |
Contrato de accesibilidad
Comportamiento legible por máquinas y responsabilidades de quien integra chart. Los detalles normativos conservan el texto canónico del registro.
- Soporte
- Contrato de composición
- Patrón
- data visualization
- Recharts
Semántica incorporada
- Chart containers can expose a labelled figure while tooltip content is available to pointer and keyboard interactions supported by the composed chart.
Responsabilidades de integración
- Provide a concise chart name, units and a textual or tabular equivalent for the underlying data.
Limitaciones conocidas
- • Canvas/SVG marks alone are not a complete accessible data representation.