Skip to content

Nested bar chart ​

A narrow bar for the result inside a wide one for the target. Good for actual against plan, month by month.

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

In your framework

import { Chart } from 'nervure/react';

const spec = {
  type: 'nested',
  valueName: 'Sales',
  targetName: 'Target',
  data: [
    { name: 'Jan', value: 71, target: 80 },
    { name: 'Feb', value: 50, target: 82 },
    { name: 'Mar', value: 47, target: 73 },
    { name: 'Apr', value: 77, target: 83 },
    { name: 'May', value: 53, target: 76 },
    { name: 'Jun', value: 52, target: 75 },
  ],
};

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

/** A wide light bar for the target, a narrow one inside for the result. */
interface NestedSpec extends Base {
  type: 'nested';
  data: { name: string; value: number; target: number }[];
  valueName?: string;
  targetName?: string;
  color?: string;
  horizontal?: boolean;
}

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