← Gallery

Heatmap

Temperature across service areas

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

Preview
Temperature across service areasChart with 2 data series: Primary, Secondary.Temperature across service areasAbsolute color anchors use uneven numeric intervalsPrimaryPrimary, A: -30-30Primary, B: -20-20Primary, C: -3-3Primary, D: 00Primary, E: 2.52.5Primary, F: 55SecondarySecondary, A: 1010Secondary, B: 22.522.5Secondary, C: 4040Secondary, D: 5555ABCDEF-20-5102540Cold · -20Warm · 40Freezing · 0
Temperature across service areas
Temperature across service areasChart with 2 data series: Primary, Secondary.Temperature across service areasAbsolute color anchors use uneven numeric intervalsPrimaryPrimary, A: -30-30Primary, B: -20-20Primary, C: -3-3Primary, D: 00Primary, E: 2.52.5Primary, F: 55SecondarySecondary, A: 1010Secondary, B: 22.522.5Secondary, C: 4040Secondary, D: 5555ABCDEF-20-5102540Cold · -20Warm · 40Freezing · 0
Temperature across service areas
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 = HeatmapPositionedColorScaleRecipe.Create("positioned-color-scale", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Temperature across service areas", "Absolute color anchors use uneven numeric intervals", 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>Maps heatmap temperatures to explicitly positioned color stops.</summary>
public static class HeatmapPositionedColorScaleRecipe {
    /// <summary>Creates temperature rows with fixed color-stop positions and masked cells.</summary>
    public static Chart Create(string variant = "positioned-color-scale", VisualThemeMode mode = VisualThemeMode.Light) {
        if (variant is not ("positioned-color-scale" or "compact-positioned-color-scale")) throw new ArgumentOutOfRangeException(nameof(variant));
        var colors = VisualTheme.Graphite().Resolve(mode);
        var values = new double?[] { -30, -20, -3, 0, 2.5, 5, 10, 22.5, 40, 55, null, null };
        return Chart.Create().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))
            .WithHeatmapCellGap(3).WithHeatmapCellRadius(3)
            .WithHeatmapValueTextMode(ChartHeatmapValueTextMode.Auto).WithDataLabels()
            .WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture));
    }

    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 = HeatmapPositionedColorScaleRecipe.Create("positioned-color-scale", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Temperature across service areas", "Absolute color anchors use uneven numeric intervals", 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>Maps heatmap temperatures to explicitly positioned color stops.</summary>
public static class HeatmapPositionedColorScaleRecipe {
    /// <summary>Creates temperature rows with fixed color-stop positions and masked cells.</summary>
    public static Chart Create(string variant = "positioned-color-scale", VisualThemeMode mode = VisualThemeMode.Light) {
        if (variant is not ("positioned-color-scale" or "compact-positioned-color-scale")) throw new ArgumentOutOfRangeException(nameof(variant));
        var colors = VisualTheme.Graphite().Resolve(mode);
        var values = new double?[] { -30, -20, -3, 0, 2.5, 5, 10, 22.5, 40, 55, null, null };
        return Chart.Create().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))
            .WithHeatmapCellGap(3).WithHeatmapCellRadius(3)
            .WithHeatmapValueTextMode(ChartHeatmapValueTextMode.Auto).WithDataLabels()
            .WithValueFormat(ChartValueFormat.Number("0.##", CultureInfo.InvariantCulture));
    }

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