React Sparklines Component

1.7.0 · maintenance · verified Tue Apr 21

react-sparklines is a lightweight React component library designed for rendering small, expressive sparkline charts using SVG. It offers a declarative API to create various types of micro-charts, including lines, bars, and spots, along with statistical overlays like reference lines for mean, median, and normal bands. The current stable version is 1.7.0, with its last publication dating back several years, suggesting the library is in a maintenance phase rather than active development. Its primary appeal lies in providing simple, customizable visualizations for dashboards or other data-dense user interfaces where the emphasis is on quickly conveying trends without the complexity and overhead of full-featured charting libraries. It distinguishes itself by focusing purely on compact, trend-oriented data representations.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic line sparkline and a more complex one with spots and a mean reference line.

import React from 'react';
import ReactDOM from 'react-dom';
import { Sparklines, SparklinesLine, SparklinesSpots, SparklinesReferenceLine } from 'react-sparklines';

const sampleData = [5, 10, 5, 20, 8, 15, 25, 12, 18, 7, 30, 22];

function App() {
  return (
    <div>
      <h2>Basic Sparkline</h2>
      <Sparklines data={[5, 10, 5, 20]} width={100} height={20} margin={5}>
        <SparklinesLine color="blue" />
      </Sparklines>

      <h2>Sparkline with Spots and Reference Line</h2>
      <Sparklines data={sampleData} width={120} height={30} margin={5}>
        <SparklinesLine style={{ fill: 'none', strokeWidth: 2 }} />
        <SparklinesSpots size={2} style={{ fill: '#ff7f0e' }} />
        <SparklinesReferenceLine type="mean" style={{ stroke: 'red', strokeDasharray: '2,2' }} />
      </Sparklines>
    </div>
  );
}

ReactDOM.render(<App />, document.getElementById('root'));

view raw JSON →