← Gallery

Bubble

Workload, time and request volume

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

Preview
Workload, time and request volumeChart with 2 data series: Recorded batches, Target duration.Workload, time and request volumeSize shows requests; named color bands showtemperatureRecorded batchesTarget durationRecorded batches · Temperature (°C)Not sampledNot sampledCold · < 0Cold · < 0Mild · 0 ≤ value < 15Mild · 0 ≤ value < 15Warm · ≥ 15Warm · ≥ 15020406080100Batch size (items)0204060Processing time (minutes)
Workload, time and request volume
Workload, time and request volumeChart with 2 data series: Recorded batches, Target duration.Workload, time and request volumeSize shows requests; named color bands showtemperatureRecorded batchesTarget durationRecorded batches · Temperature (°C)Not sampledNot sampledCold · < 0Cold · < 0Mild · 0 ≤ value < 15Mild · 0 ≤ value < 15Warm · ≥ 15Warm · ≥ 15020406080100Batch size (items)0204060Processing time (minutes)
Workload, time and request volume
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 = BubbleColorScaleRecipe.Create("compact-color-scale", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Workload, time and request volume", "Size shows requests; named color bands show temperature", 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>Colors request-volume bubbles by temperature and overlays a target duration.</summary>
public static class BubbleColorScaleRecipe {
    /// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
    public static Chart Create(string variant = "color-scale", VisualThemeMode mode = VisualThemeMode.Light) {
        if (variant is not ("color-scale" or "compact-color-scale")) throw new ArgumentOutOfRangeException(nameof(variant));
        return NumericColorScale(mode).WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture));
    }

    private static Chart NumericColorScale(VisualThemeMode mode) {
        var colors = VisualTheme.Graphite().Resolve(mode);
        var samples = new[] {
            new { Batch = 15d, Minutes = 28d, Requests = 9d, Temperature = (double?)-12 },
            new { Batch = 30d, Minutes = 42d, Requests = 36d, Temperature = (double?)0 },
            new { Batch = 45d, Minutes = 18d, Requests = 81d, Temperature = (double?)null },
            new { Batch = 60d, Minutes = 35d, Requests = 36d, Temperature = (double?)12 },
            new { Batch = 80d, Minutes = 22d, Requests = 120d, Temperature = (double?)35 }
        };
        var recorded = ChartSeries.CreateBubble(new ChartSeriesId("recorded-batches"), "Recorded batches",
            samples.Select(sample => new ChartBubble(sample.Batch, sample.Minutes, sample.Requests).WithColorValue(sample.Temperature)));
        recorded.WithColorScale(ChartColorScale.Discrete(new[] {
                new ChartColorBand(0, colors.Palette[0], "Cold"),
                new ChartColorBand(15, colors.Status.Medium.Fill, "Mild"),
                new ChartColorBand(null, colors.Status.Critical.Fill, "Warm")
            }).WithNoDataColor(colors.Border));
        var target = ChartSeries.CreateLine(new ChartSeriesId("target-duration"), "Target duration", new[] { new ChartPoint(0, 30), new ChartPoint(100, 30) })
            .ConfigureMarkers(markers => markers.Enabled = false);
        return NumericAxes().ConfigureLabels(labels => { labels.Color = "Temperature (°C)"; labels.NoData = "Not sampled"; })
            .AddSeries(recorded).AddSeries(target)
            .ConfigureBubble(bubble => { bubble.WithSizeDomain(0, 100); bubble.MinimumRadius = 4; bubble.MaximumRadius = 20; });
    }

    private static Chart NumericAxes() => Chart.Create().WithXAxis("Batch size (items)").WithYAxis("Processing time (minutes)")
        .WithXAxisBounds(0, 100).WithYAxisBounds(0, 60).WithDataLabels(false);
}
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 = BubbleColorScaleRecipe.Create("compact-color-scale", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Workload, time and request volume", "Size shows requests; named color bands show temperature", 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>Colors request-volume bubbles by temperature and overlays a target duration.</summary>
public static class BubbleColorScaleRecipe {
    /// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
    public static Chart Create(string variant = "color-scale", VisualThemeMode mode = VisualThemeMode.Light) {
        if (variant is not ("color-scale" or "compact-color-scale")) throw new ArgumentOutOfRangeException(nameof(variant));
        return NumericColorScale(mode).WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture));
    }

    private static Chart NumericColorScale(VisualThemeMode mode) {
        var colors = VisualTheme.Graphite().Resolve(mode);
        var samples = new[] {
            new { Batch = 15d, Minutes = 28d, Requests = 9d, Temperature = (double?)-12 },
            new { Batch = 30d, Minutes = 42d, Requests = 36d, Temperature = (double?)0 },
            new { Batch = 45d, Minutes = 18d, Requests = 81d, Temperature = (double?)null },
            new { Batch = 60d, Minutes = 35d, Requests = 36d, Temperature = (double?)12 },
            new { Batch = 80d, Minutes = 22d, Requests = 120d, Temperature = (double?)35 }
        };
        var recorded = ChartSeries.CreateBubble(new ChartSeriesId("recorded-batches"), "Recorded batches",
            samples.Select(sample => new ChartBubble(sample.Batch, sample.Minutes, sample.Requests).WithColorValue(sample.Temperature)));
        recorded.WithColorScale(ChartColorScale.Discrete(new[] {
                new ChartColorBand(0, colors.Palette[0], "Cold"),
                new ChartColorBand(15, colors.Status.Medium.Fill, "Mild"),
                new ChartColorBand(null, colors.Status.Critical.Fill, "Warm")
            }).WithNoDataColor(colors.Border));
        var target = ChartSeries.CreateLine(new ChartSeriesId("target-duration"), "Target duration", new[] { new ChartPoint(0, 30), new ChartPoint(100, 30) })
            .ConfigureMarkers(markers => markers.Enabled = false);
        return NumericAxes().ConfigureLabels(labels => { labels.Color = "Temperature (°C)"; labels.NoData = "Not sampled"; })
            .AddSeries(recorded).AddSeries(target)
            .ConfigureBubble(bubble => { bubble.WithSizeDomain(0, 100); bubble.MinimumRadius = 4; bubble.MaximumRadius = 20; });
    }

    private static Chart NumericAxes() => Chart.Create().WithXAxis("Batch size (items)").WithYAxis("Processing time (minutes)")
        .WithXAxisBounds(0, 100).WithYAxisBounds(0, 60).WithDataLabels(false);
}