# Service mix across two periods · Donut

Preview

![Service mix across two periods](family-donut-compact-concentric-light.png)

![Service mix across two periods](family-donut-compact-concentric-dark.png)

360 × 360 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](family-donut-compact-concentric-light.gallery.csharp.txt) 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 = ConcentricPieRecipe.Create("compact-concentric", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), 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

/// <summary>Two independent service mixes in explicit concentric Pie and Donut bands.</summary>
public static class ConcentricPieRecipe {
    /// <summary>Creates independent totals and source identities without implying equal totals across rings.</summary>
    public static Chart Create(string variant = "concentric", ThemeMode mode = ThemeMode.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) })
            .RadialBand(new ChartRadialBand(.22, .52))
            .ObservationIds(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) })
            .RadialBand(new ChartRadialBand(.66, 1))
            .ObservationIds(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().XLabels("Subscriptions", "Consulting").DataLabels()
            .Pie(p => p.SliceLabelContent(ChartPieSliceLabelContent.Percent).ShowCenterLabel(false))
            .AddSeries(prior).AddSeries(current);
    }
}
```

```
#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 = ConcentricPieRecipe.Create("compact-concentric", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), 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

/// <summary>Two independent service mixes in explicit concentric Pie and Donut bands.</summary>
public static class ConcentricPieRecipe {
    /// <summary>Creates independent totals and source identities without implying equal totals across rings.</summary>
    public static Chart Create(string variant = "concentric", ThemeMode mode = ThemeMode.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) })
            .RadialBand(new ChartRadialBand(.22, .52))
            .ObservationIds(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) })
            .RadialBand(new ChartRadialBand(.66, 1))
            .ObservationIds(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().XLabels("Subscriptions", "Consulting").DataLabels()
            .Pie(p => p.SliceLabelContent(ChartPieSliceLabelContent.Percent).ShowCenterLabel(false))
            .AddSeries(prior).AddSeries(current);
    }
}
```

<!-- PowerForge markdown artifact sha256:FA8E594199BE656B9C3003F6515EB250D1E7358D20ACD726CDFF93625F629B94 -->
