Skip to content

⚠ Early release: v0.3.2.sophistry is not ready for production use. Until 1.0, any minor release may break the API; expect missing features and bugs too.Stability and versioning

Lines, areas and time series

Series over a continuous x: lines, bands and stacked areas inside a <Chart> that fits its axes to the data. Start with ChartAutoFit and SeriesLegend; TimeSeries and CandlestickPrices use a time axis inferred from Date values.

A chart that fits itself

<Chart> ranges its axes from the layers inside it, then draws the frame before the data.

ChartAutoFit.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Chart, LinePlot, Scatter } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const runs = [
{ minutes: 12, km: 2.1 },
{ minutes: 19, km: 3.2 },
{ minutes: 25, km: 4.4 },
{ minutes: 33, km: 5.6 },
{ minutes: 41, km: 7.2 },
];
export default function ChartAutoFit() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 2.5 }));
});
// No ranges: the frame fits both axes to the runs, rounded to nice ticks.
return (
<Stage units={13}>
<Chart
width={9}
height={4.5}
center={{ x: -0.3, y: -0.4 }}
grid
title="Weekly runs"
xLabel="min"
yLabel="km"
progress={shown}
>
<LinePlot data={runs} x="minutes" y="km" />
<Scatter data={runs} x="minutes" y="km" />
</Chart>
</Stage>
);
}

Line and area curves

The same readings drawn three ways: a monotone curve (smooth, but never overshooting a reading) over a monotone band, a straight polyline, and a step-after line that holds each value until the next. Curves are native Béziers, and the reveal cuts them along x without straightening them.

LineCurves.tsx
9 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import {
Chart,
FillBetween,
LinePlot,
Scatter,
} from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const readings = [3, 3.2, 7.5, 8, 4, 4.2, 6.8, 2.5, 3, 6].map(
(level, hour) => ({
hour,
level,
}),
);
const shifted = (by: number) =>
readings.map((r) => ({ hour: r.hour, level: r.level + by }));
const linear = shifted(-1.5);
const steps = shifted(-3);
export default function LineCurves() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 3 }));
});
return (
<Stage units={12}>
<Chart
width={8}
height={4.4}
xLabel="hour"
yRange={[-2, 10, 2]}
grid="y"
legend="top"
// The top legend sits above height: leave it room.
center={{ x: 0, y: -0.3 }}
progress={shown}
>
<FillBetween
data={readings}
x="hour"
y1={(r) => r.level + 0.8}
y2={(r) => r.level - 0.8}
curve="monotone"
/>
{/* A constant series per layer names each curve in the legend. */}
<LinePlot
data={readings}
x="hour"
y="level"
series={() => "monotone"}
curve="monotone"
/>
<LinePlot data={linear} x="hour" y="level" series={() => "linear"} />
<LinePlot
data={steps}
x="hour"
y="level"
series={() => "step-after"}
curve="step-after"
/>
<Scatter data={readings} x="hour" y="level" radius={0.06} />
</Chart>
</Stage>
);
}

Series and a generated legend

One long-format dataset split by series: a line and markers per city, one colour per city from the chart's scale, and a legend that arrives after the data it explains.

SeriesLegend.tsx
5 collapsed lines
import { okabeIto } from "@sophistry/charts";
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Chart, LinePlot, Scatter } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const normals: Record<string, number[]> = {
Oslo: [-4, -4, 0, 5, 11, 15, 17, 16, 11, 6, 1, -3],
Rome: [8, 9, 11, 14, 18, 22, 25, 25, 22, 17, 12, 9],
Cairo: [14, 15, 18, 21, 25, 27, 28, 28, 26, 24, 19, 15],
};
const rows = Object.entries(normals).flatMap(([city, temps]) =>
temps.map((c, i) => ({ city, month: i + 1, c })),
);
export default function SeriesLegend() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 3.5 }));
});
return (
<Stage units={12}>
<Chart
// The legend's room comes out of width (autosize="fit"), so the
// plot and its key are centred together.
width={10}
height={4.2}
center={{ x: 0, y: -0.2 }}
grid="y"
yLabel="°C"
color={{ range: okabeIto }}
legendTitle="City"
progress={progress}
>
<LinePlot data={rows} x="month" y="c" series="city" />
<Scatter data={rows} x="month" y="c" series="city" radius={0.06} />
</Chart>
</Stage>
);
}

