Preview


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.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
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 = VisualThemeMode.Light;
var theme = VisualTheme.Graphite();
var model = PyramidRecipe.Create("options", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
new VisualFrame("How work is allocated across services", "Reversed horizontal pyramid; areas encode values including zero", 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());
/// <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", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("wide" or "compact" or "sparse" or "options" or "compact-options"))
throw new ArgumentOutOfRangeException(nameof(variant));
var chart = Chart.Create().WithDataLabels();
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)
}).WithPointColor(0, "#2F78C4").WithPointColor(1, "#E2A644").WithPointColor(2, "#34957A")
.WithPointFillPattern(1, ChartFillPattern.DiagonalForward);
chart.WithXLabels("Services", "Platform", "Support", "Unassigned").AddSeries(allocation)
.ConfigurePyramid(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.WithXLabels("Services", "Platform", "Support").AddSeries(allocation);
}
return chart.WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture));
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
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 = VisualThemeMode.Dark;
var theme = VisualTheme.Graphite();
var model = PyramidRecipe.Create("options", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
new VisualFrame("How work is allocated across services", "Reversed horizontal pyramid; areas encode values including zero", 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());
/// <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", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("wide" or "compact" or "sparse" or "options" or "compact-options"))
throw new ArgumentOutOfRangeException(nameof(variant));
var chart = Chart.Create().WithDataLabels();
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)
}).WithPointColor(0, "#2F78C4").WithPointColor(1, "#E2A644").WithPointColor(2, "#34957A")
.WithPointFillPattern(1, ChartFillPattern.DiagonalForward);
chart.WithXLabels("Services", "Platform", "Support", "Unassigned").AddSeries(allocation)
.ConfigurePyramid(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.WithXLabels("Services", "Platform", "Support").AddSeries(allocation);
}
return chart.WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture));
}
}