← Gallery

Heatmap

Temperature by grid position

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

Preview
Temperature by grid positionChart with 2 data series: Primary, Secondary.Temperature by grid positionA continuous key retains every authored color anchorPrimaryPrimary, A: -30,0 °C-30,0 °CPrimary, B: -20,0 °C-20,0 °CPrimary, C: -3,0 °C-3,0 °CPrimary, D: 0,0 °C0,0 °CPrimary, E: 2,5 °C2,5 °CPrimary, F: 5,0 °C5,0 °CSecondarySecondary, A: 10,0 °C10,0 °CSecondary, B: 22,5 °C22,5 °CSecondary, C: 40,0 °C40,0 °CSecondary, D: 55,0 °C55,0 °CABCDEFTemperatureCold · -20,0 °CWarm · 40,0 °CFreezing · 0,0 °C
Temperature by grid position
Temperature by grid positionChart with 2 data series: Primary, Secondary.Temperature by grid positionA continuous key retains every authored color anchorPrimaryPrimary, A: -30,0 °C-30,0 °CPrimary, B: -20,0 °C-20,0 °CPrimary, C: -3,0 °C-3,0 °CPrimary, D: 0,0 °C0,0 °CPrimary, E: 2,5 °C2,5 °CPrimary, F: 5,0 °C5,0 °CSecondarySecondary, A: 10,0 °C10,0 °CSecondary, B: 22,5 °C22,5 °CSecondary, C: 40,0 °C40,0 °CSecondary, D: 55,0 °C55,0 °CABCDEFTemperatureCold · -20,0 °CWarm · 40,0 °CFreezing · 0,0 °C
Temperature by grid position
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 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 = HeatmapColorDimensionRecipe.Create("gradient-color-legend", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Temperature by grid position", "A continuous key retains every authored color anchor", 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>Formats heatmap temperatures with independent color-dimension captions and legends.</summary>
public static class HeatmapColorDimensionRecipe {
    /// <summary>Creates a temperature dimension with automatic, gradient or swatch legend presentation.</summary>
    public static Chart Create(string variant = "color-dimension", VisualThemeMode mode = VisualThemeMode.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));
        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 values = new double?[] { -30, -20, -3, 0, 2.5, 5, 10, 22.5, 40, 55, null, null };
        return Chart.Create().ConfigureLabels(labels => labels.NoData = "Not sampled").WithXLabels("A", "B", "C", "D", "E", "F")
            .AddHeatmapRow("Primary", values.Take(6), id: new ChartSeriesId("primary-measurements"))
            .AddHeatmapRow("Secondary", values.Skip(6), id: new ChartSeriesId("secondary-measurements"))
            .WithHeatmapColorScale(TemperatureScale().WithNoDataColor(colors.Border))
            .ConfigureHeatmapColorDimension(options => {
                options.Name = "Temperature"; options.ValueFormat = ChartValueFormat.Number("0.0 '°C'", CultureInfo.GetCultureInfo("pl-PL"));
                options.LegendStyle = gradient ? ChartColorLegendStyle.Gradient : swatches ? ChartColorLegendStyle.Swatches : ChartColorLegendStyle.Auto;
            }).WithHeatmapCellGap(3).WithHeatmapCellRadius(3).WithDataLabels();
    }

    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");
}
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 = HeatmapColorDimensionRecipe.Create("gradient-color-legend", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Temperature by grid position", "A continuous key retains every authored color anchor", 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>Formats heatmap temperatures with independent color-dimension captions and legends.</summary>
public static class HeatmapColorDimensionRecipe {
    /// <summary>Creates a temperature dimension with automatic, gradient or swatch legend presentation.</summary>
    public static Chart Create(string variant = "color-dimension", VisualThemeMode mode = VisualThemeMode.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));
        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 values = new double?[] { -30, -20, -3, 0, 2.5, 5, 10, 22.5, 40, 55, null, null };
        return Chart.Create().ConfigureLabels(labels => labels.NoData = "Not sampled").WithXLabels("A", "B", "C", "D", "E", "F")
            .AddHeatmapRow("Primary", values.Take(6), id: new ChartSeriesId("primary-measurements"))
            .AddHeatmapRow("Secondary", values.Skip(6), id: new ChartSeriesId("secondary-measurements"))
            .WithHeatmapColorScale(TemperatureScale().WithNoDataColor(colors.Border))
            .ConfigureHeatmapColorDimension(options => {
                options.Name = "Temperature"; options.ValueFormat = ChartValueFormat.Number("0.0 '°C'", CultureInfo.GetCultureInfo("pl-PL"));
                options.LegendStyle = gradient ? ChartColorLegendStyle.Gradient : swatches ? ChartColorLegendStyle.Swatches : ChartColorLegendStyle.Auto;
            }).WithHeatmapCellGap(3).WithHeatmapCellRadius(3).WithDataLabels();
    }

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