# Network Chart

Network chart for relations: a force graph, an arc diagram, a tree and a radial tree.

- Category: Charts
- Page: https://wunderui.com/components/network-chart
- Tier: Core and Pro

## Install

Network Chart ships with WunderUI Core and Pro in the @wunderui/react package.

## Import

```tsx
import { NetworkChart, NetworkChartProps, NetworkChartVariant } from "@wunderui/react"
```

## Minimal usage

Then use it:

```tsx
import { NetworkChart } from "@wunderui/react/charts"

const nodes = [{ id: "Nora" }, { id: "Daniel" }, { id: "Priya" }]
const links = [
  { source: "Nora", target: "Daniel" },
  { source: "Nora", target: "Priya" },
]

export function TeamNetwork() {
  return <NetworkChart nodes={nodes} links={links} label="Who works with whom" />
}
```

Expected result: You see three nodes, with Nora joined to both of the others.

## When to use

### Use Network Chart for

- Relations between things: who works with whom, which service calls which
- A force graph for clusters, an arc diagram for ordered nodes
- An organisation or a folder structure as a tree or a radial tree

### Use something else

- [Sankey Chart](https://wunderui.com/components/sankey-chart) for flows with quantities between stages
- [Treemap](https://wunderui.com/components/treemap) for parts of a hierarchy by size
- [Sunburst](https://wunderui.com/components/sunburst) for a hierarchy as rings
- [Timeline Chart](https://wunderui.com/components/timeline-chart) for items on a time scale

## Keyboard

The plot is focusable: arrow keys step through the nodes in data order and the live region reads each node with its connections by name. A hidden data table adds a Connected to column.

| Key | Action |
|---|---|
| `Tab` or `Shift+Tab` | Moves focus to the plot and away from it. The plot is one tab stop; so is every legend badge. |
| `ArrowRight` or `ArrowLeft` | Moves to the next or previous node. The tooltip follows, and a live region announces the one you are on. The first press starts at the first one (Left: the last one). |
| `Home` or `End` | Jumps to the first or last node. |
| `Escape` | Clears the active point. |
| `Enter` or `Space` | On a legend badge of a ChartCard: switches its series off or on. The last visible series stays on. |

## Behavior

What the chart does on its own and what the page decides.

- **Graphs and trees:** Graph variants take nodes (id, label, group, size) and links (source, target, value), and tree variants take a hierarchy of names and children. Groups set colours and legend order.
- **Layout:** The force layout is calculated once per data set and fitted to the frame, so nodes do not jump on resize. Nodes are sized by size, or by their number of links.
- **Labels:** Names stand beside the nodes, shortened to fit. Dense graphs show the labels of the hovered node and its neighbours.
- **Tooltip:** The tooltip never covers the hovered node or its name: it sits beside them (right, or left near the edge), and moves above or below them when neither side has room.
- **Bad links:** Links to unknown nodes and self loops are ignored.
- **Loading, empty and error:** The chart keeps its size while it loads, is empty or fails, so the card never jumps. Add a retry handler to show a Try again button.
- **Legend:** A ChartCard shows the series as badges. With two or more series each badge switches its series off (the last visible one stays on), and a static legend is possible for roles instead of series.
- **Size:** The chart fills its container's width and the height prop sets the plot height. It never scales its text: labels keep their size at every width.

## Motion

The enter sequence and the hover follow the motion tokens of the library.

- **Edges, then nodes:** Force graph: the edges draw out of their source and the nodes land on them. Trees: the lines draw level by level and each node arrives as its line lands. Arc diagram: the row of nodes comes first and the arcs rise from it. It plays when the chart is first in view, after loading and when the data changes, not on a parent re-render with the same data. Turn it off with the animate prop.
- **Hover:** Hovering a node keeps it and its neighbours (in a tree: its line to the root and its reports) and dims the rest to --chart-dim, with a short opacity transition.
- **Reduced motion:** With reduced motion the enter sequence is off and the chart appears at once. The tooltip, the hover dimming and every state still work.

## Anatomy

- `NetworkChart`: Takes nodes (id, label, group, size) and links (source, target, value) for the graph variants, or a tree of name and children for the tree variants. Groups set colours and legend order.
- `Plot`: The focusable region. Arrow keys walk its marks and the live region reads each one as the tooltip shows it.
- `Marks`: Nodes sized by size (or degree) and links between them. The force layout is calculated once per data set and fitted to the frame, so nodes do not jump on resize.
- `Node labels`: Names beside each node, shortened to fit. Dense graphs show labels for the hovered node and its neighbours.
- `Tooltip`: The group and the number of links (reports, on the tree variants).
- `Loading, empty and error`: Muted dots on the force graph, muted bars on the tree and arc variants. Links to unknown nodes and self loops are ignored.
- `Data table and live region`: A table of the nodes with group and degree for screen readers.

## Best practices

### When to use

- Use NetworkChart to show structure: who is connected to whom, or how a hierarchy branches. Use SankeyChart when quantities flow between nodes.

### Do

- Keep a force graph below about 60 nodes and use size for importance. Above that, filter or aggregate first.
- Use a tree for strict hierarchies such as an org chart or file structure, and the arc diagram for ordered nodes with many links.
- Colour by group and keep to five groups, with the names in the legend.

### Don't

- Don't read distance in a force graph as a measurement. The layout places connected nodes close, but position has no axis.
- Don't use it for tabular data. If the question is a value per item, a BarChart answers it faster.

## API reference

### NetworkChart

| Prop | Type | Default | Description |
|---|---|---|---|
| activeIndex | number \| null |  | The active point (hovered or focused) as an index into `data`, to control it yourself. `null` shows none. |
| animate | boolean |  |  |
| animationKey | string \| number |  |  |
| className | string |  | Extra classes for the root element of the chart. |
| defaultActiveIndex | number \| null |  | The point that is active at first, for an uncontrolled chart. It shows the tooltip without a pointer. |
| description | string |  |  |
| groups | readonly { key: string; label?: string; color?: ChartColor }[] |  | Groups in legend order with colours. |
| height | number |  |  |
| hiddenSeries | readonly string[] |  |  |
| label | string |  |  |
| links | readonly NetworkLink[] | NO_LINKS |  |
| nodes | readonly NetworkNode[] | NO_NODES | `force-graph`, `arc-diagram`: the nodes and their links. |
| onActiveIndexChange | (index: number \| null) => void |  | Called with the index when the pointer or the arrow keys move to another point, and with `null` when they leave. Use it to show the hovered value in a headline. |
| onRetry | () => void |  | Shows a Try again button in the error state and calls this when it is pressed. |
| state | "ready" \| "loading" \| "empty" \| "error" |  |  |
| tree | TreeDatum |  | `tree`, `radial-tree`: the hierarchy. |
| variant | "force-graph" \| "arc-diagram" \| "tree" \| "radial-tree" | "force-graph" | Figma variant. Default `force-graph`. |
| width | number |  |  |

## Examples

### States

## In context

### Reporting Lines

An organisation chart as a tree.

## For AI agents

`get_component("network-chart")`

Hand your agent this page as Markdown or the WunderUI MCP server, not a screenshot.
