Preview


600 × 375 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 = EqualDonutRecipe.Create("above-labels", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(600, 375)), theme, mode,
new VisualFrame("Four equal shares", "Labels above", showLegend: false, 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>Four equal donut shares with labels above or below their measured anchors.</summary>
public static class EqualDonutRecipe {
/// <summary>Creates the symmetric label example using above-labels or below-labels.</summary>
public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("wide" or "above-labels" or "below-labels")) throw new ArgumentOutOfRangeException(nameof(variant));
var shares = new ChartSeries(new ChartSeriesId("equal-shares"), "Equal shares", ChartSeriesKind.Donut,
Enumerable.Range(1, 4).Select(index => new ChartPoint(index, 1)));
return Chart.Create().XLabels("A", "B", "C", "D").DataLabels()
.Pie(p => p.SliceLabelContent(ChartPieSliceLabelContent.Label).ShowCenterLabel(false))
.DataLabels(d => d.Placement(variant == "below-labels" ? ChartDataLabelPlacement.Below : ChartDataLabelPlacement.Above))
.AddSeries(shares);
}
}
#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 = EqualDonutRecipe.Create("above-labels", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(600, 375)), theme, mode,
new VisualFrame("Four equal shares", "Labels above", showLegend: false, 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>Four equal donut shares with labels above or below their measured anchors.</summary>
public static class EqualDonutRecipe {
/// <summary>Creates the symmetric label example using above-labels or below-labels.</summary>
public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("wide" or "above-labels" or "below-labels")) throw new ArgumentOutOfRangeException(nameof(variant));
var shares = new ChartSeries(new ChartSeriesId("equal-shares"), "Equal shares", ChartSeriesKind.Donut,
Enumerable.Range(1, 4).Select(index => new ChartPoint(index, 1)));
return Chart.Create().XLabels("A", "B", "C", "D").DataLabels()
.Pie(p => p.SliceLabelContent(ChartPieSliceLabelContent.Label).ShowCenterLabel(false))
.DataLabels(d => d.Placement(variant == "below-labels" ? ChartDataLabelPlacement.Below : ChartDataLabelPlacement.Above))
.AddSeries(shares);
}
}