Graph Format
graph describes the relationships between nodes. It consists of two kinds of records: nodes and edges. Nodes represent entities, while edges use source and target (both node ids) to describe the relationship between two nodes.
It suits charts that show networks, relationships, or flows, such as a force-directed graph.
When to use
- Showing "a network of relationships between entities" (social or dependency relationships)
- Expressing "the flow or connection strength between nodes"
- Data that has a node / edge graph-theory structure
Data structure
Graph data mixes node and edge records. Nodes use id, name, value, and series; edges additionally require source and target (pointing to node ids):
import type { RawData } from '@orbcharts/core'
const data: RawData = [
// nodes
{ id: 'id0', name: 'label0', value: 19800000, series: 'series1' },
{ id: 'id2', name: 'label2', value: 9800000, series: 'series1' },
// edge
{ id: 'id14', name: 'label8', series: 'series2', source: 'id0', target: 'id2', value: 100 },
]Available fields
| Field | Type | Required | Description |
|---|---|---|---|
id | string | Yes | Unique identifier; nodes are referenced by edges through it |
value | number | null | No | The value of a node or edge |
series | string | No | Series name; used for grouping and coloring by default |
name | string | No | Display name (e.g. the text shown in a Tooltip) |
source | string | Required for edges | The source node id of an edge |
target | string | Required for edges | The target node id of an edge |
data | any | No | Custom attached data, preserved as-is |
Tip: Whether a record is treated as an "edge" depends on whether it has both
sourceandtarget; all other records are treated as "nodes". A node'sidis required, and an edge'ssource/targetmust match theidof an existing node.
Model data (ModelDataGraph)
After OrbCharts processes RawData, graph data is split into node and edge arrays, forming an overall ModelDataGraph structure:
interface ModelDataGraph {
nodes: ModelDatumGraphNode[]
edges: ModelDatumGraphEdge[]
}The node ModelDatumGraphNode extends ModelDatumBase:
interface ModelDatumGraphNode {
// From ModelDatumBase
id: string
index: number
modelType: 'graph'
name: string
data: any
value: number | null
color: string
// Graph node-specific fields
series: string
seriesIndex: number
category: string
categoryIndex: number
}The edge ModelDatumGraphEdge carries, beyond the node fields, source / target and their indices:
interface ModelDatumGraphEdge {
// From ModelDatumBase
id: string
index: number
modelType: 'graph'
name: string
data: any
value: number | null
color: string
// Graph edge-specific fields
series: string
seriesIndex: number
category: string
categoryIndex: number
source: ModelDatumGraphNode
sourceIndex: number
target: ModelDatumGraphNode
targetIndex: number
}Corresponding Plugins
The graph format works with the following Plugins:
| Plugin | Charts |
|---|---|
| NetworkPlot | Force-directed graph |
Full example
Below is a relationship chart using NetworkPlot (which shows a force-directed graph by default):
import { OrbCharts } from '@orbcharts/core'
import type { RawData } from '@orbcharts/core'
import { NetworkPlot, Tooltip, Legend } from '@orbcharts/plugin-basic'
const data: RawData = [
// nodes
{ id: 'id0', name: 'label0', value: 19800000, series: 'series1' },
{ id: 'id2', name: 'label2', value: 9800000, series: 'series1' },
// edge
{ id: 'id14', name: 'label8', series: 'series2', source: 'id0', target: 'id2', value: 100 },
]
const chart = new OrbCharts(document.querySelector('#chart')!, {
data,
plugins: [
new NetworkPlot(),
new Tooltip(),
new Legend(),
],
})
// Remember to destroy the chart on unmount to release resources and listeners
// chart.destroy()Note: OrbCharts fills its container by default (
sizedefaults to'auto'). Make sure the#chartcontainer has an explicit width and height, otherwise the chart may not be visible. See Core Concepts.
Related links
- Back to Data Formats Overview
- See the full parameters and more chart examples in NetworkPlot
- For size and color settings, see Core Concepts
- For color and ColorType settings, see Theme API