Create Sankey Diagram Calculating Edge Thickness
Create a Sankey diagram calculating the edge thickness using the sankey()
function with an aggregator
Query
sankey(source="src", target="dst", weight=(sum(cnt)))
Introduction
The sankey()
function is used to create a Sankey
diagram to vizualise flow relationships between nodes. The input data must
be compatible with the Sankey widget, meaning that the event set must
contain source field, target
field, and weight field. For more information about
Sankey widgets, see Sankey Diagram Widget.
In this example, the sankey()
function is used with
the weight
parameter to show
the edge thickness of the fields cnt (count),
dst (destination), and src
(source) in a Sankey diagram. Edge thickness in a Sankey diagram
represents the magnitude or quantity of flow between nodes.
The edge
is the connecting line between source and
target nodes, and the thickness
represents the
weightend value of that connection.
Example incoming data might look like this:
cnt | dst | src |
---|---|---|
12 | apples | john |
1 | bananas | john |
1 | apples | joe |
1 | apples | sarah |
1 | apples | sarah |
1 | apples | sarah |
Step-by-Step
Starting with the source repository events.
- flowchart LR; %%{init: {"flowchart": {"defaultRenderer": "elk"}} }%% repo{{Events}} 0{{Aggregate}} result{{Result Set}} repo --> 0 0 --> result style 0 fill:#ff0000,stroke-width:4px,stroke:#000;logscale
sankey(source="src", target="dst", weight=(sum(cnt)))
Creates a Sankey diagram showing the sources on the left side (john, joe, sarah), and the targets on the right side (apples, bananas), and then provides the edge thickness based on the sum.
Event Result set.
Summary and Results
The query is used to create a Sankey diagram showing the sources on the
left side (john, joe, sarah), and the targets on the right side (apples,
bananas), and then display the edge thickness using the
weight
parameter. In this
example, the thickest edge is john → apples
(12)
, the medium edge is sarah → apples
(3)
, and the thin edges are joe → apples
(1)
and john → bananas (1)
.
The query is useful for rendering results as a two-level Sankey diagram and visualize flow relationships between nodes. It shows proportional relationships between data categories.
Sample output from the incoming example data:
source | target | weight |
---|---|---|
joe | apples | 1 |
john | apples | 12 |
john | bananas | 1 |
sarah | apples | 3 |
![]() |