Preview


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 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 = TileMapPartialColorRangeRecipe.Create("compact-partial-color-range", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
new VisualFrame("Requests by state", "Zero stays fixed; the color peak follows reported counts", 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>Creates a tile map with a fixed zero and an observed upper color bound.</summary>
public static class TileMapPartialColorRangeRecipe {
/// <summary>Creates the source model for a gallery variant without choosing an export backend.</summary>
public static Chart Create(string variant = "partial-color-range", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("partial-color-range" or "compact-partial-color-range"))
throw new ArgumentOutOfRangeException(nameof(variant));
var colors = VisualTheme.Graphite().Resolve(mode);
var codes = new[] { "CA", "TX", "NY", "FL", "WA", "IL" };
var counts = new[] { 0d, 18, 42, 76, 29, 51 };
return Chart.Create().ConfigureLabels(labels => labels.NoData = "Not reported")
.AddTileMap("Requests", ChartTileMapCatalog.Get("us-states"),
codes.Select((code, index) => new ChartRegionMapItem(code, counts[index])), id: new ChartSeriesId("state-requests"))
.WithMapLabels()
.WithMapColorScale(ChartColorScale.Sequential(colors.SequentialRamp)
.WithValueRange(0, null).WithLabels("None", null, "Observed peak").WithNoDataColor(colors.Border))
.ConfigureMapColorDimension(options => {
options.Name = "Requests";
options.ValueFormat = ChartValueFormat.Number("0", System.Globalization.CultureInfo.InvariantCulture);
options.LegendStyle = ChartColorLegendStyle.Gradient;
})
.WithValueFormat(ChartValueFormat.Number("0.##", System.Globalization.CultureInfo.InvariantCulture));
}
}
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 = TileMapPartialColorRangeRecipe.Create("compact-partial-color-range", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
new VisualFrame("Requests by state", "Zero stays fixed; the color peak follows reported counts", 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>Creates a tile map with a fixed zero and an observed upper color bound.</summary>
public static class TileMapPartialColorRangeRecipe {
/// <summary>Creates the source model for a gallery variant without choosing an export backend.</summary>
public static Chart Create(string variant = "partial-color-range", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("partial-color-range" or "compact-partial-color-range"))
throw new ArgumentOutOfRangeException(nameof(variant));
var colors = VisualTheme.Graphite().Resolve(mode);
var codes = new[] { "CA", "TX", "NY", "FL", "WA", "IL" };
var counts = new[] { 0d, 18, 42, 76, 29, 51 };
return Chart.Create().ConfigureLabels(labels => labels.NoData = "Not reported")
.AddTileMap("Requests", ChartTileMapCatalog.Get("us-states"),
codes.Select((code, index) => new ChartRegionMapItem(code, counts[index])), id: new ChartSeriesId("state-requests"))
.WithMapLabels()
.WithMapColorScale(ChartColorScale.Sequential(colors.SequentialRamp)
.WithValueRange(0, null).WithLabels("None", null, "Observed peak").WithNoDataColor(colors.Border))
.ConfigureMapColorDimension(options => {
options.Name = "Requests";
options.ValueFormat = ChartValueFormat.Number("0", System.Globalization.CultureInfo.InvariantCulture);
options.LegendStyle = ChartColorLegendStyle.Gradient;
})
.WithValueFormat(ChartValueFormat.Number("0.##", System.Globalization.CultureInfo.InvariantCulture));
}
}