Skip to content

Sparkline ​

A line without axes, as small as a word. Good for a trend inside a table or beside a figure.

The smallest code that works. change the code, then press Run

In your framework

import { Chart } from 'nervure/react';

const spec = {
  type: 'xy',
  bare: true,
  categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  series: [
    {
      name: 'Trend',
      kind: 'area',
      data: [40.8, 39.8, 35.7, 35.9, 31.1, 26.3, 28.4, 29.4, 25.9, 22.8, 19.2, 15.6],
      curve: 'smooth',
      dots: false,
    },
  ],
};

export default function Example() {
  return <Chart spec={spec} style={{ height: 340 }} />;
}

Or import this chart alone: what each import weighs.

Options

Beside the fields shared by every chart (title, format, heading, export…), type xy takes:

interface XYSpec extends Base {
  type: 'xy';
  /** Names, or dates: Date objects, ISO texts (`2024-03-01`), or timestamps with `xScale: 'time'`. */
  categories: (string | number | Date)[];
  /**
   * `time`: categories are dates, placed by time (uneven gaps drawn to scale), with ticks by span.
   * Chosen alone when every category is a Date or an ISO date; `category` keeps them evenly spaced.
   */
  xScale?: 'category' | 'time';
  series: Series[];
  axes?: Axis[];
  horizontal?: boolean;
  /** `percent`: each category fills the axis, its bars as shares of 100 %. Series with a `stack` pile up by group. */
  stacked?: boolean | 'percent';
  /** Rounded corners of the bars, in pixels: 4 by default, 0 for square bars. */
  radius?: number;
  /** Share of a category taken by its bars, from 0 to 1: 0.72 by default. */
  barWidth?: number;
  /** Horizontal bars: first category at the top (default) or at the bottom. */
  reverse?: boolean;
  totals?: boolean;
  legend?: boolean | LegendOptions;
  labelWidth?: number;
  grid?: boolean | 'dashed';
  /** Title under the horizontal axis. */
  xTitle?: string;
  /** Angle of the category labels (vertical charts), for example -45. */
  labelAngle?: number;
  lines?: ReferenceLine[];
  annotations?: Annotation[];
  /** Shaded zones behind the series: a period, a forecast, a range of values. */
  zones?: Zone[];
  /** Drag on the chart to look closer, double click to come back (vertical charts). */
  zoom?: boolean;
  /** No axis, no legend, no margin: a sparkline. */
  bare?: boolean;
  /**
   * Long series: keeps the lowest and highest points of each stretch, so peaks stay.
   * `true`: about one point every 3 pixels; a number: the most points kept. Zooming in brings the detail back.
   */
  thin?: boolean | number;
}

interface Series {
  name: string;

interface Axis extends AxisScale {
  side?: 'left' | 'right';

/** A line across the chart: a target, an average, a date. */
interface ReferenceLine {
  value?: number;

/** A note pinned on the chart. `at` is a category (xy) or an x value (scatter). */
interface Annotation {
  at: string | number | Date;

/** A shaded zone: a stretch of categories (`from`, `to`), or a range of values (`min`, `max`). */
interface Zone {
  /** A category, or a date on a time axis. */
  from?: string | number | Date;

Style it

  • Colours: theme.palette, chart.setColor(name, colour), or --nervure-palette in your CSS. More
  • Marks: [data-series="name"], parts: [data-part="axes"], legend, series. What you change is kept in exports.
  • Movement: animation: false draws at once. More
  • Files: chart.download('png'), svg, csv. More

Close to it