← Gallery

Donut

Service shares with authored radii

Explore the example, download the output or use the C# source in your own project.

Preview
Service shares with authored radiiChart with 1 data series: Services.
Service shares with authored radii
Service shares with authored radiiChart with 1 data series: Services.
Service shares with authored radii
390 × 480 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 = 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));
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>Authored Donut radii remain independent of each value's angular share.</summary>
public static class DonutSliceRadiusRecipe {
    /// <summary>Creates service shares with explicit source identities and normalized band-relative radii.</summary>
    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);
    }
}
#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 = 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));
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>Authored Donut radii remain independent of each value's angular share.</summary>
public static class DonutSliceRadiusRecipe {
    /// <summary>Creates service shares with explicit source identities and normalized band-relative radii.</summary>
    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);
    }
}