← kothry

Charts

Thin composable wrappers around recharts: ChartContainer provides the responsive canvas and theme colors; ChartLine / ChartBar / ChartArea wrap the chart roots and rotate the --chart-1..6 series palette; grid, axes, tooltip and legend come pre-styled with semantic tokens. TreeMap shares the same palette.

Line chart

Series colors rotate through --chart-1..6 automatically; pass stroke to override.

<ChartContainer>
  <ChartLine data={data}>
    <ChartGrid />
    <ChartXAxis dataKey="month" />
    <ChartYAxis />
    <ChartTooltip />
    <ChartLegend />
    <Line type="monotone" dataKey="scans" name="Scans" dot={false} strokeWidth={2} />
    <Line type="monotone" dataKey="findings" name="Findings" dot={false} strokeWidth={2} />
  </ChartLine>
</ChartContainer>

Bar chart

Same composition with ChartBar; the tooltip cursor band follows the hover token.

<ChartContainer>
  <ChartBar data={data}>
    <ChartGrid />
    <ChartXAxis dataKey="severity" />
    <ChartYAxis />
    <ChartTooltip />
    <ChartLegend />
    <Bar dataKey="open" name="Open" radius={[4, 4, 0, 0]} />
    <Bar dataKey="resolved" name="Resolved" radius={[4, 4, 0, 0]} />
  </ChartBar>
</ChartContainer>

Area chart

Area fills default to a 10% tint of the series color.

<ChartContainer>
  <ChartArea data={data}>
    <ChartGrid />
    <ChartXAxis dataKey="month" />
    <ChartYAxis />
    <ChartTooltip />
    <Area type="monotone" dataKey="scans" name="Scans" strokeWidth={2} />
  </ChartArea>
</ChartContainer>

Tree map

Proportional rectangles with the shared series palette; aria-label is required.

<TreeMap
  data={[
    { name: 'Lending', value: 4200 },
    { name: 'DEX', value: 3100 },
    // …
  ]}
  aria-label="Total value locked by protocol category"
/>

Chart API

Thin composable wrappers around recharts 3.x. ChartContainer provides the responsive canvas and theme colors via context; the root wrappers rotate the --chart-1..6 palette onto their Line/Bar/Area children (re-exported from recharts so you need no direct recharts dependency). Each wrapper forwards its props to the underlying recharts component.

Prop / methodTypeDefaultDescription
ChartContainerReact.ComponentProps<'div'>h-64 w-fullSizes the chart (height via className) and mounts the recharts ResponsiveContainer once computed theme colors are available. Takes a single chart-root child.
ChartLineReact.ComponentProps<typeof LineChart>Line-chart root. Pass data plus chrome/series children; series colors resolve via useChartColors. Wraps recharts LineChart.
ChartBarReact.ComponentProps<typeof BarChart>Bar-chart root. Same composition as ChartLine. Wraps recharts BarChart.
ChartAreaReact.ComponentProps<typeof AreaChart>Area-chart root. Area fills default to a 10% tint of the series color. Wraps recharts AreaChart.
Line / Bar / Arearecharts series elementsrecharts series primitives re-exported here. Place them inside the matching root; stroke/fill colors are assigned automatically (explicit stroke/fill wins).
ChartGridReact.ComponentProps<typeof CartesianGrid>CartesianGrid pre-styled with border-secondary lines; horizontal-only (vertical={false}) by default.
ChartXAxisReact.ComponentProps<typeof XAxis>XAxis with axis/tick lines removed and 12px text-quaternary ticks. Set dataKey to the category field.
ChartYAxisReact.ComponentProps<typeof YAxis>YAxis pre-styled to match ChartXAxis (no axis/tick lines, 12px ticks).
ChartTooltiprecharts TooltipPropsPopover-style tooltip card with a hover cursor band. Wraps recharts Tooltip with a custom content renderer.
ChartLegendrecharts LegendPropsHorizontal legend below the plot: a series-color dot plus a text-secondary label per entry. Wraps recharts Legend.
useChartColors() => ChartColorsHook returning the computed --chart-1..6 series palette plus grid/tick/surface/cursor/label values, kept in sync with light/dark switches.

TreeMap API

A static proportional treemap (role="img") sharing the --chart-1..6 series palette. Extends React.ComponentProps<'div'> minus children; extra div props are forwarded.

Prop / methodTypeDefaultDescription
dataTreemapProps['data']Flat or nested treemap data; each cell's area is taken from dataKey.
dataKeyTreemapProps['dataKey']'value'Field holding the cell area value.
nameKeyTreemapProps['nameKey']'name'Field holding the cell label.
aspectRationumberTarget cell aspect ratio passed to recharts squarify.
aria-labelstringRequired. The map renders as a single role="img" graphic, so it needs a text alternative.
classNamestringh-64 w-fullClasses merged onto the wrapper; control height here.