Network Graph
What is a network graph?
A network graph (also called a network diagram, network chart, node-link diagram or graph visualisation) is a chart that shows how things are connected. Each thing is a dot called a node, and each connection is a line called an edge or link. It reveals groups, central players and the links between groups.

A network graph of who works with whom in an imaginary company of 60 people (sample data). Colour shows each person's team; dot size shows how many connections they have. Try the interactive version.
- A network graph shows connections: nodes are the items, edges are the links between them.
- Look for three things: hubs (nodes with many links), clusters (groups linked mostly to each other) and bridges (the few links that join groups).
- In a force-directed graph, the most common kind, a node's position has no units. Only which nodes are close, and what's linked to what, means something.
- Use colour for a group and size for a measure such as the number of connections, and say what each one means.
- Above a few hundred nodes, a network graph turns into a tangle. Filter, group or zoom rather than drawing everything.
How to read a network graph
- Find out what the nodes and edges are. A node might be a person, an airport, a web page or a gene. An edge might mean "emailed", "flies to", "links to" or "interacts with".
- Check what colour, size and line thickness mean. Colour usually shows a group, such as a team or a type of item. Node size often shows the number of connections. A thicker edge usually means a stronger or more frequent link (a weighted edge). An arrow on an edge means the link has a direction (a directed graph), such as "follows" or "cites".
- Look for clusters. A cluster (or community) is a group of nodes with many links among themselves and few to the rest. On most layouts they show up as tight knots of dots.
- Find the hubs. A hub is a node with many more connections than most. The number of connections a node has is its degree.
- Find the bridges. A bridge is a node or edge that joins two clusters. Remove it and the groups lose touch, so bridges often matter more than their number of connections suggests.
- Check the edges of the chart. Nodes with one link sit on the outside, and an isolate, a node with no links at all, floats on its own.
- Don't read the x and y positions as values. In a force-directed layout there are no axes. Linked nodes are drawn close together, but a node on the left is not "less" than one on the right.
Patterns to look for in a network graph
The same few shapes turn up again and again, whatever the network is about:
| Pattern | What it looks like | What it usually means |
|---|---|---|
| Hub and spoke | One large node with lines to many small ones | Everything goes through one person, server or airport: efficient, but a single point of failure |
| Clusters | Tight knots of nodes with only a few lines between them | Teams, friend groups, topics or modules that mostly keep to themselves |
| Bridge | One node or edge that is the main route between two clusters | A broker or go-between. If it goes, the groups lose touch |
| Chain | Nodes in a line, each linked only to the next | Long paths: information or traffic takes many steps, and one broken link splits the network |
| Core and periphery | A dense centre with loosely attached nodes around it | An inner group that does most of the work, with occasional contributors on the outside |
| Isolate | A node with no lines | Someone or something not yet connected: a new starter, an unused page, an error in the data |
Network graph measures: degree, betweenness and density
Patterns you see by eye have numbers behind them. These are the ones most often used to size or colour nodes:
| Measure | What it counts | What a high value suggests |
|---|---|---|
| Degree | The number of edges a node has | A hub: well connected, often busy |
| Betweenness centrality | How often a node sits on the shortest route between two other nodes | A bridge or broker that controls the flow between groups |
| Closeness centrality | How few steps a node needs, on average, to reach every other node | A node that can reach the whole network quickly |
| Density | The share of all possible edges that exist | A tightly knit network; low density means a sparse one |
| Path length | The number of edges on the shortest route between two nodes | How many steps information takes to spread |
A worked example: who works with whom
The network graph at the top of this page shows an imaginary company of 60 people in four teams of 15. An edge joins two people who work together regularly. The data is made up but has the shape real organisations often have: each team has a lead, and a few people work across teams.
- 60 nodes and 127 edges. Of the 1,770 possible pairs of people, 127 work together, a density of about 7%.
- The average person has about 4 connections. The team leads have 11 to 14.
- Only 8 of the 127 edges cross between teams. That is why the four teams form four clear clusters.
- Any two connected people are 3.5 steps apart on average, and never more than 7.
- Jon has no connections. He has just joined Support, so he is an isolate.
The table compares five people by degree and by betweenness, shown here as the share of shortest routes between other pairs of people that pass through them:
| Person | Team | Connections (degree) | Shortest routes through them (betweenness) |
|---|---|---|---|
| Grace | Sales (lead) | 14 | 47% |
| Tom | Engineering | 5 | 44% |
| Chloe | Marketing (lead) | 11 | 35% |
| Priya | Engineering (lead) | 13 | 29% |
| Marco | Support (lead) | 12 | 27% |
Priya has the second-highest number of connections, but every one of them is inside Engineering. Tom has only five connections, yet 44% of shortest routes run through him, because three of his five links go to other teams. On the chart Tom is the small blue dot in the middle, with lines out to Sales, Marketing and Support. A count of connections finds the hubs; betweenness finds the bridges. Hover over Tom in the live example below to see it.
How to describe a network graph
Use this template when you report a network graph:
The network has [number] [nodes] and [number] [links]. They form [number] main clusters, which match [groups, or what they have in common]. The most connected node is [name], with [degree] links, and [name] is the main bridge between [cluster] and [cluster].
Worked example: "The company network has 60 people and 127 working relationships. They form four clusters, one for each team, joined by only eight cross-team links. Grace, the Sales lead, has the most connections (14), and Tom in Engineering is the main bridge from Engineering to the other three teams."
How a force-directed graph layout works
A network has no natural x and y, so a layout method has to place the nodes. The most common is the force-directed layout, which treats the network as a set of physical objects. A network drawn this way is called a force-directed graph, or a force graph for short. The layout takes five steps:
- Start anywhere. Each node gets a starting position, often random. A fixed random seed makes the result the same every time.
- Every pair of nodes pushes apart, like magnets of the same pole. The push is strongest when they are close, so nodes don't overlap.
- Every edge pulls its two nodes together, like a spring. The further apart they are, the harder it pulls.
- Move each node a little in the direction of its total force, then repeat. Each round, nodes are allowed to move a bit less (called cooling), so the layout settles instead of shaking forever.
- Stop when nothing moves much. Linked nodes are now close, groups with many links between them form clusters, and nodes with few links drift to the outside.
The Fruchterman–Reingold method (1991) is a well-known version of these steps, and it's what the live example on this page uses, with a weak pull towards the centre so that separate pieces stay in view. This has two consequences for reading the result:
- Distances are only roughly meaningful. Close nodes are usually linked, or share neighbours. The exact distance between two nodes is not a measurement.
- The picture can change from run to run. A different start can mirror, rotate or rearrange the layout. The clusters and links stay the same, so read those, not the positions.
Every pair of nodes pushes on every other, so each round takes longer as the network grows. Libraries for very large networks speed this up by treating distant groups of nodes as one.
Other layouts suit other data:
| Layout | Nodes placed by | Best for |
|---|---|---|
| Force-directed | A simulation of pushing and pulling | Finding clusters and bridges in general networks |
| Circular | Equal spacing round a circle, often sorted by group | Comparing links within and between groups |
| Hierarchical (tree) | Levels, top to bottom | Organisation charts, family trees, dependencies |
| Geographic | Real locations on a map | Flight routes, power grids, delivery networks |
When to use a network graph
Use a network graph when the connections are the point: who is linked to whom, which groups form, and who holds them together. Typical uses:
- people: social networks, teams and email traffic, fraud rings;
- technology: computers on a network, services that call each other, web pages and their links;
- transport and infrastructure: routes between airports, stations or substations;
- science: citations between papers, interactions between genes or proteins;
- knowledge: topics or keywords that appear together.
| Chart | Best for |
|---|---|
| Network graph | Arbitrary links between items, to find hubs, clusters and bridges |
| Sankey diagram | A quantity flowing one way through stages, with band widths showing amounts |
| Heatmap (adjacency matrix) | Large or dense networks: one row and one column per node, with colour showing the link between them. No tangle, but harder to see paths |
| Treemap | A strict hierarchy, where every item has exactly one parent |
| Scatter plot | Items with two real measured values. A network graph's x and y are not values |
In IT, a network diagram often means a plan of a computer network, with routers, switches and servers drawn as icons. That plan is a network graph too, but a person lays it out by hand. This page is about network graphs drawn from data.
Common network graph mistakes
- The hairball. Draw every node and edge of a large network and you get a dense tangle that shows nothing. Filter to the nodes that matter, group clusters into single nodes, or show one node's neighbourhood at a time.
- Colour or size with no key. Readers can't guess that colour means team and size means connections. Add a legend, and use colour only for something that matters.
- Too many labels. Labelling every node buries the chart in text. Label the hubs and bridges, and show the rest in a tooltip on hover.
- Ignoring direction and weight. "A follows B" is not "B follows A", and one email is not a thousand. Use arrows for direction and line thickness for weight when they matter.
- Hiding the isolates. Nodes with no links are easy to filter out by accident, but they are often the finding: the customer nobody contacts, the server nothing uses.
How to create a network graph in JavaScript, React or Angular
SciChart.js has no separate network series, but a network graph is lines and circles: all the edges go in one line segment series and the nodes in bubble series, both drawn with WebGL or WebGPU. A short helper works out the layout. Try the graph below: hover over a person to highlight their links and neighbours, drag a person to move them (the network follows), scroll to zoom, drag the background to pan and double-click to reset.
Here is the code for this graph. The data is plain JSON: a list of nodes, each with a group, and a list of links that name the two nodes they join:
{
"groups": [{ "id": "eng", "name": "Engineering", "color": "#50C7E0" }],
"nodes": [{ "id": "Priya", "name": "Priya", "group": "eng" }, { "id": "Tom", "name": "Tom", "group": "eng" }],
"links": [{ "source": "Priya", "target": "Tom" }]
}
- JavaScript
- React
- Angular
// Create a JavaScript network graph with SciChart.js: edges as line segments, nodes as bubbles,
// laid out by a small force-directed simulation
const {
SciChartSurface,
NumericAxis,
NumberRange,
XyxyDataSeries,
XyzDataSeries,
FastLineSegmentRenderableSeries,
FastBubbleRenderableSeries,
EllipsePointMarker,
EStrokePaletteMode,
parseColorToUIntArgb,
NativeTextAnnotation,
EHorizontalAnchorPoint,
EVerticalAnchorPoint,
EMultiLineAlignment,
Thickness,
CustomChartModifier2D,
translateFromCanvasToSeriesViewRect,
LegendModifier,
ELegendPlacement,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier,
SciChartJsNavyTheme
} = SciChart;
// or, for npm, import { SciChartSurface, ... } from "scichart"
// 1. FORCE-DIRECTED LAYOUT (plain JavaScript, no SciChart code)
// Takes { nodes: [{ id, name, group }], links: [{ source, target }] } and gives every node an x and y.
// Every pair of nodes pushes apart, every link pulls its two ends together like a spring, and a weak pull
// towards the centre keeps separate pieces in view. Each step moves nodes less (cooling), until they settle.
function createForceLayout(data, options) {
const { size = 1000, iterations = 300, gravity = 0.06, seed = 1 } = options || {};
let state = seed;
const random = () => {
state = (state * 16807) % 2147483647; // seeded, so the layout is the same every time
return state / 2147483647;
};
const nodes = data.nodes.map((node, index) => ({
...node,
index,
x: (random() - 0.5) * size,
y: (random() - 0.5) * size,
fixed: false, // true while a node is being dragged
neighbours: [], // the nodes this one is linked to
degree: 0 // number of connections
}));
const nodeById = new Map();
nodes.forEach((node) => nodeById.set(node.id, node));
const links = data.links.map((link) => {
const source = nodeById.get(link.source);
const target = nodeById.get(link.target);
if (!source || !target) throw new Error(`Unknown node in link ${link.source} - ${link.target}`);
source.neighbours.push(target);
target.neighbours.push(source);
return { source, target };
});
nodes.forEach((node) => (node.degree = node.neighbours.length));
const k = Math.sqrt((size * size) / nodes.length) * 0.6; // the preferred distance between nodes
// One step of the Fruchterman-Reingold method: no node moves further than `temperature`
function step(temperature) {
const moveX = new Float64Array(nodes.length);
const moveY = new Float64Array(nodes.length);
for (let i = 0; i < nodes.length; i++) {
for (let j = i + 1; j < nodes.length; j++) {
const dx = nodes[i].x - nodes[j].x;
const dy = nodes[i].y - nodes[j].y;
const distance = Math.max(Math.hypot(dx, dy), 0.01);
const push = (k * k) / distance; // repulsion: strong when close
moveX[i] += (dx / distance) * push;
moveY[i] += (dy / distance) * push;
moveX[j] -= (dx / distance) * push;
moveY[j] -= (dy / distance) * push;
}
}
links.forEach(({ source, target }) => {
const dx = source.x - target.x;
const dy = source.y - target.y;
const distance = Math.max(Math.hypot(dx, dy), 0.01);
const pull = (distance * distance) / k; // attraction: strong when far apart
moveX[source.index] -= (dx / distance) * pull;
moveY[source.index] -= (dy / distance) * pull;
moveX[target.index] += (dx / distance) * pull;
moveY[target.index] += (dy / distance) * pull;
});
nodes.forEach((node) => {
if (node.fixed) return;
const mx = moveX[node.index] - node.x * gravity * k * 0.05;
const my = moveY[node.index] - node.y * gravity * k * 0.05;
const length = Math.max(Math.hypot(mx, my), 0.01);
const distance = Math.min(length, temperature);
node.x += (mx / length) * distance;
node.y += (my / length) * distance;
});
}
// Settle the layout before the first draw: start hot, cool down step by step
for (let i = 0; i < iterations; i++) step((size / 10) * (1 - i / iterations) + 0.5);
return { nodes, links, step };
}
// 2. TURN THE LAYOUT INTO SCICHART SERIES
// All edges in one FastLineSegmentRenderableSeries (an XyxyDataSeries holds x1, y1, x2, y2 per segment),
// plus one for the highlighted edges. One FastBubbleRenderableSeries per group, so the legend names the colours.
function addNetworkSeries(sciChartSurface, wasmContext, layout, groups) {
// Blend a colour towards the chart background, to fade a node without transparency
const mixColors = (color, background, amount) => {
const channel = (hex, i) => parseInt(hex.slice(1 + i * 2, 3 + i * 2), 16);
const mixed = [0, 1, 2].map((i) => Math.round(channel(color, i) * (1 - amount) + channel(background, i) * amount));
return "#" + mixed.map((value) => value.toString(16).padStart(2, "0")).join("");
};
const edgeData = new XyxyDataSeries(wasmContext);
const highlightData = new XyxyDataSeries(wasmContext);
const edgeSeries = new FastLineSegmentRenderableSeries(wasmContext, {
dataSeries: edgeData,
stroke: "#A9B8D0",
strokeThickness: 1.5,
opacity: 0.45
});
const highlightSeries = new FastLineSegmentRenderableSeries(wasmContext, {
dataSeries: highlightData,
stroke: "#FFFFFF",
strokeThickness: 2.5
});
sciChartSurface.renderableSeries.add(edgeSeries, highlightSeries);
let focus = null; // the node under the mouse, or null
const isActive = (node) => !focus || node === focus || focus.neighbours.includes(node);
const nodeSeries = groups.map((group) => {
const members = layout.nodes.filter((node) => node.group === group.id);
const normal = { fill: parseColorToUIntArgb(group.color), stroke: parseColorToUIntArgb("#FFFFFF") };
const faded = { fill: parseColorToUIntArgb(mixColors(group.color, "#1F2A44", 0.7)), stroke: 0 };
// Fade every node that isn't the hovered node or one of its neighbours
const paletteProvider = {
strokePaletteMode: EStrokePaletteMode.SOLID,
onAttached: () => {},
onDetached: () => {},
overridePointMarkerArgb: (x, y, index) => (isActive(members[index]) ? normal : faded)
};
const dataSeries = new XyzDataSeries(wasmContext, { dataSeriesName: group.name });
sciChartSurface.renderableSeries.add(
new FastBubbleRenderableSeries(wasmContext, {
dataSeries,
pointMarker: new EllipsePointMarker(wasmContext, { width: 64, height: 64, fill: group.color, strokeThickness: 0 }),
stroke: group.color, // the legend's colour swatch
paletteProvider
})
);
return { members, dataSeries };
});
// Copy the node positions into the series. Call it after the layout moves or the focus changes.
function update() {
const lines = { x1: [], y1: [], x2: [], y2: [] };
const bright = { x1: [], y1: [], x2: [], y2: [] };
layout.links.forEach(({ source, target }) => {
const into = focus && (source === focus || target === focus) ? bright : lines;
into.x1.push(source.x);
into.y1.push(source.y);
into.x2.push(target.x);
into.y2.push(target.y);
});
edgeData.clear();
edgeData.appendRange(lines.x1, lines.y1, lines.x2, lines.y2);
edgeSeries.opacity = focus ? 0.15 : 0.45;
highlightData.clear();
highlightData.appendRange(bright.x1, bright.y1, bright.x2, bright.y2);
nodeSeries.forEach(({ members, dataSeries }) => {
dataSeries.clear();
dataSeries.appendRange(
members.map((node) => node.x),
members.map((node) => node.y),
members.map((node) => 12 + 2.2 * node.degree) // bubble size in pixels: bigger = more connections
);
});
}
function setFocus(node) {
focus = node;
update();
}
update();
return { update, setFocus, edgeSeries, highlightSeries };
}
// 3. HOVER AND DRAG
// Hover over a node to highlight it, its links and its neighbours, with a tooltip. Drag a node to move it:
// the layout runs again while you drag, so its neighbours follow.
class NetworkModifier extends CustomChartModifier2D {
layout;
network;
groups;
tooltip;
hovered = null;
dragged = null;
temperature = 0;
animating = false;
constructor(layout, network, groups) {
super();
this.layout = layout;
this.network = network;
this.groups = groups;
this.tooltip = new NativeTextAnnotation({
text: "",
isHidden: true,
textColor: "#FFFFFF",
fontSize: 15,
background: "#0F1A2B",
multiLineAlignment: EMultiLineAlignment.Left,
padding: new Thickness(6, 10, 6, 10),
lineSpacing: 4,
verticalAnchorPoint: EVerticalAnchorPoint.Bottom
});
}
onAttach() {
super.onAttach();
this.parentSurface.annotations.add(this.tooltip);
}
onDetach() {
this.parentSurface?.annotations.remove(this.tooltip);
super.onDetach();
}
// Mouse position in data units, or null outside the plot area
toDataPoint(mousePoint) {
const point = translateFromCanvasToSeriesViewRect(mousePoint, this.parentSurface.seriesViewRect);
if (!point) return null;
const xCalc = this.parentSurface.xAxes.get(0).getCurrentCoordinateCalculator();
const yCalc = this.parentSurface.yAxes.get(0).getCurrentCoordinateCalculator();
return { x: xCalc.getDataValue(point.x), y: yCalc.getDataValue(point.y), xCalc, yCalc };
}
// The nearest node within about 14 pixels of the mouse, or null
findNode(mousePoint) {
const point = this.toDataPoint(mousePoint);
if (!point) return null;
let best = null;
let bestDistance = Infinity;
this.layout.nodes.forEach((node) => {
const dx = point.xCalc.getCoordinate(node.x) - point.xCalc.getCoordinate(point.x);
const dy = point.yCalc.getCoordinate(node.y) - point.yCalc.getCoordinate(point.y);
const distance = Math.hypot(dx, dy);
if (distance < bestDistance) {
best = node;
bestDistance = distance;
}
});
return bestDistance <= 14 * (window.devicePixelRatio || 1) ? best : null;
}
describe(node) {
const groupName = (id) => this.groups.find((group) => group.id === id).name;
const otherTeams = [...new Set(node.neighbours.map((n) => n.group).filter((g) => g !== node.group))];
const lines = [`${node.name} (${groupName(node.group)})`, `${node.degree} connection${node.degree === 1 ? "" : "s"}`];
if (otherTeams.length) lines.push(`Bridge to ${otherTeams.map(groupName).join(", ")}`);
return lines.join("\n");
}
showTooltip(node) {
this.tooltip.isHidden = !node;
if (!node) return;
const xRange = this.parentSurface.xAxes.get(0).visibleRange;
const yRange = this.parentSurface.yAxes.get(0).visibleRange;
const nearRightEdge = node.x > xRange.min + xRange.diff * 0.65;
this.tooltip.text = this.describe(node);
this.tooltip.horizontalAnchorPoint = nearRightEdge ? EHorizontalAnchorPoint.Right : EHorizontalAnchorPoint.Left;
this.tooltip.x1 = node.x + xRange.diff * (nearRightEdge ? -0.015 : 0.015);
this.tooltip.y1 = node.y + yRange.diff * 0.03;
}
// Run the layout a step per frame, cooling down, until it settles
animate() {
if (this.animating) return;
this.animating = true;
const frame = () => {
if (!this.parentSurface || this.parentSurface.isDeleted) return;
this.layout.step(this.temperature);
this.temperature *= 0.94;
if (this.dragged) this.temperature = Math.max(this.temperature, 6);
this.network.update();
this.showTooltip(this.dragged ?? this.hovered);
if (this.temperature > 0.3) requestAnimationFrame(frame);
else this.animating = false;
};
requestAnimationFrame(frame);
}
modifierMouseDown(args) {
super.modifierMouseDown(args);
const node = this.findNode(args.mousePoint);
if (!node) return;
this.dragged = node;
node.fixed = true;
args.handled = true; // stop ZoomPanModifier panning the chart
}
modifierMouseMove(args) {
super.modifierMouseMove(args);
if (this.dragged) {
const point = this.toDataPoint(args.mousePoint);
if (point) {
this.dragged.x = point.x;
this.dragged.y = point.y;
this.temperature = Math.max(this.temperature, 20);
this.animate();
}
args.handled = true;
return;
}
const node = this.findNode(args.mousePoint);
if (node !== this.hovered) {
this.hovered = node;
this.network.setFocus(node);
}
this.showTooltip(node);
}
modifierMouseUp(args) {
super.modifierMouseUp(args);
if (!this.dragged) return;
this.dragged.fixed = false;
this.dragged = null;
args.handled = true;
}
modifierMouseLeave(args) {
super.modifierMouseLeave(args);
if (this.dragged) this.dragged.fixed = false;
this.dragged = null;
this.hovered = null;
this.network.setFocus(null);
this.showTooltip(null);
}
}
// 4. THE CHART
async function networkGraph(divElementId) {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(divElementId, {
theme: new SciChartJsNavyTheme()
});
// Your data: nodes, links and the groups that colour the nodes
const data = getTeamNetworkData();
const layout = createForceLayout(data, { size: 1000, seed: 7 });
// The axes only set the drawing area. They're hidden: a node's x and y have no meaning of their own.
// Extra space at the bottom keeps the nodes clear of the chart's bottom-left corner.
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { isVisible: false, growBy: new NumberRange(0.06, 0.06) }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { isVisible: false, growBy: new NumberRange(0.12, 0.06) }));
const network = addNetworkSeries(sciChartSurface, wasmContext, layout, data.groups);
// Hover to highlight a node's neighbours, drag a node to move it, scroll to zoom, drag the background to pan,
// double-click to reset. The legend says what each colour means.
const legend = new LegendModifier({ showCheckboxes: false, placement: ELegendPlacement.TopRight });
sciChartSurface.chartModifiers.add(
new NetworkModifier(layout, network, data.groups),
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier(),
legend
);
// The legend lists the groups only, not the two edge series
legend.includeSeries(network.edgeSeries, false);
legend.includeSeries(network.highlightSeries, false);
}
import { SciChartReact } from "scichart-react";
import {
SciChartSurface,
NumericAxis,
NumberRange,
LegendModifier,
ELegendPlacement,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier,
SciChartJsNavyTheme
} from "scichart";
// createForceLayout, addNetworkSeries and NetworkModifier from the JavaScript tab, saved as network.ts
import { createForceLayout, addNetworkSeries, NetworkModifier } from "./network";
// initChart builds the chart; SciChartReact creates it, sizes it and cleans it up
const initChart = async (rootElement: string | HTMLDivElement) => {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
theme: new SciChartJsNavyTheme()
});
// { groups: [{ id, name, color }], nodes: [{ id, name, group }], links: [{ source, target }] }
const data = getYourNetworkData();
const layout = createForceLayout(data, { size: 1000, seed: 7 });
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { isVisible: false, growBy: new NumberRange(0.06, 0.06) }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { isVisible: false, growBy: new NumberRange(0.12, 0.06) }));
const network = addNetworkSeries(sciChartSurface, wasmContext, layout, data.groups);
const legend = new LegendModifier({ showCheckboxes: false, placement: ELegendPlacement.TopRight });
sciChartSurface.chartModifiers.add(
new NetworkModifier(layout, network, data.groups),
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier(),
legend
);
legend.includeSeries(network.edgeSeries, false);
legend.includeSeries(network.highlightSeries, false);
return { sciChartSurface };
};
export const NetworkGraph = () => (
<SciChartReact initChart={initChart} style={{ width: "100%", height: 500 }} />
);
import { Component } from "@angular/core";
import { ScichartAngularComponent } from "scichart-angular";
import {
SciChartSurface,
NumericAxis,
NumberRange,
LegendModifier,
ELegendPlacement,
MouseWheelZoomModifier,
ZoomPanModifier,
ZoomExtentsModifier,
SciChartJsNavyTheme
} from "scichart";
// createForceLayout, addNetworkSeries and NetworkModifier from the JavaScript tab, saved as network.ts
import { createForceLayout, addNetworkSeries, NetworkModifier } from "./network";
@Component({
selector: "app-network-graph",
standalone: true,
imports: [ScichartAngularComponent],
template: `<scichart-angular [initChart]="initChart" style="display: block; width: 100%; height: 500px"></scichart-angular>`
})
export class NetworkGraphComponent {
// initChart builds the chart; scichart-angular creates it, sizes it and cleans it up
initChart = async (rootElement: string | HTMLDivElement) => {
const { wasmContext, sciChartSurface } = await SciChartSurface.create(rootElement, {
theme: new SciChartJsNavyTheme()
});
// { groups: [{ id, name, color }], nodes: [{ id, name, group }], links: [{ source, target }] }
const data = getYourNetworkData();
const layout = createForceLayout(data, { size: 1000, seed: 7 });
sciChartSurface.xAxes.add(new NumericAxis(wasmContext, { isVisible: false, growBy: new NumberRange(0.06, 0.06) }));
sciChartSurface.yAxes.add(new NumericAxis(wasmContext, { isVisible: false, growBy: new NumberRange(0.12, 0.06) }));
const network = addNetworkSeries(sciChartSurface, wasmContext, layout, data.groups);
const legend = new LegendModifier({ showCheckboxes: false, placement: ELegendPlacement.TopRight });
sciChartSurface.chartModifiers.add(
new NetworkModifier(layout, network, data.groups),
new MouseWheelZoomModifier(),
new ZoomPanModifier(),
new ZoomExtentsModifier(),
legend
);
legend.includeSeries(network.edgeSeries, false);
legend.includeSeries(network.highlightSeries, false);
return { sciChartSurface };
};
}
Key points:
createForceLayoutis plain JavaScript with no SciChart code, so you can reuse it anywhere. It runs 300 rounds of a Fruchterman–Reingold layout before the first draw, from a seeded start, so the graph looks the same every time. Itsstep()function runs one more round, which the drag uses to let the network follow the node you move. Each round compares every pair of nodes, so keep to a few hundred nodes or use a faster layout for more.- All the edges are one FastLineSegmentRenderableSeries with an
XyxyDataSeries, which holds a start point and an end point for each segment. A second line segment series draws the hovered node's edges on top. - Each group's nodes are a FastBubbleRenderableSeries, with the bubble size in pixels set from the node's number of connections. One series per group gives the legend one entry per colour. A palette provider fades every node that isn't the hovered node or one of its neighbours.
NetworkModifierextendsCustomChartModifier2D(custom chart modifiers) to find the nearest node on each mouse move, show the tooltip and handle dragging. Settingargs.handled = trueon a node stopsZoomPanModifierpanning the chart at the same time. The axes are hidden, but they still set the drawing area, so zoom and pan work as on any chart.
See it in the demo app: JavaScript force-directed graph · React force-directed graph · Angular force-directed graph, a network of US airports and flight routes.
Go deeper: SciChart.js line segment series documentation, the SciChart.js bubble series documentation and the custom chart modifier documentation.
Frequently asked questions
What is a network graph used for?
A network graph is used to show how things are connected and to find the structure in those connections: which items are central, which groups form, and which items link one group to another. Common uses are social and organisational networks, computer and telecoms networks, transport routes, citations between papers, links between web pages, and interactions between genes or proteins.
What is a force-directed graph?
A force-directed graph, or force graph for short, is a network graph whose layout comes from a simple physics simulation. Every pair of nodes pushes apart, every edge pulls the two nodes it joins together like a spring, and the simulation runs until the nodes settle. Linked nodes end up close together, so clusters form groups on the screen. The x and y positions themselves carry no units or meaning.
What is the difference between a network graph and a network diagram?
In data visualisation the two names mean the same chart: nodes joined by edges, drawn from data. In IT, a network diagram usually means a hand-drawn plan of a computer network, with routers, switches, servers and the cables between them, often drawn with icons. That plan is a kind of network graph, but it is laid out by a person rather than computed from data.
Is a network graph the same as a graph neural network?
No. A network graph is a chart that draws nodes and the links between them. A graph neural network is a machine learning model that takes the same kind of data, nodes and links, as its input, and learns to make predictions about the nodes, the links or the whole network. You might draw a network graph to explore the data that a graph neural network is trained on.
How do I make a network graph in JavaScript?
Store the data as a list of nodes and a list of edges, where each edge names the two nodes it joins. Run a layout, such as a force-directed simulation, to give each node an x and y position. Then draw the edges as line segments and the nodes as circles. With SciChart.js you draw all the edges in one FastLineSegmentRenderableSeries and the nodes as bubble or scatter series, and add a custom modifier for hover and drag. The same code works in React with scichart-react and in Angular with scichart-angular.
Sources
- Fruchterman, T. M. J. and Reingold, E. M. (1991), Graph drawing by force-directed placement. Software: Practice and Experience, 21(11), 1129–1164. The force-directed layout method used in the live example: nodes repel, edges attract, and the movement cools step by step.
- Freeman, L. C. (1978), Centrality in social networks: conceptual clarification. Social Networks, 1(3), 215–239. Defines degree, betweenness and closeness centrality.
- Girvan, M. and Newman, M. E. J. (2002), Community structure in social and biological networks. Proceedings of the National Academy of Sciences, 99(12), 7821–7826. Clusters (communities) in networks, and finding them through the edges that bridge them.