Time series

Native Dates make a UTC time axis that ticks on month boundaries and writes dates.

TimeSeries.tsx
2 collapsed lines
import { Stage } from "@sophistry/solidjs";
import { Chart, FillBetween, LinePlot } from "@sophistry/solidjs/charts";
const months = [
4.1, 4.6, 6.8, 9.9, 13.2, 16.4, 18.1, 17.8, 15.2, 11.3, 7.4, 4.9,
];
const temps = months.map((celsius, m) => ({
t: new Date(Date.UTC(2024, m, 15)),
celsius,
}));
export default function TimeSeries() {
return (
<Stage units={12}>
<Chart width={9} height={4.5} yLabel="°C" grid="y">
<FillBetween data={temps} x="t" y1="celsius" />
<LinePlot data={temps} x="t" y="celsius" />
</Chart>
</Stage>
);
}

Annotated series

Marks layered in one chart: a shaded span, a target rule, the series, labelled points with tooltips.

AnnotatedSeries.tsx
11 collapsed lines
import { draw, track, UP } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import {
Chart,
Labels,
LinePlot,
Rects,
RuleY,
Scatter,
} from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const sales = [3.1, 3.6, 4.2, 3.4, 2.6, 2.9, 4.4, 5.1, 5.6, 6.2];
const peak = { month: 9, value: 6.2, note: "record" };
export default function AnnotatedSeries() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 3 }));
});
return (
<Stage units={13}>
<Chart width={9} height={4.5} xLabel="month" yLabel="£m" progress={shown}>
{/* A slump, shaded behind the data, and the year's target. */}
<Rects data={[{ from: 3, to: 5 }]} x1="from" x2="to" color="tomato" />
<RuleY data={[5]} dash={[0.1, 0.08]} tooltip={() => "target: £5m"} />
<LinePlot data={sales} />
<Scatter
data={sales}
symbol="diamond"
radius={0.11}
stagger={0.6}
tooltip
/>
<Labels data={[peak]} x="month" y="value" text="note" direction={UP} />
</Chart>
</Stage>
);
}

One reveal front

reveal="x" sweeps a single clip edge across the plot, so the band, the line and its markers enter together, at a constant rate along x.

SweepReveal.tsx
9 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import {
Chart,
FillBetween,
LinePlot,
Scatter,
} from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const runs = [3.1, 4.2, 3.8, 5.6, 6.1, 5.4, 7.2, 7.9, 7.1, 8.6].map((y, x) => ({
x,
y,
lo: y - 0.8,
hi: y + 0.8,
}));
export default function SweepReveal() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 3 }));
});
return (
<Stage units={12}>
<Chart width={9} height={4.5} grid="y" reveal="x" progress={progress}>
<FillBetween data={runs} x="x" y1="lo" y2="hi" />
<LinePlot data={runs} x="x" y="y" />
<Scatter data={runs} x="x" y="y" radius={0.07} />
</Chart>
</Stage>
);
}

Two y axes

Rainfall as bars on the left axis and temperature as a line on a secondary axis on the right. Layers inside SecondaryY share the month axis and the reveal but fit their own scale, aligned with alignTicks so its ticks sit on the left axis's grid lines, and the frame makes room for the right-hand numbers inside its width.

DualAxis.tsx
10 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import {
Bars,
Chart,
LinePlot,
Scatter,
SecondaryY,
} from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"];
const rain = [78, 61, 55, 52, 49, 41];
const temp = [3.1, 4.2, 7.0, 10.6, 14.4, 18.2];
const climate = months.map((m, i) => ({
m,
rain: rain[i],
temp: temp[i],
// A band axis centres category i at i + 0.5: the line's x.
at: i + 0.5,
}));
const warm = "#e07a5f";
export default function DualAxis() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 2.5 }));
});
return (
<Stage units={12}>
<Chart
width={9}
height={4}
center={{ x: 0, y: -0.4 }}
yLabel="rain (mm)"
y2Label="°C"
// The temperature ticks sit on the rain axis's grid lines.
y2Axis={{ zero: true, alignTicks: true }}
grid="y"
progress={shown}
>
<Bars data={climate} category="m" value="rain" />
<SecondaryY>
<LinePlot data={climate} x="at" y="temp" stroke={warm} />
<Scatter data={climate} x="at" y="temp" color={warm} radius={0.07} />
</SecondaryY>
</Chart>
</Stage>
);
}

