Preview


900 × 560 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 = MultiRingCalloutsRecipe.Create("vertical", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(900, 560)), theme, mode,
new VisualFrame("Independent periods with inner captions", "Exact displaced sectors share one frame; source-owned overlay leaders retain every ring association", 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
/// <summary>Independent periods retain source-owned inner callouts and exact exploded native sectors.</summary>
public static class MultiRingCalloutsRecipe {
/// <summary>Creates explicit or automatically allocated rings with shared outside caption lanes.</summary>
/// <remarks>Shifted sectors may overlap; haloed caption leaders overlay enclosing rings. Exact typography requires registered or installed Carlito regular/bold.</remarks>
public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("wide" or "compact" or "automatic" or "compact-automatic" or "vertical" or "compact-vertical" or "mixed" or "compact-mixed"))
throw new ArgumentOutOfRangeException(nameof(variant));
var compact = variant.StartsWith("compact", StringComparison.Ordinal);
var chart = Chart.Create().Size(compact ? 390 : 900, compact ? 580 : 560)
.Title("Service intake across two periods").Subtitle("Caption leaders retain their own ring and observation")
.Theme(VisualTheme.Graphite()).ThemeMode(mode).XLabels("Consulting", "Subscriptions")
.DataLabels().Pie(p => p.ShowCenterLabel(false).SliceLabelContent(ChartPieSliceLabelContent.LabelAndPercent));
var automatic = variant.EndsWith("automatic", StringComparison.Ordinal);
if (automatic) chart.RadialBandAllocation(new ChartRadialBandAllocation(.18, .14));
for (var index = 0; index < 2; index++) {
var values = index == 0 ? new[] { 60d, 30 } : new[] { 40d, 80 };
var series = new ChartSeries(new ChartSeriesId(index == 0 ? "prior" : "current"), index == 0 ? "Prior period" : "Current period", ChartSeriesKind.Donut,
values.Select((value, category) => new ChartPoint(category + 1, value)))
.ObservationIds(new[] { new ChartObservationId("consulting"), new ChartObservationId("subscriptions") })
.PointSliceOffset(index, index == 0 ? .16 : .1);
if (!automatic) series.RadialBand(index == 0 ? new ChartRadialBand(.18, .48) : new ChartRadialBand(.62, 1));
series.DataLabelPlacement = variant.EndsWith("vertical", StringComparison.Ordinal) ? ChartDataLabelPlacement.Above
: variant.EndsWith("mixed", StringComparison.Ordinal) && index == 1 ? ChartDataLabelPlacement.Below : ChartDataLabelPlacement.Outside;
chart.AddSeries(series);
}
return chart;
}
}
#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 = MultiRingCalloutsRecipe.Create("vertical", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(900, 560)), theme, mode,
new VisualFrame("Independent periods with inner captions", "Exact displaced sectors share one frame; source-owned overlay leaders retain every ring association", 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
/// <summary>Independent periods retain source-owned inner callouts and exact exploded native sectors.</summary>
public static class MultiRingCalloutsRecipe {
/// <summary>Creates explicit or automatically allocated rings with shared outside caption lanes.</summary>
/// <remarks>Shifted sectors may overlap; haloed caption leaders overlay enclosing rings. Exact typography requires registered or installed Carlito regular/bold.</remarks>
public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("wide" or "compact" or "automatic" or "compact-automatic" or "vertical" or "compact-vertical" or "mixed" or "compact-mixed"))
throw new ArgumentOutOfRangeException(nameof(variant));
var compact = variant.StartsWith("compact", StringComparison.Ordinal);
var chart = Chart.Create().Size(compact ? 390 : 900, compact ? 580 : 560)
.Title("Service intake across two periods").Subtitle("Caption leaders retain their own ring and observation")
.Theme(VisualTheme.Graphite()).ThemeMode(mode).XLabels("Consulting", "Subscriptions")
.DataLabels().Pie(p => p.ShowCenterLabel(false).SliceLabelContent(ChartPieSliceLabelContent.LabelAndPercent));
var automatic = variant.EndsWith("automatic", StringComparison.Ordinal);
if (automatic) chart.RadialBandAllocation(new ChartRadialBandAllocation(.18, .14));
for (var index = 0; index < 2; index++) {
var values = index == 0 ? new[] { 60d, 30 } : new[] { 40d, 80 };
var series = new ChartSeries(new ChartSeriesId(index == 0 ? "prior" : "current"), index == 0 ? "Prior period" : "Current period", ChartSeriesKind.Donut,
values.Select((value, category) => new ChartPoint(category + 1, value)))
.ObservationIds(new[] { new ChartObservationId("consulting"), new ChartObservationId("subscriptions") })
.PointSliceOffset(index, index == 0 ? .16 : .1);
if (!automatic) series.RadialBand(index == 0 ? new ChartRadialBand(.18, .48) : new ChartRadialBand(.62, 1));
series.DataLabelPlacement = variant.EndsWith("vertical", StringComparison.Ordinal) ? ChartDataLabelPlacement.Above
: variant.EndsWith("mixed", StringComparison.Ordinal) && index == 1 ? ChartDataLabelPlacement.Below : ChartDataLabelPlacement.Outside;
chart.AddSeries(series);
}
return chart;
}
}