Vesture

Charts

LineChart

A line chart with a static, zero-JS server component and a separate client component for hover tooltips and a toggleable legend — pick whichever your page actually needs.

LineChartInteractiveLineChart

Preview

JanFebMarAprMayJun020406080100120140160180200220240260

Usage

tsx
import { InteractiveLineChart } from "@vesture/react";

const data = [
  { x: "Jan", revenue: 120, cost: 90 },
  { x: "Feb", revenue: 180, cost: 110 },
  { x: "Mar", revenue: 150, cost: 130 },
];

// The parent needs an explicit height — InteractiveLineChart measures it
// via ResizeObserver to auto-size its width.
<div style={{ height: 320 }}>
  <InteractiveLineChart
    data={data}
    series={[
      { key: "revenue", label: "Revenue" },
      { key: "cost", label: "Cost" },
    ]}
  />
</div>

// Server component / static report — no client JS, explicit dimensions:
import { LineChart } from "@vesture/react";

<LineChart width={640} height={320} data={data} series={[{ key: "revenue", label: "Revenue" }]} />

Behavior

  • LineChart takes explicit width/height and renders no event handlers — safe in a server component, has no "use client" directive, and ships zero client JS of its own.
  • InteractiveLineChart auto-sizes to its parent container (ResizeObserver via @visx/responsive's ParentSize, so its parent needs an explicit height), and adds a nearest-point hover tooltip plus a legend below the chart.
  • Clicking a legend item hides that series' line; a series keeps its assigned color if a sibling is hidden, rather than the remaining colors shifting.
  • xScale defaults to inferring from the first data point's x type: a Date infers "time", a number infers "linear", a string infers "band" — override explicitly if your data's x type is ambiguous.
  • Series colors cycle through the theme's 8 chart tokens (vars.chart.series1-8) in order; a 9th+ series wraps back to series1, so the legend label becomes the only way to distinguish them.

Props

LineChartDataPoint

PropTypeDefaultDescription
xstring | number | DateRequired. Shared category/position for every series in this row.
[seriesKey]string | number | DateEach series' value, looked up by its key on this row.

LineChartSeries

PropTypeDefaultDescription
keystringRequired. Looks up this series' value on each data point.
labelstringRequired. Shown in the legend and tooltip.
colorstringOverrides the auto-assigned series1-8 token color for just this series.

LineChart

PropTypeDefaultDescription
data / seriesrequiredRow data and series definitions, above.
width / heightnumberRequired. LineChart has no auto-sizing — pass explicit pixel dimensions.
xScale"linear" | "time" | "band"Overrides the inferred x-axis scale type.
margin{ top, right, bottom, left }{ top: 16, right: 16, bottom: 32, left: 48 }Chart margin, partially overridable.

InteractiveLineChart

PropTypeDefaultDescription
data / series / xScale / marginsame as LineChart
heightnumber320Fixed height — width auto-tracks the parent container.