← Gallery

Pyramid

Allocation by service

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

Preview
Allocation by serviceAllocation by service with 1 data series: Allocation.Regional service 1: 16, height encoding, 11.8% of totalRegional service 2: 15, height encoding, 11.0% of totalRegional service 3: 14, height encoding, 10.3% of totalRegional service 4: 13, height encoding, 9.6% of totalRegional service 5: 12, height encoding, 8.8% of totalRegional service 6: 11, height encoding, 8.1% of totalRegional service 7: 10, height encoding, 7.4% of totalRegional service 8: 9, height encoding, 6.6% of totalRegional service 9: 8, height encoding, 5.9% of totalRegional service 10: 7, height encoding, 5.1% of totalRegional service 11: 6, height encoding, 4.4% of totalRegional service 12: 5, height encoding, 3.7% of totalRegional service 13: 4, height encoding, 2.9% of totalRegional service 14: 3, height encoding, 2.2% of totalRegional service 15: 2, height encoding, 1.5% of totalRegional service 16: 1, height encoding, 0.7% of total
Allocation by service
Allocation by serviceAllocation by service with 1 data series: Allocation.Regional service 1: 16, height encoding, 11.8% of totalRegional service 2: 15, height encoding, 11.0% of totalRegional service 3: 14, height encoding, 10.3% of totalRegional service 4: 13, height encoding, 9.6% of totalRegional service 5: 12, height encoding, 8.8% of totalRegional service 6: 11, height encoding, 8.1% of totalRegional service 7: 10, height encoding, 7.4% of totalRegional service 8: 9, height encoding, 6.6% of totalRegional service 9: 8, height encoding, 5.9% of totalRegional service 10: 7, height encoding, 5.1% of totalRegional service 11: 6, height encoding, 4.4% of totalRegional service 12: 5, height encoding, 3.7% of totalRegional service 13: 4, height encoding, 2.9% of totalRegional service 14: 3, height encoding, 2.2% of totalRegional service 15: 2, height encoding, 1.5% of totalRegional service 16: 1, height encoding, 0.7% of total
Allocation by service
800 × 440 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 = PyramidRecipe.Create("dense", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Allocation by service", "", 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>Builds a triangular allocation chart from ordered service values.</summary>
public static class PyramidRecipe {
    /// <summary>Creates the selected pyramid example, including area encoding and geometric reversal.</summary>
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "compact" or "sparse" or "options" or "compact-options" or "dense" or "compact-dense"))
            throw new ArgumentOutOfRangeException(nameof(variant));
        var chart = Chart.Create().DataLabels();
        if (variant is "dense" or "compact-dense") {
            chart.Title("Allocation by service")
                .XLabels(Enumerable.Range(1, 16).Select(index => "Regional service " + index).ToArray())
                .AddPyramid("Allocation", Enumerable.Range(1, 16).Select(index => new ChartPoint(index, 17 - index)));
        }
        else if (variant is "options" or "compact-options") {
            var allocation = new ChartSeries(new ChartSeriesId("allocation"), "Allocation", ChartSeriesKind.Pyramid, new[] {
                new ChartPoint(1, 50), new ChartPoint(2, 30), new ChartPoint(3, 20), new ChartPoint(4, 0)
            }).PointColor(0, ChartColor.FromHex("#2F78C4")).PointColor(1, ChartColor.FromHex("#E2A644")).PointColor(2, ChartColor.FromHex("#34957A"))
                .PointFillPattern(1, ChartFillPattern.DiagonalForward);
            chart.XLabels("Services", "Platform", "Support", "Unassigned").AddSeries(allocation)
                .Pyramid(options => {
                    options.ValueEncoding = ChartPyramidValueEncoding.Area;
                    options.Orientation = ChartOrientation.Horizontal;
                    options.Reversed = true;
                    options.AspectRatio = .75;
                });
        }
        else {
            var allocation = new ChartSeries(new ChartSeriesId("allocation"), "Allocation", ChartSeriesKind.Pyramid,
                new[] { new ChartPoint(1, 50), new ChartPoint(2, 30), new ChartPoint(3, 20) });
            chart.XLabels("Services", "Platform", "Support").AddSeries(allocation);
        }
        return chart;
    }
}
#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 = PyramidRecipe.Create("dense", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Allocation by service", "", 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>Builds a triangular allocation chart from ordered service values.</summary>
public static class PyramidRecipe {
    /// <summary>Creates the selected pyramid example, including area encoding and geometric reversal.</summary>
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "compact" or "sparse" or "options" or "compact-options" or "dense" or "compact-dense"))
            throw new ArgumentOutOfRangeException(nameof(variant));
        var chart = Chart.Create().DataLabels();
        if (variant is "dense" or "compact-dense") {
            chart.Title("Allocation by service")
                .XLabels(Enumerable.Range(1, 16).Select(index => "Regional service " + index).ToArray())
                .AddPyramid("Allocation", Enumerable.Range(1, 16).Select(index => new ChartPoint(index, 17 - index)));
        }
        else if (variant is "options" or "compact-options") {
            var allocation = new ChartSeries(new ChartSeriesId("allocation"), "Allocation", ChartSeriesKind.Pyramid, new[] {
                new ChartPoint(1, 50), new ChartPoint(2, 30), new ChartPoint(3, 20), new ChartPoint(4, 0)
            }).PointColor(0, ChartColor.FromHex("#2F78C4")).PointColor(1, ChartColor.FromHex("#E2A644")).PointColor(2, ChartColor.FromHex("#34957A"))
                .PointFillPattern(1, ChartFillPattern.DiagonalForward);
            chart.XLabels("Services", "Platform", "Support", "Unassigned").AddSeries(allocation)
                .Pyramid(options => {
                    options.ValueEncoding = ChartPyramidValueEncoding.Area;
                    options.Orientation = ChartOrientation.Horizontal;
                    options.Reversed = true;
                    options.AspectRatio = .75;
                });
        }
        else {
            var allocation = new ChartSeries(new ChartSeriesId("allocation"), "Allocation", ChartSeriesKind.Pyramid,
                new[] { new ChartPoint(1, 50), new ChartPoint(2, 30), new ChartPoint(3, 20) });
            chart.XLabels("Services", "Platform", "Support").AddSeries(allocation);
        }
        return chart;
    }
}