#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; // Native PNG and standalone SVG use bundled Archivo. // Add ChartFontAssets.StyleSheet once for other text on a host page. var mode = ThemeMode.Light; var theme = VisualTheme.Graphite(); var model = EqualPieRecipe.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), FontSpec.FromFamily(ChartFontStacks.ProductSans)); 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 pie shares with labels above or below their measured anchors. public static class EqualPieRecipe { /// 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.Pie, 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); } }