Create Sankey Diagram Calculating Edge Thickness

Create a Sankey diagram calculating the edge thickness using the sankey() function with an aggregator

Query

logscale
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:

cntdstsrc
12applesjohn
1bananasjohn
1applesjoe
1applessarah
1applessarah
1applessarah

Step-by-Step

  1. Starting with the source repository events.

  2. 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.

    The default weight parameter is count().

  3. 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:

sourcetargetweight
joeapples1
johnapples12
johnbananas1
sarahapples3
Showing Edge Thickness with Sankey()