Skip to content

Network graph ​

Nodes spread by forces, and their links. Good for who is linked to whom.

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

In your framework

import { Chart } from 'nervure/react';

const spec = {
  type: 'network',
  nodes: [
    { id: 'n0', label: 'Tunis', value: 33, group: 'North' },
    { id: 'n1', label: 'Sfax', value: 26, group: 'South' },
    { id: 'n2', label: 'Sousse', value: 13, group: 'East' },
    { id: 'n3', label: 'Bizerte', value: 31, group: 'North' },
    { id: 'n4', label: 'Gabes', value: 11, group: 'South' },
    { id: 'n5', label: 'Kairouan', value: 10, group: 'East' },
    { id: 'n6', label: 'Tozeur', value: 38, group: 'North' },
    { id: 'n7', label: 'Nabeul', value: 34, group: 'South' },
    { id: 'n8', label: 'Mahdia', value: 16, group: 'East' },
    { id: 'n9', label: 'Djerba', value: 17, group: 'North' },
    { id: 'n10', label: 'Bread', value: 15, group: 'South' },
    { id: 'n11', label: 'Fruit', value: 15, group: 'East' },
    { id: 'n12', label: 'Cheese', value: 57, group: 'North' },
    { id: 'n13', label: 'Coffee', value: 5, group: 'South' },
    { id: 'n14', label: 'Tea', value: 39, group: 'East' },
    { id: 'n15', label: 'Juice', value: 4, group: 'North' },
    { id: 'n16', label: 'Nuts', value: 27, group: 'South' },
    { id: 'n17', label: 'Honey', value: 17, group: 'East' },
  ],
  links: [
    { source: 'n1', target: 'n0' },
    { source: 'n1', target: 'n12' },
    { source: 'n2', target: 'n0' },
    { source: 'n3', target: 'n1' },
    { source: 'n4', target: 'n2' },
    { source: 'n5', target: 'n2' },
    { source: 'n5', target: 'n14' },
    { source: 'n6', target: 'n1' },
    { source: 'n7', target: 'n2' },
    { source: 'n8', target: 'n4' },
    { source: 'n9', target: 'n7' },
    { source: 'n9', target: 'n4' },
    { source: 'n10', target: 'n5' },
    { source: 'n11', target: 'n3' },
    { source: 'n12', target: 'n1' },
    { source: 'n13', target: 'n9' },
    { source: 'n13', target: 'n5' },
    { source: 'n14', target: 'n6' },
    { source: 'n15', target: 'n13' },
    { source: 'n16', target: 'n13' },
    { source: 'n17', target: 'n5' },
    { source: 'n17', target: 'n2' },
  ],
};

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

interface NetworkSpec extends Base {
  type: 'network';
  nodes: { id: string; label?: string; value?: number; group?: string; color?: string }[];
  links: { source: string; target: string; value?: number }[];
  onNodeClick?: (id: string) => void;
}

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