Skip to content

Sankey Diagram

Flow diagram showing quantities transferred between stages.

When to Use

  • Supply chain flows (raw material → factory → distributor → retail)
  • Budget allocation (income → categories → subcategories)
  • User journey funnels

Example

from d3_bridge import Sankey

chart = Sankey(
    nodes=[
        {"id": "Farms", "name": "Farms"},
        {"id": "Cooperative", "name": "Cooperative"},
        {"id": "Export", "name": "Export"},
        {"id": "Local", "name": "Local Market"},
    ],
    links=[
        {"source": "Farms", "target": "Cooperative", "value": 80},
        {"source": "Cooperative", "target": "Export", "value": 60},
        {"source": "Cooperative", "target": "Local", "value": 20},
    ],
    title="Cacao Supply Chain",
)

Note

Sankey requires the d3-sankey plugin, which is not loaded by default. Enable it with {% d3_scripts sankey=True %}, or globally for every page via D3_BRIDGE = {"SANKEY": True} in settings. Alternatively, add the script tag yourself before {% d3_scripts %}:

<script src="https://cdn.jsdelivr.net/npm/d3-sankey@0.12"></script>
If the plugin isn't loaded, the chart renders an inline message instead of failing silently.

Parameters

Parameter Type Default Description
nodes list or QuerySet Node data
links list or QuerySet Link data with value
node_id str "id" Node identifier field
node_label str "name" Node label field
link_source str "source" Link source field
link_target str "target" Link target field
link_value str "value" Link value field
node_padding int 10 Vertical padding between nodes
node_width int 20 Width of node rectangles
align str "justify" "left", "right", "center", "justify"