Skip to content

Range bar chart ​

A floating bar from the lowest to the highest value, with a mark for today. Good for temperatures, prices and salaries: a span and where we stand in it.

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

In your framework

import { Chart } from 'nervure/react';

const spec = {
  type: 'range',
  valueName: 'Today',
  data: [
    { name: 'Kairouan', min: -1, max: 10, value: 9 },
    { name: 'Gabes', min: -4, max: 13, value: -4 },
    { name: 'Sousse', min: 3, max: 14, value: 6 },
    { name: 'Mahdia', min: 8, max: 16, value: 11 },
    { name: 'Djerba', min: 5, max: 19, value: 17 },
    { name: 'Sfax', min: -1, max: 12, value: 6 },
  ],
  format: { unit: '°C' },
};

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 range takes:

/** A bar from the lowest to the highest value of each row. */
interface RangeSpec extends Base {
  type: 'range';
  data: { name: string; min: number; max: number; /** The mark: today's figure. */ value?: number; color?: string }[];
  color?: string;
  /** Name of the mark, 'Now' by default. */
  valueName?: string;
}

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