# Daily average temperature · Calendar Heatmap

Preview

![Daily average temperature](family-calendar-heatmap-compact-color-dimension-light.png)

![Daily average temperature](family-calendar-heatmap-compact-color-dimension-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-calendar-heatmap-compact-color-dimension-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 = CalendarHeatmapColorDimensionRecipe.Create("compact-color-dimension", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Daily average temperature", "Temperature captions use their own format and culture", 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 daily temperature independently from the calendar's numeric observations.</summary>
public static class CalendarHeatmapColorDimensionRecipe {
    /// <summary>Creates a temperature calendar with Polish number formatting and a named color dimension.</summary>
    public static Chart Create(string variant = "color-dimension", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("color-dimension" or "compact-color-dimension")) throw new ArgumentOutOfRangeException(nameof(variant));
        var colors = VisualTheme.Graphite().Resolve(mode);
        return Chart.Create().Labels(labels => labels.NoData = "Not sampled")
            .Calendar(options => options.FirstDayOfWeek = DayOfWeek.Monday)
            .AddCalendarHeatmap("Daily mean", Enumerable.Range(0, 120)
                .Where(index => index % 7 != 0 && index % 9 != 0)
                .Select(index => new ChartCalendarHeatmapItem(new DateTime(2026, 1, 1).AddDays(index), index * 2.5 % 13)),
                id: new ChartSeriesId("daily-mean"))
            .Heatmap(h => h.ColorScale(ChartColorScale.Sequential(colors.SequentialRamp).WithValueRange(0, 12)
                .WithLabels("Cool", null, "Warm").WithNoDataColor(colors.Border)))
            .Heatmap(heatmap => heatmap.ColorDimension(options => {
                options.Name = "Temperature"; options.ValueFormat = ChartValueFormat.Number("#,0.### '°C'", CultureInfo.InvariantCulture);
                options.LegendStyle = ChartColorLegendStyle.Auto;
            }));
    }
}
```

```
#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 = CalendarHeatmapColorDimensionRecipe.Create("compact-color-dimension", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Daily average temperature", "Temperature captions use their own format and culture", 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 daily temperature independently from the calendar's numeric observations.</summary>
public static class CalendarHeatmapColorDimensionRecipe {
    /// <summary>Creates a temperature calendar with Polish number formatting and a named color dimension.</summary>
    public static Chart Create(string variant = "color-dimension", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("color-dimension" or "compact-color-dimension")) throw new ArgumentOutOfRangeException(nameof(variant));
        var colors = VisualTheme.Graphite().Resolve(mode);
        return Chart.Create().Labels(labels => labels.NoData = "Not sampled")
            .Calendar(options => options.FirstDayOfWeek = DayOfWeek.Monday)
            .AddCalendarHeatmap("Daily mean", Enumerable.Range(0, 120)
                .Where(index => index % 7 != 0 && index % 9 != 0)
                .Select(index => new ChartCalendarHeatmapItem(new DateTime(2026, 1, 1).AddDays(index), index * 2.5 % 13)),
                id: new ChartSeriesId("daily-mean"))
            .Heatmap(h => h.ColorScale(ChartColorScale.Sequential(colors.SequentialRamp).WithValueRange(0, 12)
                .WithLabels("Cool", null, "Warm").WithNoDataColor(colors.Border)))
            .Heatmap(heatmap => heatmap.ColorDimension(options => {
                options.Name = "Temperature"; options.ValueFormat = ChartValueFormat.Number("#,0.### '°C'", CultureInfo.InvariantCulture);
                options.LegendStyle = ChartColorLegendStyle.Auto;
            }));
    }
}
```

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