Skip to content
Stylhero 0.8.0
Components

Core

Layout and type

Inputs

Overlays

Navigation

Data display

Charts

Transitions and utilities

Page pieces (landing pages, portfolios, docs)

Icons

Components / Charts

LineChart

Change over time (MUI X's LineChart). Hover anywhere for a crosshair with every series' value.

import { LineChart } from "@stylhero/ui";

Example

Code
import { LineChart } from "@stylhero/ui";

const months = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"];

function LineChartExample() {
  return <LineChart title="Average price" labels={months} valueFormat={(v) => `$${v}`} curved area
    series={[{ name: "Average", data: [1180, 1150, 1120, 1135, 1100, 1090] }]} />;
}

Props

PropTypeDefaultDescription
labels required string[] - X-axis categories, e.g. ["Mon", "Tue", ...].
series required ChartSeries[] - Up to 8 series. More than that should be grouped into "Other" before charting.
area boolean - Fills under each line with a light wash (MUI's area chart).
curved boolean - Smooth curves instead of straight segments.
description string -
height number 260
subtitle ReactNode -
title ReactNode -
valueFormat Fmt defaultFmt

Also takes the HTML attributes of its root element (id, style, data-*, aria-*, event handlers…).

Types

type ChartSeries = { name: string; data: number[] };

type Fmt = (n: number) => string;

Accessibility

  • role="img" labelled by description (else the title). The "Show as table" button switches to a data table with the same numbers.

Generated from src/components/Charts.tsx. Something wrong or missing? Open an issue.