Grid

A customizable grid component for charts with horizontal and vertical lines, fade effects, and dashed styling

Preview

Installation

pnpm dlx shadcn@latest add https://ui.bklit.com/r/grid.json

Usage

The Grid component adds visual reference lines to charts. It must be used inside a chart component (LineChart, AreaChart, BarChart).

import { LineChart, Line, Grid, ChartTooltip } from "@bklitui/ui/charts";

<LineChart data={data}>
  <Grid horizontal />
  <Line dataKey="value" />
  <ChartTooltip />
</LineChart>

Props

PropTypeDefaultDescription
horizontalbooleantrueShow horizontal grid lines
verticalbooleanfalseShow vertical grid lines
numTicksRowsnumber5Number of horizontal lines
numTicksColumnsnumber10Number of vertical lines
rowTickValuesnumber[]-Explicit tick values for horizontal grid lines. When set, overrides numTicksRows. Use with Live Line Chart so grid rows align with LiveYAxis labels.
strokestringvar(--chart-grid)Line color
strokeOpacitynumber1Line opacity
strokeWidthnumber1Line width
strokeDasharraystring"4,4"Dash pattern (empty string for solid)
fadeHorizontalbooleantrueFade horizontal lines at left/right edges
fadeVerticalbooleanfalseFade vertical lines at top/bottom edges

Examples

Horizontal Only (Default)

The most common configuration with horizontal reference lines.

<LineChart data={data}><Grid horizontal /><Line dataKey="value" /><XAxis /><ChartTooltip /></LineChart>

Vertical Only

Use vertical grid lines to emphasize time intervals.

<LineChart data={data}><Grid horizontal={false} vertical /><Line dataKey="value" /><XAxis /><ChartTooltip /></LineChart>

Both Horizontal and Vertical

Display a full grid for detailed reference.

<LineChart data={data}><Grid horizontal vertical /><Line dataKey="value" /><XAxis /><ChartTooltip /></LineChart>

Solid Lines

Remove the dash pattern for solid grid lines.

<LineChart data={data}><Grid horizontal strokeDasharray="" /><Line dataKey="value" /><XAxis /><ChartTooltip /></LineChart>

Without Edge Fade

Disable the edge fade effect for sharp line endings.

<LineChart data={data}><Grid horizontal fadeHorizontal={false} /><Line dataKey="value" /><XAxis /><ChartTooltip /></LineChart>

Dense Grid

Increase the number of grid lines for more granular reference.

<LineChart data={data}><Grid horizontal vertical numTicksRows={10} numTicksColumns={15} /><Line dataKey="value" /><XAxis /><ChartTooltip /></LineChart>

Custom Styling

<LineChart data={data}>
  <Grid
    horizontal
    vertical
    stroke="var(--border)"
    strokeOpacity={0.5}
    strokeWidth={0.5}
    strokeDasharray=""
    fadeHorizontal={false}
    fadeVertical={false}
  />
  <Line dataKey="value" />
</LineChart>

Theming

The Grid uses CSS variables for theming:

:root {
  --chart-grid: oklch(0.9 0 0);
}

.dark {
  --chart-grid: oklch(0.25 0 0);
}