← Gallery

Sankey

Requests across processing stages

Explore the example, download the output or use the C# source in your own project.

Preview
Requests across processing stagesChart with 1 data series: Requests.
Requests across processing stages
Requests across processing stagesChart with 1 data series: Requests.
Requests across processing stages
360 × 360 pixels

Create this example

Create a console project, add the ChartForgeX package, and replace Program.cs with this source. Run it to write SVG, PNG and HTML with the default system fonts.

For the same typography as the gallery, download the gallery-font recipe and copy the gallery’s fonts directory beside your program.

#region Setup
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using ChartForgeX;
using ChartForgeX.Core;
using ChartForgeX.Primitives;
using ChartForgeX.Rendering;
using ChartForgeX.Themes;
using ChartForgeX.Topology;
using ChartForgeX.Typography;
using ChartForgeX.VisualArtifacts;
using ChartForgeX.VisualBlocks;

var mode = ThemeMode.Light;
var theme = VisualTheme.Graphite();
var model = SankeyRecipe.Create("compact", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Requests across processing stages", "", showLegend: null, showSurface: false));
var prepared = model.Prepare(context);
File.WriteAllText("visual.svg", prepared.ToSvg());
File.WriteAllBytes("visual.png", prepared.ToPng());
File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Chart).ToHtmlPage());
#endregion

/// <summary>Weighted requests flow from their channels through automatic and manual processing to an outcome.</summary>
public static class SankeyRecipe {
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        var requests = ChartSeries.CreateSankey(new ChartSeriesId("requests"), "Requests", new[] {
            new ChartNode("portal", "Portal"), new ChartNode("email", "Email"), new ChartNode("phone", "Phone"),
            new ChartNode("automatic", "Automatic"), new ChartNode("manual", "Manual"),
            new ChartNode("completed", "Completed"), new ChartNode("review", "Review"), new ChartNode("rejected", "Rejected")
        }, new[] {
            new ChartFlowLink("portal-automatic", "portal", "automatic", 410), new ChartFlowLink("portal-manual", "portal", "manual", 90),
            new ChartFlowLink("email-automatic", "email", "automatic", 160), new ChartFlowLink("email-manual", "email", "manual", 140),
            new ChartFlowLink("phone-manual", "phone", "manual", 200),
            new ChartFlowLink("automatic-completed", "automatic", "completed", 505), new ChartFlowLink("automatic-review", "automatic", "review", 45),
            new ChartFlowLink("automatic-rejected", "automatic", "rejected", 20),
            new ChartFlowLink("manual-completed", "manual", "completed", 330), new ChartFlowLink("manual-review", "manual", "review", 70),
            new ChartFlowLink("manual-rejected", "manual", "rejected", 30)
        });
        if (variant == "sparse") requests.ReplaceFlowData(new[] {
            new ChartNode("received", "Received"), new ChartNode("completed", "Completed"), new ChartNode("review", "Review")
        }, new[] {
            new ChartFlowLink("received-completed", "received", "completed", 85),
            new ChartFlowLink("received-review", "received", "review", 15)
        });
        if (variant != "sparse") {
            // Channels and processing paths take series colours; outcomes take the theme's status colours.
            var colors = VisualTheme.Graphite().Resolve(mode);
            for (var index = 0; index < 5; index++) requests.PointColor(index, colors.Palette[index]);
            requests.NodeState("completed", ChartSeriesState.Success)
                .NodeState("review", ChartSeriesState.Warning)
                .NodeState("rejected", ChartSeriesState.Danger);
        }
        return Chart.Create().AddSeries(requests);
    }
}
#region Setup
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using ChartForgeX;
using ChartForgeX.Core;
using ChartForgeX.Primitives;
using ChartForgeX.Rendering;
using ChartForgeX.Themes;
using ChartForgeX.Topology;
using ChartForgeX.Typography;
using ChartForgeX.VisualArtifacts;
using ChartForgeX.VisualBlocks;

var mode = ThemeMode.Dark;
var theme = VisualTheme.Graphite();
var model = SankeyRecipe.Create("compact", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Requests across processing stages", "", showLegend: null, showSurface: false));
var prepared = model.Prepare(context);
File.WriteAllText("visual.svg", prepared.ToSvg());
File.WriteAllBytes("visual.png", prepared.ToPng());
File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Chart).ToHtmlPage());
#endregion

/// <summary>Weighted requests flow from their channels through automatic and manual processing to an outcome.</summary>
public static class SankeyRecipe {
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        var requests = ChartSeries.CreateSankey(new ChartSeriesId("requests"), "Requests", new[] {
            new ChartNode("portal", "Portal"), new ChartNode("email", "Email"), new ChartNode("phone", "Phone"),
            new ChartNode("automatic", "Automatic"), new ChartNode("manual", "Manual"),
            new ChartNode("completed", "Completed"), new ChartNode("review", "Review"), new ChartNode("rejected", "Rejected")
        }, new[] {
            new ChartFlowLink("portal-automatic", "portal", "automatic", 410), new ChartFlowLink("portal-manual", "portal", "manual", 90),
            new ChartFlowLink("email-automatic", "email", "automatic", 160), new ChartFlowLink("email-manual", "email", "manual", 140),
            new ChartFlowLink("phone-manual", "phone", "manual", 200),
            new ChartFlowLink("automatic-completed", "automatic", "completed", 505), new ChartFlowLink("automatic-review", "automatic", "review", 45),
            new ChartFlowLink("automatic-rejected", "automatic", "rejected", 20),
            new ChartFlowLink("manual-completed", "manual", "completed", 330), new ChartFlowLink("manual-review", "manual", "review", 70),
            new ChartFlowLink("manual-rejected", "manual", "rejected", 30)
        });
        if (variant == "sparse") requests.ReplaceFlowData(new[] {
            new ChartNode("received", "Received"), new ChartNode("completed", "Completed"), new ChartNode("review", "Review")
        }, new[] {
            new ChartFlowLink("received-completed", "received", "completed", 85),
            new ChartFlowLink("received-review", "received", "review", 15)
        });
        if (variant != "sparse") {
            // Channels and processing paths take series colours; outcomes take the theme's status colours.
            var colors = VisualTheme.Graphite().Resolve(mode);
            for (var index = 0; index < 5; index++) requests.PointColor(index, colors.Palette[index]);
            requests.NodeState("completed", ChartSeriesState.Success)
                .NodeState("review", ChartSeriesState.Warning)
                .NodeState("rejected", ChartSeriesState.Danger);
        }
        return Chart.Create().AddSeries(requests);
    }
}