# Findings by category · Donut

Preview

![Findings by category](donut-explicit-series-light.png)

![Findings by category](donut-explicit-series-dark.png)

800 × 440 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](donut-explicit-series-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 = FindingsRecipe.Create("explicit-series", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Findings by category", "Open findings from the October assessment", 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>Open assessment findings by category with explicit zero, empty, dense and semantic-color variants.</summary>
public static class FindingsRecipe {
    private static readonly (string Name, string Long, double Count)[] Categories = {
        ("Patching", "Missing security updates on servers", 46), ("Identity", "Stale and over-privileged accounts", 38),
        ("Certificates", "Certificates expiring within 30 days", 27), ("Network", "Exposed management ports", 21),
        ("Backups", "Backups without a recent restore test", 17), ("Logging", "Audit logging disabled or incomplete", 12),
        ("Encryption", "Unencrypted data at rest", 8)
    };

    private static readonly string[] DenseCategories = {
        "Patching", "Identity", "Certificates", "Network", "Backups", "Logging", "Encryption", "DNS", "Firewall", "Endpoints",
        "Mail flow", "Licensing", "Monitoring", "Replication", "Group Policy", "Service accounts", "Shares", "Printers",
        "Remote access", "Web servers", "Databases", "Hypervisors", "Storage", "Wireless"
    };

    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        var dense = variant == "dense";
        var count = variant == "empty" ? 0 : dense ? DenseCategories.Length : Categories.Length;
        // Dense findings fall off steeply, as they do in a real assessment: a few categories carry most of the work.
        double Count(int index) => dense ? Math.Round(60 * Math.Pow(.84, index)) + 1 : Categories[index].Count;
        string Name(int index) => dense ? DenseCategories[index] : variant == "wrapped-legend" ? Categories[index].Long : Categories[index].Name;
        var points = Enumerable.Range(0, count).Where(index => variant != "missing" || index is not (2 or 3))
            .Select(index => new ChartPoint(index + 1, variant == "zero" ? 0 : Count(index)));
        var findings = new ChartSeries(new ChartSeriesId("findings"), "Findings", ChartSeriesKind.Donut, points);
        if (variant is "explicit-status" or "explicit-series") {
            var colors = VisualTheme.Graphite().Resolve(mode);
            var selected = variant == "explicit-status"
                ? new[] { colors.Status.Pass.Fill, colors.Status.Medium.Fill, colors.Status.Critical.Fill }
                : colors.Palette.Take(3).ToArray();
            for (var index = 0; index < findings.Points.Count; index++) findings.PointColor(index, selected[index % selected.Length]);
        }
        return Chart.Create().XLabels(Enumerable.Range(0, count).Select(Name).ToArray()).AddSeries(findings);
    }
}
```

```
#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 = FindingsRecipe.Create("explicit-series", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Findings by category", "Open findings from the October assessment", 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>Open assessment findings by category with explicit zero, empty, dense and semantic-color variants.</summary>
public static class FindingsRecipe {
    private static readonly (string Name, string Long, double Count)[] Categories = {
        ("Patching", "Missing security updates on servers", 46), ("Identity", "Stale and over-privileged accounts", 38),
        ("Certificates", "Certificates expiring within 30 days", 27), ("Network", "Exposed management ports", 21),
        ("Backups", "Backups without a recent restore test", 17), ("Logging", "Audit logging disabled or incomplete", 12),
        ("Encryption", "Unencrypted data at rest", 8)
    };

    private static readonly string[] DenseCategories = {
        "Patching", "Identity", "Certificates", "Network", "Backups", "Logging", "Encryption", "DNS", "Firewall", "Endpoints",
        "Mail flow", "Licensing", "Monitoring", "Replication", "Group Policy", "Service accounts", "Shares", "Printers",
        "Remote access", "Web servers", "Databases", "Hypervisors", "Storage", "Wireless"
    };

    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        var dense = variant == "dense";
        var count = variant == "empty" ? 0 : dense ? DenseCategories.Length : Categories.Length;
        // Dense findings fall off steeply, as they do in a real assessment: a few categories carry most of the work.
        double Count(int index) => dense ? Math.Round(60 * Math.Pow(.84, index)) + 1 : Categories[index].Count;
        string Name(int index) => dense ? DenseCategories[index] : variant == "wrapped-legend" ? Categories[index].Long : Categories[index].Name;
        var points = Enumerable.Range(0, count).Where(index => variant != "missing" || index is not (2 or 3))
            .Select(index => new ChartPoint(index + 1, variant == "zero" ? 0 : Count(index)));
        var findings = new ChartSeries(new ChartSeriesId("findings"), "Findings", ChartSeriesKind.Donut, points);
        if (variant is "explicit-status" or "explicit-series") {
            var colors = VisualTheme.Graphite().Resolve(mode);
            var selected = variant == "explicit-status"
                ? new[] { colors.Status.Pass.Fill, colors.Status.Medium.Fill, colors.Status.Critical.Fill }
                : colors.Palette.Take(3).ToArray();
            for (var index = 0; index < findings.Points.Count; index++) findings.PointColor(index, selected[index % selected.Length]);
        }
        return Chart.Create().XLabels(Enumerable.Range(0, count).Select(Name).ToArray()).AddSeries(findings);
    }
}
```

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