← Gallery

Donut

Findings by category

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

Preview
Findings by categoryChart with 1 data series: Findings.Findings by categoryOne prepared scene for SVG and native PNGDay 718.7%38Day 617.2%35Day 515.8%32Day 414.3%29Day 312.8%26Other21.2%43203Findings
Findings by category
Findings by categoryChart with 1 data series: Findings.Findings by categoryOne prepared scene for SVG and native PNGDay 718.7%38Day 617.2%35Day 515.8%32Day 414.3%29Day 312.8%26Other21.2%43203Findings
Findings by category
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 and copy the gallery’s fonts directory beside your program.

using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
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 = VisualThemeMode.Light;
var theme = VisualTheme.Graphite();
var model = FindingsRecipe.Create("compact", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Findings by category", "One prepared scene for SVG and native PNG", 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());

/// <summary>Findings by category with explicit zero, empty, dense and semantic-color variants.</summary>
public static class FindingsRecipe {
    public static Chart Create(string variant = "wide", VisualThemeMode mode = VisualThemeMode.Light) {
        var count = variant == "empty" ? 0 : variant == "dense" ? 24 : 7;
        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 : 20 + index * 3 % 23));
        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.WithPointColor(index, selected[index % selected.Length]);
        }
        return Chart.Create().WithXLabels(Enumerable.Range(1, count).Select(index => variant == "wrapped-legend"
            ? "Assessment category " + index + " requiring follow-up" : "Day " + index).ToArray()).AddSeries(findings);
    }
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
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 = VisualThemeMode.Dark;
var theme = VisualTheme.Graphite();
var model = FindingsRecipe.Create("compact", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Findings by category", "One prepared scene for SVG and native PNG", 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());

/// <summary>Findings by category with explicit zero, empty, dense and semantic-color variants.</summary>
public static class FindingsRecipe {
    public static Chart Create(string variant = "wide", VisualThemeMode mode = VisualThemeMode.Light) {
        var count = variant == "empty" ? 0 : variant == "dense" ? 24 : 7;
        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 : 20 + index * 3 % 23));
        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.WithPointColor(index, selected[index % selected.Length]);
        }
        return Chart.Create().WithXLabels(Enumerable.Range(1, count).Select(index => variant == "wrapped-legend"
            ? "Assessment category " + index + " requiring follow-up" : "Day " + index).ToArray()).AddSeries(findings);
    }
}