Background

Pattern fill for the plot area when grid lines are hidden — presets, edge fade, and enter animation

Preview

Installation

pnpm dlx shadcn@latest add @bklit/background

Usage

Use Background instead of Grid when you want a textured plot fill rather than reference lines. It must be a child of a cartesian chart (LineChart, AreaChart, BarChart, ScatterChart, CandlestickChart, ComposedChart, LiveLineChart, and other charts that provide chart context).

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

<LineChart data={data}>
  <Background pattern="diagonal" />
  <Line dataKey="value" />
  <XAxis />
  <ChartTooltip />
</LineChart>

Background renders behind series layers. On time-series charts it sits outside the series clip reveal and fades in after the chart finishes loading.

Props

PropTypeDefaultDescription
pattern"diagonal" | "horizontal" | "vertical" | "cross" | "dots" | "circles" | "accent" | "none""diagonal"Pattern preset ("none" renders nothing)
colorstringvar(--chart-grid)Pattern stroke or dot color
scalenumber1Tile scale multiplier
strokeWidthnumberpreset defaultLine stroke width for line-based patterns
radiusnumberpreset defaultDot or circle radius for dots / circles
complementbooleanfalseAlternate tile fill for circle patterns
fillstringSolid fill inside circles
dotFillbooleantrueDot grid only — hollow dots when false
tileBackgroundstringBackground color inside each pattern tile
showFillbooleantrueApply the pattern texture to the plot area
opacitynumber1Pattern fill opacity
fadeHorizontalbooleantrueFade pattern at left and right edges
fadeVerticalbooleantrueFade pattern at top and bottom edges
fadeHorizontalLengthnumber10Horizontal fade zone as % of plot width per edge (0–45)
fadeVerticalLengthnumber10Vertical fade zone as % of plot height per edge (0–45)

Patterns use @visx/pattern under the hood (PatternLines and PatternCircles).

Studio

Edit in Studio

Open in Studio

Open Studio with the line chart, hide Grid in the layers panel, then select Background to tune pattern, fade, and opacity. The same layer is available on area, bar, candlestick, composed, live line, line, and scatter charts.

Examples

Diagonal (default)

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

Dot grid

<LineChart data={data}>  <Background pattern="dots" opacity={0.85} />  <Line dataKey="value" />  <XAxis />  <ChartTooltip /></LineChart>

Cross hatch

<LineChart data={data}>  <Background pattern="cross" scale={1.25} />  <Line dataKey="value" />  <XAxis />  <ChartTooltip /></ComponentShowcase>

No edge fade

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

Grid vs Background

Use Grid for reference lines. Use Background when you want a subtle pattern fill without ticks. They are typically mutually exclusive — pick one visual treatment for the plot area.