← Gallery

Bubble

Workload, requests and temperature

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

Preview
Workload, requests and temperatureChart with 1 data series: Recorded batches.Not sampledCold < 0 °CMild 0 °C–15 °CWarm ≥ 15 °C
Workload, requests and temperature
Workload, requests and temperatureChart with 1 data series: Recorded batches.Not sampledCold < 0 °CMild 0 °C–15 °CWarm ≥ 15 °C
Workload, requests and temperature
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.

#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 = BubbleColorDimensionRecipe.Create("compact-color-dimension", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Workload, requests and temperature", "Temperature captions use their own format and culture", 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>Formats bubble temperature separately from processing time and request volume.</summary>
public static class BubbleColorDimensionRecipe {
    /// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
    public static Chart Create(string variant = "color-dimension", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("color-dimension" or "compact-color-dimension")) throw new ArgumentOutOfRangeException(nameof(variant));
        return ColorDimension(mode);
    }

    private static Chart ColorDimension(ThemeMode mode) {
        var colors = VisualTheme.Graphite().Resolve(mode);
        var minutes = new[] { 18d, 30, 24, 44, 32 };
        var temperatures = new double?[] { -12, 0, null, 2.5, 22.5 };
        var sizes = new[] { 9d, 36, 81, 49, 25 };
        var recorded = ChartSeries.CreateBubble(new ChartSeriesId("recorded-batches"), "Recorded batches", temperatures.Select((value, index) =>
            new ChartBubble((index + 1) * 16, minutes[index], sizes[index]).WithColorValue(value)));
        recorded.ColorScale(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)).ColorDimension(options => {
                options.Name = "Temperature";
                options.ValueFormat = ChartValueFormat.Number("#,0.### '°C'", CultureInfo.InvariantCulture);
                options.LegendStyle = ChartColorLegendStyle.Auto;
            });
        return NumericAxes().Labels(labels => labels.NoData = "Not sampled")
            .ValueFormat(ChartValueFormat.Number("0.0 'min'", CultureInfo.InvariantCulture)).AddSeries(recorded);
    }

    private static Chart NumericAxes() => Chart.Create().XAxis(x => x.Title("Batch size (items)")).YAxis(y => y.Title("Processing time (minutes)"))
        .XAxis(x => x.Bounds(0, 100)).YAxis(y => y.Bounds(0, 60)).DataLabels(false);
}
#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 = BubbleColorDimensionRecipe.Create("compact-color-dimension", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Workload, requests and temperature", "Temperature captions use their own format and culture", 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>Formats bubble temperature separately from processing time and request volume.</summary>
public static class BubbleColorDimensionRecipe {
    /// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
    public static Chart Create(string variant = "color-dimension", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("color-dimension" or "compact-color-dimension")) throw new ArgumentOutOfRangeException(nameof(variant));
        return ColorDimension(mode);
    }

    private static Chart ColorDimension(ThemeMode mode) {
        var colors = VisualTheme.Graphite().Resolve(mode);
        var minutes = new[] { 18d, 30, 24, 44, 32 };
        var temperatures = new double?[] { -12, 0, null, 2.5, 22.5 };
        var sizes = new[] { 9d, 36, 81, 49, 25 };
        var recorded = ChartSeries.CreateBubble(new ChartSeriesId("recorded-batches"), "Recorded batches", temperatures.Select((value, index) =>
            new ChartBubble((index + 1) * 16, minutes[index], sizes[index]).WithColorValue(value)));
        recorded.ColorScale(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)).ColorDimension(options => {
                options.Name = "Temperature";
                options.ValueFormat = ChartValueFormat.Number("#,0.### '°C'", CultureInfo.InvariantCulture);
                options.LegendStyle = ChartColorLegendStyle.Auto;
            });
        return NumericAxes().Labels(labels => labels.NoData = "Not sampled")
            .ValueFormat(ChartValueFormat.Number("0.0 'min'", CultureInfo.InvariantCulture)).AddSeries(recorded);
    }

    private static Chart NumericAxes() => Chart.Create().XAxis(x => x.Title("Batch size (items)")).YAxis(y => y.Title("Processing time (minutes)"))
        .XAxis(x => x.Bounds(0, 100)).YAxis(y => y.Bounds(0, 60)).DataLabels(false);
}