← 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: Standard, Priority.
Workload, time and request volume
Workload, time and request volumeChart with 2 data series: Standard, Priority.
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.

#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 = BubbleMarkerOptionsRecipe.Create("compact-options", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Workload, time and request volume", "Equal request volumes share a filled area; values above 100 retain their facts", 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>Compares standard and priority observations with independent bubble markers.</summary>
public static class BubbleMarkerOptionsRecipe {
    /// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
    public static Chart Create(string variant = "options", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("options" or "compact-options" or "custom-markers" or "compact-custom-markers"))
            throw new ArgumentOutOfRangeException(nameof(variant));
        return MarkerOptions(variant.EndsWith("custom-markers", StringComparison.Ordinal), mode);
    }

    private static Chart MarkerOptions(bool custom, ThemeMode mode) {
        var standard = ChartSeries.CreateBubble(new ChartSeriesId("standard"), "Standard", new[] {
            new ChartBubble(1, 18, 9), new ChartBubble(2, 30, 36), new ChartBubble(3, 24, 81)
        }).Markers(markers => markers.Shape = ChartMarkerShape.Circle);
        var priority = ChartSeries.CreateBubble(new ChartSeriesId("priority"), "Priority", new[] {
            new ChartBubble(1.5, 32, 16), new ChartBubble(2.5, 20, 36), new ChartBubble(3.5, 36, 200)
        }).Markers(markers => markers.Shape = ChartMarkerShape.Diamond);
        if (custom) priority.Markers(markers => {
            markers.CustomPath = ChartMarkerPath.Start(0, -1).CubicTo(1, -1, 1, 1, 0, 1)
                .CubicTo(-1, 1, -1, -1, 0, -1);
            var outline = mode == ThemeMode.Dark ? ChartColor.FromRgb(226, 232, 240) : ChartColor.FromRgb(51, 65, 85);
            markers.OutlineStroke = new ChartStrokeStyle(outline, 2, dash: new[] { 4d, 3d });
            markers.StrokeDashOffset = 1;
        });
        return Chart.Create().XAxis(x => x.Title("Workload batches")).YAxis(y => y.Title("Time (minutes)"))
            .AddSeries(standard).AddSeries(priority)
            .Bubble(bubble => {
                bubble.SizeDomain(0, 100); bubble.MinimumRadius = 0; bubble.MaximumRadius = 24;
                bubble.SizeEncoding = ChartBubbleSizeEncoding.Area;
                bubble.SizeDimension.Name = "Requests"; bubble.SizeDimension.ShowLegend = true;
            });
    }
}
#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 = BubbleMarkerOptionsRecipe.Create("compact-options", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Workload, time and request volume", "Equal request volumes share a filled area; values above 100 retain their facts", 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>Compares standard and priority observations with independent bubble markers.</summary>
public static class BubbleMarkerOptionsRecipe {
    /// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
    public static Chart Create(string variant = "options", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("options" or "compact-options" or "custom-markers" or "compact-custom-markers"))
            throw new ArgumentOutOfRangeException(nameof(variant));
        return MarkerOptions(variant.EndsWith("custom-markers", StringComparison.Ordinal), mode);
    }

    private static Chart MarkerOptions(bool custom, ThemeMode mode) {
        var standard = ChartSeries.CreateBubble(new ChartSeriesId("standard"), "Standard", new[] {
            new ChartBubble(1, 18, 9), new ChartBubble(2, 30, 36), new ChartBubble(3, 24, 81)
        }).Markers(markers => markers.Shape = ChartMarkerShape.Circle);
        var priority = ChartSeries.CreateBubble(new ChartSeriesId("priority"), "Priority", new[] {
            new ChartBubble(1.5, 32, 16), new ChartBubble(2.5, 20, 36), new ChartBubble(3.5, 36, 200)
        }).Markers(markers => markers.Shape = ChartMarkerShape.Diamond);
        if (custom) priority.Markers(markers => {
            markers.CustomPath = ChartMarkerPath.Start(0, -1).CubicTo(1, -1, 1, 1, 0, 1)
                .CubicTo(-1, 1, -1, -1, 0, -1);
            var outline = mode == ThemeMode.Dark ? ChartColor.FromRgb(226, 232, 240) : ChartColor.FromRgb(51, 65, 85);
            markers.OutlineStroke = new ChartStrokeStyle(outline, 2, dash: new[] { 4d, 3d });
            markers.StrokeDashOffset = 1;
        });
        return Chart.Create().XAxis(x => x.Title("Workload batches")).YAxis(y => y.Title("Time (minutes)"))
            .AddSeries(standard).AddSeries(priority)
            .Bubble(bubble => {
                bubble.SizeDomain(0, 100); bubble.MinimumRadius = 0; bubble.MaximumRadius = 24;
                bubble.SizeEncoding = ChartBubbleSizeEncoding.Area;
                bubble.SizeDimension.Name = "Requests"; bubble.SizeDimension.ShowLegend = true;
            });
    }
}