#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("below-labels", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(600, 375)), theme, mode, new VisualFrame("Four equal shares", "Labels below", 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 /// Four equal donut shares with labels above or below their measured anchors. public static class EqualDonutRecipe { /// Creates the symmetric label example using above-labels or below-labels. 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); } }