{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"line-charts-multi-series","type":"registry:component","title":"Line charts · Multi-series","description":"Up to four series, volt first and the rest neutral or dashed; legend toggles rescale the axis with a spring morph and the crosshair reads every visible line.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/geturui/examples/line-charts/multi-series.tsx","type":"registry:component","target":"components/examples/line-charts/multi-series.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useInView, useReducedMotion } from \"motion/react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface LineSeries {\n  id: string;\n  label: string;\n  /** One value per label, oldest first. */\n  values: number[];\n}\n\nexport interface MultiSeriesLineChartProps {\n  title?: string;\n  subtitle?: string;\n  /** X-axis labels, one per point. */\n  labels?: string[];\n  /** First series is the primary (volt); the rest render in neutral tones. */\n  series?: LineSeries[];\n  formatValue?: (n: number) => string;\n  /** Formats the y-axis ticks. */\n  formatTick?: (n: number) => string;\n  className?: string;\n}\n\nconst LABELS = [\"Apr\", \"May\", \"Jun\", \"Jul\", \"Aug\", \"Sep\", \"Oct\", \"Nov\", \"Dec\", \"Jan\", \"Feb\", \"Mar\"];\nconst SERIES: LineSeries[] = [\n  { id: \"web\", label: \"Web app\", values: [18.2, 19.4, 21.1, 20.6, 22.8, 24.9, 26.3, 25.8, 28.4, 30.1, 31.7, 34.2] },\n  { id: \"ios\", label: \"iOS\", values: [9.1, 9.8, 10.4, 11.9, 12.2, 13.6, 14.1, 15.8, 16.3, 17.9, 18.4, 19.6] },\n  { id: \"android\", label: \"Android\", values: [6.4, 6.9, 7.2, 7.1, 8.0, 8.6, 9.3, 9.1, 10.2, 10.8, 11.6, 12.1] },\n];\nconst STYLES = [\n  { stroke: \"var(--volt-ink)\", width: 2.25, dash: undefined },\n  { stroke: \"var(--ink-muted)\", width: 1.75, dash: undefined },\n  { stroke: \"var(--ink-subtle)\", width: 1.75, dash: \"5 4\" },\n  { stroke: \"var(--ink-subtle)\", width: 1.5, dash: \"1.5 3.5\" },\n];\n\nfunction niceTicks(max: number, count = 4) {\n  const raw = Math.max(max, 1e-6) / count;\n  const mag = 10 ** Math.floor(Math.log10(raw));\n  const step = [1, 2, 2.5, 5, 10].map((m) => m * mag).find((s) => s >= raw) ?? raw;\n  return Array.from({ length: count + 1 }, (_, i) => i * step);\n}\n\nfunction smooth(pts: [number, number][]) {\n  const f = (n: number) => n.toFixed(2);\n  return pts\n    .map((p, i) => {\n      if (i === 0) return `M${f(p[0])},${f(p[1])}`;\n      const a = pts[i - 2] ?? pts[i - 1];\n      const b = pts[i - 1];\n      const c = pts[i + 1] ?? p;\n      return `C${f(b[0] + (p[0] - a[0]) / 6)},${f(b[1] + (p[1] - a[1]) / 6)} ${f(p[0] - (c[0] - b[0]) / 6)},${f(p[1] - (c[1] - b[1]) / 6)} ${f(p[0])},${f(p[1])}`;\n    })\n    .join(\"\");\n}\n\n/** Multi-series line chart: legend toggles rescale the axis with a spring morph, and a crosshair reads every visible series on hover or arrow keys. */\nexport function MultiSeriesLineChart({\n  title = \"Weekly active users\",\n  subtitle = \"By platform, in thousands\",\n  labels = LABELS,\n  series = SERIES,\n  formatValue = (n) => `${n.toFixed(1)}k`,\n  formatTick = (n) => (n ? `${n}k` : \"0\"),\n  className,\n}: MultiSeriesLineChartProps) {\n  const reduce = useReducedMotion() ?? false;\n  const ref = React.useRef<HTMLDivElement>(null);\n  const inView = useInView(ref, { once: true, margin: \"-40px\" });\n  const uid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const [hidden, setHidden] = React.useState<Set<string>>(new Set());\n  const [active, setActive] = React.useState<number | null>(null);\n\n  const n = labels.length;\n  const visible = series.filter((s) => !hidden.has(s.id));\n  const ticks = niceTicks(Math.max(...visible.flatMap((s) => s.values), 0));\n  const top = ticks[ticks.length - 1] || 1;\n  const xp = (i: number) => (n > 1 ? (i / (n - 1)) * 100 : 50);\n  const yp = (v: number) => (1 - v / top) * 100;\n  const spring = reduce ? { duration: 0 } : { type: \"spring\" as const, stiffness: 200, damping: 30 };\n\n  const toggle = (id: string) =>\n    setHidden((prev) => {\n      const next = new Set(prev);\n      if (next.has(id)) next.delete(id);\n      else if (series.length - next.size > 1) next.add(id);\n      return next;\n    });\n\n  function onMove(e: React.PointerEvent<HTMLDivElement>) {\n    const r = e.currentTarget.getBoundingClientRect();\n    setActive(Math.max(0, Math.min(n - 1, Math.round(((e.clientX - r.left) / r.width) * (n - 1)))));\n  }\n  function onKey(e: React.KeyboardEvent) {\n    const map: Record<string, number> = { ArrowLeft: -1, ArrowRight: 1 };\n    if (e.key in map) {\n      e.preventDefault();\n      setActive((a) => Math.max(0, Math.min(n - 1, (a ?? n - 1) + map[e.key])));\n    } else if (e.key === \"Home\" || e.key === \"End\") {\n      e.preventDefault();\n      setActive(e.key === \"Home\" ? 0 : n - 1);\n    } else if (e.key === \"Escape\") setActive(null);\n  }\n\n  const summary = `${title}. ${series.map((s) => `${s.label} from ${formatValue(s.values[0] ?? 0)} to ${formatValue(s.values[n - 1] ?? 0)}`).join(\"; \")}.`;\n\n  return (\n    <figure className={cn(\"@container w-full rounded-xl border border-border bg-surface-raised p-4 shadow-sm sm:p-5\", className)}>\n      <div className=\"flex flex-wrap items-start justify-between gap-3\">\n        <figcaption>\n          <p className=\"text-[15px] font-semibold text-ink\">{title}</p>\n          <p className=\"text-[12.5px] text-ink-subtle\">{subtitle}</p>\n        </figcaption>\n        <ul className=\"flex flex-wrap gap-1.5\" aria-label=\"Toggle series\">\n          {series.map((s, i) => {\n            const on = !hidden.has(s.id);\n            const st = STYLES[i % STYLES.length];\n            return (\n              <li key={s.id}>\n                <motion.button\n                  type=\"button\"\n                  whileTap={{ scale: 0.96 }}\n                  aria-pressed={on}\n                  onClick={() => toggle(s.id)}\n                  className={cn(\n                    \"inline-flex h-7 items-center gap-1.5 rounded-full border px-2.5 text-[12px] font-medium outline-none transition-colors focus-visible:shadow-[var(--focus-ring)]\",\n                    on ? \"border-border-strong/40 bg-surface text-ink\" : \"border-dashed border-border text-ink-subtle\",\n                  )}\n                >\n                  <svg aria-hidden width=\"14\" height=\"4\" className=\"overflow-visible\">\n                    <line x1=\"0\" x2=\"14\" y1=\"2\" y2=\"2\" style={{ stroke: st.stroke, opacity: on ? 1 : 0.35 }} strokeWidth={2.5} strokeDasharray={st.dash} strokeLinecap=\"round\" />\n                  </svg>\n                  {s.label}\n                </motion.button>\n              </li>\n            );\n          })}\n        </ul>\n      </div>\n\n      <div className=\"mt-5 grid grid-cols-[2.25rem_minmax(0,1fr)] gap-x-2\">\n        <div aria-hidden className=\"relative h-52 @md:h-60\">\n          {ticks.map((t) => (\n            <motion.span key={t} layout=\"position\" className=\"absolute right-0 -translate-y-1/2 font-mono text-[10.5px] tabular-nums text-ink-subtle\" style={{ top: `${yp(t)}%` }}>\n              {formatTick(t)}\n            </motion.span>\n          ))}\n        </div>\n        <div\n          ref={ref}\n          tabIndex={0}\n          role=\"group\"\n          aria-label={`${title} chart. Use left and right arrow keys to read each month.`}\n          onPointerMove={onMove}\n          onPointerLeave={() => setActive(null)}\n          onFocus={() => setActive((a) => a ?? n - 1)}\n          onBlur={() => setActive(null)}\n          onKeyDown={onKey}\n          className=\"relative h-52 touch-none rounded-xs outline-none focus-visible:shadow-[var(--focus-ring)] @md:h-60\"\n        >\n          <svg role=\"img\" aria-label={summary} viewBox=\"0 0 100 100\" preserveAspectRatio=\"none\" className=\"absolute inset-0 size-full overflow-visible\">\n            <defs>\n              <clipPath id={`${uid}-reveal`}>\n                <motion.rect x={-2} y={-10} height={120} initial={{ width: reduce ? 104 : 0 }} animate={{ width: inView ? 104 : reduce ? 104 : 0 }} transition={{ duration: reduce ? 0 : 1.2, ease: [0.65, 0, 0.35, 1] }} />\n              </clipPath>\n            </defs>\n            {ticks.map((t, i) => (\n              <motion.line key={t} initial={false} animate={{ y1: yp(t), y2: yp(t) }} transition={spring} x1={0} x2={100} className=\"stroke-border\" strokeDasharray={i === 0 ? undefined : \"2 4\"} vectorEffect=\"non-scaling-stroke\" />\n            ))}\n            <g clipPath={`url(#${uid}-reveal)`}>\n              {series.map((s, i) => {\n                const st = STYLES[i % STYLES.length];\n                const d = smooth(s.values.map((v, k) => [xp(k), yp(v)]));\n                return (\n                  <motion.path\n                    key={s.id}\n                    initial={false}\n                    animate={{ d, opacity: hidden.has(s.id) ? 0 : 1 }}\n                    transition={{ d: spring, opacity: { duration: 0.2 } }}\n                    fill=\"none\"\n                    style={{ stroke: st.stroke }}\n                    strokeWidth={st.width}\n                    strokeDasharray={st.dash}\n                    strokeLinecap=\"round\"\n                    vectorEffect=\"non-scaling-stroke\"\n                  />\n                );\n              })}\n            </g>\n            {active !== null && <line x1={xp(active)} x2={xp(active)} y1={0} y2={100} className=\"stroke-ink-subtle\" strokeDasharray=\"3 3\" vectorEffect=\"non-scaling-stroke\" />}\n          </svg>\n\n          {active !== null &&\n            series.map((s, i) =>\n              hidden.has(s.id) ? null : (\n                <motion.span\n                  key={s.id}\n                  aria-hidden\n                  initial={false}\n                  animate={{ left: `${xp(active)}%`, top: `${yp(s.values[active] ?? 0)}%` }}\n                  transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 38 }}\n                  className=\"pointer-events-none absolute size-2.5 -translate-x-1/2 -translate-y-1/2 rounded-full border-2 border-surface-raised\"\n                  style={{ background: STYLES[i % STYLES.length].stroke }}\n                />\n              ),\n            )}\n\n          <AnimatePresence>\n            {active !== null && (\n              <motion.div\n                key=\"tip\"\n                aria-hidden\n                initial={{ opacity: 0, scale: 0.96, left: `${xp(active)}%` }}\n                animate={{ opacity: 1, scale: 1, left: `${xp(active)}%` }}\n                exit={{ opacity: 0, transition: { duration: 0.1 } }}\n                transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 480, damping: 36 }}\n                style={{ x: xp(active) > 55 ? \"calc(-100% - 12px)\" : \"12px\" }}\n                className=\"pointer-events-none absolute top-1 z-10 min-w-36 rounded-sm border border-border bg-surface-raised px-2.5 py-2 text-xs shadow-md\"\n              >\n                <p className=\"mb-1 font-medium text-ink-muted\">{labels[active]}</p>\n                {series.map((s, i) =>\n                  hidden.has(s.id) ? null : (\n                    <p key={s.id} className=\"flex items-center justify-between gap-4\">\n                      <span className=\"flex items-center gap-1.5 text-ink-muted\">\n                        <span className=\"size-1.5 rounded-full\" style={{ background: STYLES[i % STYLES.length].stroke }} />\n                        {s.label}\n                      </span>\n                      <span className=\"font-mono font-semibold tabular-nums text-ink\">{formatValue(s.values[active] ?? 0)}</span>\n                    </p>\n                  ),\n                )}\n              </motion.div>\n            )}\n          </AnimatePresence>\n        </div>\n        <div />\n        <div aria-hidden className=\"relative mt-2 h-4\">\n          {labels.map((l, i) => (\n            <span\n              key={l + i}\n              className={cn(\"absolute font-mono text-[10.5px] text-ink-subtle\", i === 0 ? \"\" : i === n - 1 ? \"-translate-x-full\" : \"-translate-x-1/2\", (i % 2 === 1 || i === n - 2) && i !== n - 1 && \"hidden @md:block\")}\n              style={{ left: `${xp(i)}%` }}\n            >\n              {l}\n            </span>\n          ))}\n        </div>\n      </div>\n      <p className=\"sr-only\" aria-live=\"polite\">\n        {active !== null ? `${labels[active]}: ${visible.map((s) => `${s.label} ${formatValue(s.values[active] ?? 0)}`).join(\", \")}` : \"\"}\n      </p>\n    </figure>\n  );\n}\n"},{"path":"LICENSE-geturui.md","type":"registry:file","target":"LICENSE-geturui.md","content":"MIT License\n\nCopyright (c) 2026 geturui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"}],"categories":["examples","chart","line chart","time series","comparison","annotations","tooltip","crosshair","svg"],"meta":{"tier":"free","license":"MIT","docs":"https://geturui.com/docs/line-charts#multi-series"}}