#region Setup 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 = ConcentricPieRecipe.Create("concentric", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode, new VisualFrame("Service mix across two periods", "Independent totals share categories; disjoint bands preserve each series", 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 /// Two independent service mixes in explicit concentric Pie and Donut bands. public static class ConcentricPieRecipe { /// Creates independent totals and source identities without implying equal totals across rings. public static Chart Create(string variant = "concentric", VisualThemeMode mode = VisualThemeMode.Light) { if (variant is not ("concentric" or "compact-concentric")) throw new ArgumentOutOfRangeException(nameof(variant)); var prior = new ChartSeries(new ChartSeriesId("prior"), "Prior", ChartSeriesKind.Donut, new[] { new ChartPoint(1, 75), new ChartPoint(2, 25) }) .WithRadialBand(new ChartRadialBand(.22, .52)) .WithObservationIds(new[] { new ChartObservationId("subscriptions"), new ChartObservationId("consulting") }); var current = new ChartSeries(new ChartSeriesId("current"), "Current", ChartSeriesKind.Pie, new[] { new ChartPoint(1, 132), new ChartPoint(2, 88) }) .WithRadialBand(new ChartRadialBand(.66, 1)) .WithObservationIds(new[] { new ChartObservationId("subscriptions"), new ChartObservationId("consulting") }); prior.DataLabelPlacement = ChartDataLabelPlacement.Inside; current.DataLabelPlacement = ChartDataLabelPlacement.Inside; // The legend retains each period's values; keep these small concentric holes free of center text. return Chart.Create().WithXLabels("Subscriptions", "Consulting").WithDataLabels() .WithPieSliceLabelContent(ChartPieSliceLabelContent.Percent).WithDonutCenterLabel(false) .AddSeries(prior).AddSeries(current); } }