#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 = DonutSliceRadiusRecipe.Create("compact-variable-radius", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(390, 480)), theme, mode, new VisualFrame("Service shares with authored radii", "Values determine angles; explicit fractions determine band thickness", showLegend: null, 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 /// Authored Donut radii remain independent of each value's angular share. public static class DonutSliceRadiusRecipe { /// Creates service shares with explicit source identities and normalized band-relative radii. public static Chart Create(string variant = "variable-radius", ThemeMode mode = ThemeMode.Light) { if (variant is not ("variable-radius" or "compact-variable-radius")) throw new ArgumentOutOfRangeException(nameof(variant)); var services = new ChartSeries(new ChartSeriesId("services"), "Services", ChartSeriesKind.Donut, new[] { new ChartPoint(1, 80), new ChartPoint(2, 60), new ChartPoint(3, 20) }) .ObservationIds(new[] { new ChartObservationId("subscriptions"), new ChartObservationId("consulting"), new ChartObservationId("support") }) .PointSliceRadiusRatio(0, .35).PointSliceRadiusRatio(1, .7).PointSliceRadiusRatio(2, 1); services.DataLabelPlacement = ChartDataLabelPlacement.Outside; return Chart.Create().XLabels("Subscriptions", "Consulting", "Support").DataLabels() .Pie(p => p.SliceLabelContent(ChartPieSliceLabelContent.LabelAndPercent).ShowCenterLabel(false)) .AddSeries(services); } }