# Processing time by workload · Scatter

Preview

![Processing time by workload](family-scatter-compact-color-scale-light.png)

![Processing time by workload](family-scatter-compact-color-scale-dark.png)

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](family-scatter-compact-color-scale-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 = ScatterColorScaleRecipe.Create("compact-color-scale", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Processing time by workload", "Temperature has its own fixed color domain; processing time stays independent", 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>Colors processing observations by temperature and overlays a target duration.</summary>
public static class ScatterColorScaleRecipe {
    /// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
    public static Chart Create(string variant = "color-scale", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("color-scale" or "compact-color-scale")) throw new ArgumentOutOfRangeException(nameof(variant));
        return NumericColorScale(mode);
    }

    private static Chart NumericColorScale(ThemeMode mode) {
        var colors = VisualTheme.Graphite().Resolve(mode);
        var samples = new[] {
            new { Batch = 15d, Minutes = 28d, Temperature = (double?)-12 },
            new { Batch = 30d, Minutes = 42d, Temperature = (double?)0 },
            new { Batch = 45d, Minutes = 18d, Temperature = (double?)null },
            new { Batch = 60d, Minutes = 35d, Temperature = (double?)12 },
            new { Batch = 80d, Minutes = 22d, Temperature = (double?)35 }
        };
        var recorded = ChartSeries.CreateScatter(new ChartSeriesId("recorded-batches"), "Recorded batches",
            samples.Select(sample => new ChartPoint(sample.Batch, sample.Minutes).WithColorValue(sample.Temperature)));
        recorded.ColorScale(ChartColorScale.Diverging(new[] { colors.Palette[0] }, colors.Surface,
                new[] { ChartColor.FromHex("#D9A441"), ChartColor.FromHex("#CF6A42"), colors.Status.Critical.Fill }, 0)
                .WithValueRange(-15, 30).WithLabels("Cold", "Freezing", "Warm").WithNoDataColor(colors.Border));
        var target = ChartSeries.CreateLine(new ChartSeriesId("target-duration"), "Target duration", new[] { new ChartPoint(0, 30), new ChartPoint(100, 30) })
            .Markers(markers => markers.Enabled = false);
        return NumericAxes().Labels(labels => { labels.Color = "Temperature (°C)"; labels.NoData = "Not sampled"; })
            .AddSeries(recorded).AddSeries(target);
    }

    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 = ScatterColorScaleRecipe.Create("compact-color-scale", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Processing time by workload", "Temperature has its own fixed color domain; processing time stays independent", 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>Colors processing observations by temperature and overlays a target duration.</summary>
public static class ScatterColorScaleRecipe {
    /// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
    public static Chart Create(string variant = "color-scale", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("color-scale" or "compact-color-scale")) throw new ArgumentOutOfRangeException(nameof(variant));
        return NumericColorScale(mode);
    }

    private static Chart NumericColorScale(ThemeMode mode) {
        var colors = VisualTheme.Graphite().Resolve(mode);
        var samples = new[] {
            new { Batch = 15d, Minutes = 28d, Temperature = (double?)-12 },
            new { Batch = 30d, Minutes = 42d, Temperature = (double?)0 },
            new { Batch = 45d, Minutes = 18d, Temperature = (double?)null },
            new { Batch = 60d, Minutes = 35d, Temperature = (double?)12 },
            new { Batch = 80d, Minutes = 22d, Temperature = (double?)35 }
        };
        var recorded = ChartSeries.CreateScatter(new ChartSeriesId("recorded-batches"), "Recorded batches",
            samples.Select(sample => new ChartPoint(sample.Batch, sample.Minutes).WithColorValue(sample.Temperature)));
        recorded.ColorScale(ChartColorScale.Diverging(new[] { colors.Palette[0] }, colors.Surface,
                new[] { ChartColor.FromHex("#D9A441"), ChartColor.FromHex("#CF6A42"), colors.Status.Critical.Fill }, 0)
                .WithValueRange(-15, 30).WithLabels("Cold", "Freezing", "Warm").WithNoDataColor(colors.Border));
        var target = ChartSeries.CreateLine(new ChartSeriesId("target-duration"), "Target duration", new[] { new ChartPoint(0, 30), new ChartPoint(100, 30) })
            .Markers(markers => markers.Enabled = false);
        return NumericAxes().Labels(labels => { labels.Color = "Temperature (°C)"; labels.NoData = "Not sampled"; })
            .AddSeries(recorded).AddSeries(target);
    }

    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);
}
```

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