# Temperature by workload · Scatter

Preview

![Temperature by workload](family-scatter-swatch-color-legend-light.png)

![Temperature by workload](family-scatter-swatch-color-legend-dark.png)

800 × 440 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-swatch-color-legend-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 = ScatterColorDimensionRecipe.Create("swatch-color-legend", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Temperature by workload", "A sampled key keeps the continuous measurement and its color domain", 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 a temperature color dimension independently from processing time.</summary>
public static class ScatterColorDimensionRecipe {
    /// <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" or "gradient-color-legend" or "compact-gradient-color-legend" or "swatch-color-legend" or "compact-swatch-color-legend")) throw new ArgumentOutOfRangeException(nameof(variant));
        return ColorDimension(variant, mode);
    }

    private static Chart ColorDimension(string variant, ThemeMode mode) {
        var colors = VisualTheme.Graphite().Resolve(mode);
        var gradient = variant is "gradient-color-legend" or "compact-gradient-color-legend";
        var swatches = variant is "swatch-color-legend" or "compact-swatch-color-legend";
        var minutes = new[] { 18d, 30, 24, 44, 32 };
        var temperatures = new double?[] { -12, 0, null, 2.5, 22.5 };
        var recorded = ChartSeries.CreateScatter(new ChartSeriesId("recorded-batches"), "Recorded batches", temperatures.Select((value, index) =>
            new ChartPoint((index + 1) * 16, minutes[index]).WithColorValue(value)));
        recorded.ColorScale(TemperatureScale().WithNoDataColor(colors.Border)).ColorDimension(options => {
            options.Name = "Temperature";
            options.ValueFormat = ChartValueFormat.Number("#,0.### '°C'", CultureInfo.InvariantCulture);
            options.LegendStyle = gradient ? ChartColorLegendStyle.Gradient : swatches ? ChartColorLegendStyle.Swatches : 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);

    private static ChartColorScale TemperatureScale() => ChartColorScale.Diverging(new[] {
        new ChartColorStop(-20, ChartColor.FromHex("#2166AC")), new ChartColorStop(-3, ChartColor.FromHex("#67A9CF"))
    }, new ChartColorStop(0, ChartColor.FromHex("#D1D5DB")), new[] {
        new ChartColorStop(5, ChartColor.FromHex("#D9A441")), new ChartColorStop(40, ChartColor.FromHex("#B2182B"))
    }).WithLabels("Cold", "Freezing", "Warm");
}
```

```
#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 = ScatterColorDimensionRecipe.Create("swatch-color-legend", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Temperature by workload", "A sampled key keeps the continuous measurement and its color domain", 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 a temperature color dimension independently from processing time.</summary>
public static class ScatterColorDimensionRecipe {
    /// <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" or "gradient-color-legend" or "compact-gradient-color-legend" or "swatch-color-legend" or "compact-swatch-color-legend")) throw new ArgumentOutOfRangeException(nameof(variant));
        return ColorDimension(variant, mode);
    }

    private static Chart ColorDimension(string variant, ThemeMode mode) {
        var colors = VisualTheme.Graphite().Resolve(mode);
        var gradient = variant is "gradient-color-legend" or "compact-gradient-color-legend";
        var swatches = variant is "swatch-color-legend" or "compact-swatch-color-legend";
        var minutes = new[] { 18d, 30, 24, 44, 32 };
        var temperatures = new double?[] { -12, 0, null, 2.5, 22.5 };
        var recorded = ChartSeries.CreateScatter(new ChartSeriesId("recorded-batches"), "Recorded batches", temperatures.Select((value, index) =>
            new ChartPoint((index + 1) * 16, minutes[index]).WithColorValue(value)));
        recorded.ColorScale(TemperatureScale().WithNoDataColor(colors.Border)).ColorDimension(options => {
            options.Name = "Temperature";
            options.ValueFormat = ChartValueFormat.Number("#,0.### '°C'", CultureInfo.InvariantCulture);
            options.LegendStyle = gradient ? ChartColorLegendStyle.Gradient : swatches ? ChartColorLegendStyle.Swatches : 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);

    private static ChartColorScale TemperatureScale() => ChartColorScale.Diverging(new[] {
        new ChartColorStop(-20, ChartColor.FromHex("#2166AC")), new ChartColorStop(-3, ChartColor.FromHex("#67A9CF"))
    }, new ChartColorStop(0, ChartColor.FromHex("#D1D5DB")), new[] {
        new ChartColorStop(5, ChartColor.FromHex("#D9A441")), new ChartColorStop(40, ChartColor.FromHex("#B2182B"))
    }).WithLabels("Cold", "Freezing", "Warm");
}
```

<!-- PowerForge markdown artifact sha256:0554E8791F824E36F5956AD9D9A628A833F7029B8552B4FA85E4DEC7F208EF71 -->