Stacked areas

Wide-format rows (one object per x) become stacked bands: y takes one channel per band, mixing keys and functions, and series names them, so the bands take the chart's colours and legend.

StackedAreas.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Chart, StackPlot } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
const rows = Array.from({ length: 13 }, (_, month) => ({
month,
web: 3 + Math.sin(month / 2) * 1.2,
mobile: 2 + month * 0.25,
api: 1.5 + Math.cos(month / 3) * 0.6,
}));
export default function StackedAreas() {
const { play } = usePlayer();
const progress = track(0);
onSettled(() => {
void play(draw(progress, { duration: 2 }));
});
return (
<Stage units={12}>
<Chart
xRange={[0, 12, 2]}
yRange={[0, 10, 2]}
width={9}
height={4.6}
// The top legend sits above height: leave it room.
center={{ x: 0, y: -0.3 }}
xLabel="month"
legend="top"
progress={progress}
>
<StackPlot
data={rows}
x="month"
y={["web", "mobile", (row) => row.api]}
series={["web", "mobile", "api"]}
/>
</Chart>
</Stage>
);
}

Streamgraph

StackPlot with offset="wiggle" and order="insideOut": the layers float around a centre line chosen to keep them as level as possible, and the whole stream grows out of it. The week axis sits at the bottom edge (xAxis position) rather than through the stream, and series names the bands for the legend.

Streamgraph.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Chart, StackPlot } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
// Five smooth bumps peaking at different weeks.
const bump = (week: number, peak: number, width: number, height: number) =>
height * Math.exp(-(((week - peak) / width) ** 2)) + 0.3;
const genres = ["jazz", "folk", "rock", "soul", "funk"] as const;
const rows = Array.from({ length: 41 }, (_, week) => ({
week,
jazz: bump(week, 8, 6, 4),
folk: bump(week, 16, 7, 3),
rock: bump(week, 22, 5, 5),
soul: bump(week, 28, 8, 3),
funk: bump(week, 34, 5, 4),
}));
export default function Streamgraph() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 2.5 }));
});
return (
<Stage units={12}>
<Chart
// The legend's room comes out of width (autosize="fit").
width={10.5}
height={4.5}
// A stream floats around zero, mid-chart: draw the week axis
// along the bottom edge instead of through the stream. Its
// y values are offsets, not quantities, so that axis is hidden.
xAxis={{ position: "bottom" }}
yAxis={{ visible: false }}
xLabel="week"
grid="x"
progress={shown}
>
<StackPlot
data={rows}
x="week"
y={genres}
series={genres}
offset="wiggle"
order="insideOut"
/>
</Chart>
</Stage>
);
}

Candlesticks

Prices on a time axis (inferred from Dates): each wick draws low to high, then the body grows from the open to the close.

CandlestickPrices.tsx
4 collapsed lines
import { draw, track } from "@sophistry/core";
import { Stage, usePlayer } from "@sophistry/solidjs";
import { Candlestick, Chart } from "@sophistry/solidjs/charts";
import { onSettled } from "solid-js";
// A deterministic random walk, one candle per day.
const days = Array.from({ length: 20 }, (_, i) => i).reduce<
{ t: Date; o: number; h: number; l: number; c: number }[]
>((list, i) => {
const open = list.at(-1)?.c ?? 100;
const close = open + Math.sin(i * 1.7) * 3 + Math.cos(i * 0.6) * 1.5;
const high = Math.max(open, close) + 1 + Math.abs(Math.sin(i * 2.3)) * 2;
const low = Math.min(open, close) - 1 - Math.abs(Math.cos(i * 1.1)) * 2;
list.push({
t: new Date(Date.UTC(2026, 2, 2 + i)),
o: open,
h: high,
l: low,
c: close,
});
return list;
}, []);
export default function CandlestickPrices() {
const { play } = usePlayer();
const shown = track(0);
onSettled(() => {
void play(draw(shown, { duration: 3 }));
});
return (
<Stage units={13}>
<Chart width={10} height={4.5} grid="y" progress={shown}>
<Candlestick
data={days}
x="t"
open="o"
high="h"
low="l"
close="c"
stagger={0.7}
tooltip
/>
</Chart>
</Stage>
);
}