Charts and graphs · @jengacore/chart-line
Line chart
Trends per series with a dash pattern and dots per line, so no line depends on hue alone.
Transfer latency (ms)Latency improved from week 38: the 99th percentile fell from 1,390 ms to 905 ms, the median from 190 ms to 158 ms.
| Week | Median | 95th percentile | 99th percentile |
|---|---|---|---|
| W36 | 180 | 620 | 1,210 |
| W37 | 176 | 598 | 1,150 |
| W38 | 190 | 655 | 1,390 |
| W39 | 171 | 570 | 1,080 |
| W40 | 165 | 540 | 990 |
| W41 | 168 | 552 | 1,020 |
| W42 | 160 | 515 | 940 |
| W43 | 158 | 498 | 905 |
Install
terminal
npx shadcn@latest add @jengacore/chart-lineWithout the namespace configured: npx shadcn@latest add https://ui.jengacore.com/r/<new-york-v4|base-nova>/chart-line.json
Registry dependencies
Source
components/blocks/chart-line.tsx
"use client"
import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts"
import { ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart"
import { ChartFigure, type ChartCopy, seriesConfig, seriesDash, type ChartSeries } from "@/components/jc/chart-figure"
type Row = Record<string, string | number>
const SAMPLE: Row[] = [
{ week: "W36", p50: 180, p95: 620, p99: 1210 },
{ week: "W37", p50: 176, p95: 598, p99: 1150 },
{ week: "W38", p50: 190, p95: 655, p99: 1390 },
{ week: "W39", p50: 171, p95: 570, p99: 1080 },
{ week: "W40", p50: 165, p95: 540, p99: 990 },
{ week: "W41", p50: 168, p95: 552, p99: 1020 },
{ week: "W42", p50: 160, p95: 515, p99: 940 },
{ week: "W43", p50: 158, p95: 498, p99: 905 },
]
const SAMPLE_SERIES: ChartSeries[] = [
{ key: "p50", label: "Median" },
{ key: "p95", label: "95th percentile" },
{ key: "p99", label: "99th percentile" },
]
/** Line chart: a trend per series. Each line has its own dash pattern and dot, so it never depends on hue alone. */
export function ChartLine({
data = SAMPLE,
xKey = "week",
xLabel = "Week",
series = SAMPLE_SERIES,
title = "Transfer latency (ms)",
summary = "Latency improved from week 38: the 99th percentile fell from 1,390 ms to 905 ms, the median from 190 ms to 158 ms.",
showTable,
className,
}: {
xKey?: string
xLabel?: string
series?: ChartSeries[]
showTable?: boolean
className?: string
} & ChartCopy<Row[]>) {
const config = seriesConfig(series)
return (
<ChartFigure
title={title}
summary={summary}
data={data}
columns={[{ key: xKey, label: xLabel }, ...series.map((s) => ({ key: s.key, label: s.label }))]}
showTable={showTable}
className={className}
>
<ChartContainer config={config} className="aspect-auto h-64 w-full">
<LineChart data={data} accessibilityLayer title={title} margin={{ left: 4, right: 12, top: 8 }}>
<CartesianGrid vertical={false} />
<XAxis dataKey={xKey} tickLine={false} axisLine={false} tickMargin={8} />
<YAxis tickLine={false} axisLine={false} width={44} />
<ChartTooltip cursor={false} content={<ChartTooltipContent indicator="line" />} />
<ChartLegend itemSorter={(item) => series.findIndex((s) => s.key === item.dataKey)} content={<ChartLegendContent />} />
{series.map((s, i) => (
<Line
key={s.key}
dataKey={s.key}
type="monotone"
stroke={`var(--color-${s.key})`}
strokeWidth={2}
strokeDasharray={seriesDash(i)}
dot={{ r: 2.5, fill: `var(--color-${s.key})`, strokeWidth: 0 }}
activeDot={{ r: 4 }}
isAnimationActive={false}
/>
))}
</LineChart>
</ChartContainer>
</ChartFigure>
)
}