Charts

Copy-paste chart examples for every Bklit UI component.

Composed Chart

Scatter, band, line and bars on one time axis: daily revenue points, the smoothed 7-day trend inside its expected range, and orders as quiet bars underneath. Use the curve menu to swap the line and band interpolation.

import { curveCatmullRom } from "d3-shape";const yDomains = {  orders: ([, max]) => [0, max * 3], // bars in the bottom third  left: [minValue - range * 0.6, maxValue + range * 0.05], // band + points above them};<ComposedChart data={data} xDataKey="date" aspectRatio="2 / 1" maxBarSize={14} yDomains={yDomains}>  <Grid horizontal />  <SeriesBar    dataKey="orders"    fill="color-mix(in oklch, var(--chart-3) 30%, transparent)"    stroke="var(--chart-3)"    radius={3}    yAxisId="orders"  />  <Band    upperKey="high"    lowerKey="low"    label="Expected"    curve={curveCatmullRom.alpha(0.42)}    fill="var(--chart-1)"    fillType="gradient"    fillOpacity={0.22}    strokeDasharray="3,4"    strokeOpacity={0.5}  />  <Scatter dataKey="revenue" fill="color-mix(in oklch, var(--chart-2) 75%, transparent)" radius={3.5} />  <Line dataKey="trend" curve={curveCatmullRom.alpha(0.42)} stroke="var(--chart-1)" strokeWidth={2.5} />  <ChartTooltip />  <XAxis numTicks={6} /></ComposedChart>

Orders sit on their own hidden `yAxisId`; `yDomains` stretches that axis so the bars stay in the bottom third under the band.

Composed Chart — Bar + line

30 daily points with rounded SeriesBar tops (`radius`) and a smoothed revenue line

<ComposedChart margin={{ top: 8, right: 8, bottom: 40, left: 8 }} data={data} xDataKey="date" aspectRatio="3 / 2" barGap={0} maxBarSize={32}>  <Grid horizontal />  <SeriesBar dataKey="units" fill="var(--chart-3)" radius={5} />  <Line curve={curveMonotoneX} dataKey="revenue" stroke="var(--chart-1)" />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={8} /></ComposedChart>

Dense time series: use numTicks on XAxis so labels stay readable. Ticks snap to data rows by default so crosshair and tooltip align.

Composed Chart — Pattern fills

One SeriesBar with a fuchsia-400 diagonal pattern, one solid bar on theme colors; revenue line unchanged

import { PatternPreset } from "@bklitui/ui/charts";<ComposedChart margin={{ top: 8, right: 8, bottom: 40, left: 8 }} data={data} aspectRatio="3 / 2" barGap={0} maxBarSize={22}>  <PatternPreset    color="#e879f9"    id="composed-pat-fuchsia"    preset="diagonal-up"  />  <Grid horizontal />  <SeriesBar dataKey="units" fill="url(#composed-pat-fuchsia)" stroke="#e879f9" />  <SeriesBar dataKey="runRate" fill="var(--chart-5)" />  <Line curve={curveMonotoneX} dataKey="revenue" stroke="var(--chart-1)" />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={8} /></ComposedChart>

Composed Chart — Markers & dashed tail

Ring markers and a dashed projection on the run-rate line and area stroke

<ComposedChart data={data} xDataKey="date" aspectRatio="3 / 2">  <Grid horizontal />  <SeriesBar dataKey="revenue" fill="var(--chart-1)" radius={4} />  <Area curve={curveMonotoneX}    dataKey="runRate"    dashArray="6,4"    dashFromIndex={4}    fill="var(--chart-4)"    fillOpacity={0.3}    showMarkers  />  <Line curve={curveMonotoneX}    dataKey="runRate"    dashArray="6,4"    dashFromIndex={4}    showMarkers    stroke="var(--chart-2)"    strokeWidth={2}  />  <ChartTooltip showCrosshair={false} />  <XAxis tickMode="data" /></ComposedChart>

Use dashFromIndex on Line and Area when projecting an incomplete final period

Composed Chart — Price + volume crosshair

Candlesticks with a 5-day average over volume bars, and a finance-style crosshair: the price under the cursor pinned to the right axis

const yDomains = {  volume: ([, max]) => [0, max * 4], // bars in the bottom quarter  right: ([min, max]) => [min - (max - min) * 0.45, max], // candles above them};<ComposedChart data={data} xDataKey="date" margin={{ top: 8, right: 72, bottom: 40, left: 8 }} aspectRatio="3 / 2" maxBarSize={10} yDomains={yDomains}>  <Grid horizontal />  <SeriesBar dataKey="volume" fill="var(--chart-3)" fadedOpacity={0.4} yAxisId="volume" />  <Candlestick yAxisId="right" widthRatio={0.55} />  <Line curve={curveMonotoneX} dataKey="ma5" stroke="var(--chart-1)" strokeWidth={1.5} yAxisId="right" />  <YAxis orientation="right" yAxisId="right" formatValue={(v) => `$${Math.round(v)}`} />  <ChartCrosshair yAxisId="right" numberFlow prefix="$" format={{ minimumFractionDigits: 2, maximumFractionDigits: 2 }} />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={6} /></ComposedChart>

`ChartCrosshair` follows the cursor's y freely and snaps its vertical line to the hovered candle. The pill reads the value from the axis you pass in `yAxisId`, rolls digits with `numberFlow`, and the `YAxis` ticks it covers fade out — the same as the date pill on the x-axis. `yDomains` keeps the volume bars in the bottom quarter and the candles above them.

Composed Chart — Scatter crosshair

Raw daily signups with a 7-day mean and fitted trend, under a free-moving crosshair that reads the value on the left axis

<ComposedChart data={data} xDataKey="date" margin={{ top: 8, right: 8, bottom: 40, left: 48 }} aspectRatio="3 / 2">  <Grid horizontal />  <Scatter dataKey="signups" fill="var(--chart-2)" radius={4} />  <Line dataKey="avg7" stroke="var(--chart-1)" curve={curveMonotoneX} />  <TrendLine dataKey="signups" stroke="var(--chart-4)" strokeStyle="dashed" />  <YAxis />  <ChartCrosshair snap={false} numberFlow format={{ maximumFractionDigits: 0 }} />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={6} /></ComposedChart>

`snap={false}` lets the vertical line follow the cursor too, so both lines meet exactly under the pointer. Scatter registers like any other series, so the tooltip lists the raw value next to the average.

Composed Chart — Actuals + forecast band

Bars for the measured period, then a dashed forecast inside a widening confidence band

<ComposedChart data={data} xDataKey="date" aspectRatio="3 / 2" maxBarSize={18}>  <Grid horizontal />  <Band curve={curveMonotoneX} upperKey="upper" lowerKey="lower" label="Range" fill="var(--chart-2)" fillOpacity={0.18} />  <SeriesBar dataKey="actual" fill="var(--chart-3)" radius={3} />  <Line curve={curveMonotoneX} dataKey="forecast" stroke="var(--chart-2)" dashFromIndex={20} dashArray="5,4" />  <ChartTooltip />  <XAxis numTicks={6} /></ComposedChart>

Rows without an `actual` value simply skip the bar; the band and dashed tail carry the forecast.

Composed Chart — P&L + trade count

A profit / loss line that recolours across zero, with daily trades as bars on their own axis

<ComposedChart data={data} xDataKey="date" margin={{ top: 8, right: 8, bottom: 40, left: 48 }} aspectRatio="3 / 2" maxBarSize={12}>  <Grid horizontal />  <SeriesBar dataKey="trades" fill="var(--muted-foreground)" fadedOpacity={0.5} yAxisId="right" />  <ProfitLossLine dataKey="pnl" curve={curveMonotoneX} fadeEdges strokeWidth={2} />  <YAxis yAxisId="left" />  <ChartTooltip />  <XAxis numTicks={6} /></ComposedChart>

Putting the bars on a separate axis keeps them anchored to the bottom while the P&L axis spans negative values.

Composed Chart — Stacked bars + area, two axes

Stacked channel bars on the left (domain fits the stack totals) and revenue as an area on the right

<ComposedChart data={data} xDataKey="date" margin={{ top: 8, right: 56, bottom: 40, left: 56 }} aspectRatio="3 / 2" stacked stackGap={3} barGap={0} maxBarSize={20}>  <Grid horizontal />  <SeriesBar dataKey="direct" fill="var(--chart-1)" radius={4} />  <SeriesBar dataKey="partner" fill="var(--chart-3)" radius={4} />  <Area curve={curveMonotoneX} dataKey="revenue" fill="var(--chart-2)" fillOpacity={0.15} yAxisId="right" />  <YAxis yAxisId="left" />  <YAxis orientation="right" yAxisId="right" />  <ChartTooltip />  <XAxis numTicks={6} /></ComposedChart>

`stackGap` separates the rounded segments. Bars are inset half a slot from each edge, so the first and last columns clear both y-axes.

Composed Chart — Sessions area + signup points

Sessions as a soft area on the left axis, individual signup days as ringed points on the right

<ComposedChart data={data} xDataKey="date" margin={{ top: 8, right: 56, bottom: 40, left: 8 }} aspectRatio="3 / 2">  <Grid horizontal />  <Area dataKey="sessions" fill="var(--chart-3)" fillOpacity={0.2} curve={curveMonotoneX} />  <Scatter dataKey="signups" fill="var(--chart-1)" radius={3.5} strokeWidth={1.5} yAxisId="right" />  <YAxis orientation="right" yAxisId="right" />  <ChartTooltip />  <XAxis numTicks={6} /></ComposedChart>

Composed Chart - Pattern Background

Diagonal pattern fill instead of grid lines

<ComposedChart margin={{ top: 8, right: 8, bottom: 40, left: 8 }} data={data} xDataKey="date">  <Background />  <SeriesBar dataKey="units" fill="var(--chart-3)" radius={4} />  <Line curve={curveMonotoneX} dataKey="revenue" stroke="var(--chart-1)" />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={8} /></ComposedChart>

Use Background instead of Grid — see /docs/utility/background

Composed Chart - Dot Grid Background

Dot grid texture with edge fade

<ComposedChart margin={{ top: 8, right: 8, bottom: 40, left: 8 }} data={data} xDataKey="date">  <Background pattern="dots" opacity={0.85} />  <SeriesBar dataKey="units" fill="var(--chart-3)" radius={4} />  <Line curve={curveMonotoneX} dataKey="revenue" stroke="var(--chart-1)" />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={8} /></ComposedChart>

Composed Chart - Reference Band

Horizontal Y band behind the series with dashed edges and bracket markers

<ComposedChart margin={{ top: 8, right: 8, bottom: 40, left: 8 }} data={data} xDataKey="date">  <ReferenceArea y1={95} y2={110} strokeStyle="dashed" showMarkers />  <SeriesBar dataKey="units" fill="var(--chart-3)" radius={4} />  <Line curve={curveMonotoneX} dataKey="revenue" stroke="var(--chart-1)" />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={8} /></ComposedChart>

See /docs/utility/reference-area — tune bounds, fill, and markers in Studio

Composed Chart - Pattern Reference Band

Pattern fill inside the band with colored Y-axis tick labels

<ComposedChart margin={{ top: 8, right: 8, bottom: 40, left: 8 }} data={data} xDataKey="date">  <ReferenceArea    y1={95}    y2={110}    pattern="diagonal-up"    patternColor="var(--chart-foreground-muted)"    axisLabelColor="var(--chart-1)"    fillOpacity={0.85}  />  <SeriesBar dataKey="units" fill="var(--chart-3)" radius={4} />  <Line curve={curveMonotoneX} dataKey="revenue" stroke="var(--chart-1)" />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={8} /></ComposedChart>

Composed Chart - Trend Line

Dashed least-squares trend line drawn over the series

<ComposedChart margin={{ top: 8, right: 8, bottom: 40, left: 8 }} data={data} xDataKey="date">  <Grid horizontal />  <SeriesBar dataKey="units" fill="var(--chart-3)" radius={4} />  <Line curve={curveMonotoneX} dataKey="revenue" stroke="var(--chart-2)" />  <TrendLine dataKey="revenue" stroke="var(--chart-1)" />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={8} /></ComposedChart>

See /docs/utility/trend-line — place TrendLine after the series so it draws on top

Composed Chart - Gradient Trend Line

Gradient stroke along the fit with faded ends

<ComposedChart margin={{ top: 8, right: 8, bottom: 40, left: 8 }} data={data} xDataKey="date">  <Grid horizontal />  <SeriesBar dataKey="units" fill="var(--chart-3)" radius={4} />  <Line curve={curveMonotoneX} dataKey="revenue" stroke="var(--chart-2)" />  <TrendLine    dataKey="revenue"    strokeStyle="gradient"    gradientStart="var(--chart-3)"    gradientEnd="var(--chart-1)"    strokeWidth={2.5}    fadeEdges  />  <ChartTooltip showCrosshair={false} />  <XAxis numTicks={8} /></ComposedChart>