Preview


390 × 271 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.
#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 = ServerRenderedRecipe.Create("compact-support-schedule", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(390, 271)), theme, mode,
new VisualFrame("Open-ended release support", "An open fading task and an independently current row", showLegend: false, 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>Illustrative page charts with mark navigation, a current schedule row and a shared strip domain.</summary>
public static class ServerRenderedRecipe {
/// <summary>Creates a catalog model; page hosts can prepare the shared-strip variant with <see cref="SharedScale"/>.</summary>
public static Chart Create(string variant = "linked-columns", ThemeMode mode = ThemeMode.Light) => variant switch {
"linked-columns" or "compact-linked-columns" => LinkedColumns(mode, GalleryPage(mode)),
"support-schedule" or "compact-support-schedule" => SupportSchedule(mode, GalleryPage(mode)),
"shared-strip" or "compact-shared-strip" => CreateStrip(1, mode, GalleryPage(mode)),
_ => throw new ArgumentException("Unknown embedding example.", nameof(variant))
};
/// <summary>Creates five linked stacked columns. Publisher notes open separately from the local daily summaries.</summary>
public static Chart LinkedColumns(ThemeMode mode = ThemeMode.Light, string summaryPage = "") {
var updates = new[] { 8d, 12, 7, 16, 10 };
var notes = new[] { 2d, 3, 2, 4, 1 };
ChartPoint Point(int index, double value, bool publisher) {
var day = new DateTime(2026, 7, 13).AddDays(index).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
return new ChartPoint(index + 1, value).WithMarkOptions(new ChartMarkOptions(
href: publisher ? "https://github.com/EvotecIT/ChartForgeX/releases" : summaryPage + "#day-" + day,
linkTarget: publisher ? VisualSvgLinkTarget.NewContext : VisualSvgLinkTarget.SameContext,
tooltip: publisher ? "Open publisher release notes in a new tab" : "Read this day's update summary",
accessibleLabel: day + ": " + value.ToString("0", CultureInfo.InvariantCulture)
+ (publisher ? " publisher notes; opens in a new tab" : " updates; read the daily summary"),
cssClass: publisher ? "publisher-mark" : "activity-mark",
dataAttributes: new Dictionary<string, string> { ["data-day"] = day, ["data-kind"] = publisher ? "publisher" : "update" }));
}
var chart = Chart.Create().Theme(VisualTheme.Graphite()).ThemeMode(mode).Bars(b => b.Stacked().Style(ChartBarStyle.Flat))
.Legend(false).XLabels("Mon", "Tue", "Wed", "Thu", "Fri")
.YAxis(y => y.Bounds(0, 24)).YAxis(axis => { axis.TickCount = 4; axis.IntegerTicks = true; })
.AddBar("Updates", updates.Select((value, index) => Point(index, value, false)), Color("--updates", mode))
.AddBar("Publisher notes", notes.Select((value, index) => Point(index, value, true)), Color("--publisher-notes", mode));
chart.Series[0].MarkOptions(new ChartMarkOptions(cssClass: "activity-series",
dataAttributes: new Dictionary<string, string> { ["data-feed"] = "daily-updates" }));
chart.Series[1].MarkOptions(new ChartMarkOptions(cssClass: "publisher-series",
dataAttributes: new Dictionary<string, string> { ["data-feed"] = "publisher-notes" }));
return chart;
}
/// <summary>Creates three support rows, including an open task and independently current row metadata.</summary>
public static Chart SupportSchedule(ThemeMode mode = ThemeMode.Light, string summaryPage = "") {
var chart = Schedule(mode);
for (var row = 0; row < 3; row++) chart.AddSeries(SupportRow(row, mode, summaryPage));
return chart.GanttToday(new DateTime(2026, 7, 15));
}
/// <summary>Creates one support row for plot-only preparation; HTML owns the row label.</summary>
public static Chart CreateStrip(int row, ThemeMode mode = ThemeMode.Light, string summaryPage = "") =>
Schedule(mode).AddSeries(SupportRow(row, mode, summaryPage));
/// <summary>Creates an explicit 1 January 2026 to 1 January 2027 domain shared by every strip and the axis.</summary>
public static ChartStripScale SharedScale() {
var axis = new ChartAxis();
ConfigureTimeAxis(axis);
return new ChartStripScale(axis);
}
private static Chart Schedule(ThemeMode mode) => Chart.Create().Theme(VisualTheme.Graphite()).ThemeMode(mode)
.Legend(false).Gantt(g => g.OpenEndStyle(ChartGanttOpenEndStyle.Fade))
.XAxis(x => x.Bounds(new DateTime(2026, 1, 1).ToOADate(), new DateTime(2027, 1, 1).ToOADate()))
.XAxis(ConfigureTimeAxis);
private static void ConfigureTimeAxis(ChartAxis axis) {
axis.Min = new DateTime(2026, 1, 1).ToOADate(); axis.Max = new DateTime(2027, 1, 1).ToOADate();
axis.Scale = ChartScaleKind.Time; axis.TickCount = 3;
axis.ValueFormat = ChartValueFormat.Custom(value => DateTime.FromOADate(value).ToString("MMM yy", CultureInfo.InvariantCulture));
axis.Labels.Clear();
foreach (var date in new[] { new DateTime(2026, 1, 1), new DateTime(2026, 7, 1), new DateTime(2027, 1, 1) })
axis.Labels.Add(new ChartAxisLabel(date.ToOADate(), date.ToString("MMM yy", CultureInfo.InvariantCulture)));
}
private static string GalleryPage(ThemeMode mode) => "embedding/" + (mode == ThemeMode.Dark ? "dark" : "light") + ".html";
private static ChartSeries SupportRow(int row, ThemeMode mode, string summaryPage) {
var (name, key, start, end) = row switch {
0 => ("2025", "release-2025", new DateTime(2026, 1, 1), new DateTime(2026, 5, 31)),
1 => ("2026", "release-2026", new DateTime(2026, 3, 1), new DateTime(2027, 1, 1)),
2 => ("Next", "release-next", new DateTime(2026, 9, 1), new DateTime(2026, 12, 31)),
_ => throw new ArgumentOutOfRangeException(nameof(row))
};
var current = row == 1;
var item = current ? ChartGanttItem.OpenEnded(start) : new ChartGanttItem(start, end);
item = item.WithMarkOptions(new ChartMarkOptions(href: summaryPage + "#" + key,
tooltip: current ? "Current release; support has no fixed end date" : "Read this release's support summary",
accessibleLabel: name + (current ? ": support from March 2026, no fixed end date" : ": view support dates"),
cssClass: "support-mark", dataAttributes: new Dictionary<string, string> { ["data-release"] = key }));
return ChartSeries.CreateGanttTask(new ChartSeriesId(key), name, start, end, color: Color(current ? "--updates" : "--support", mode))
.ReplaceGanttItems(new[] { item })
.MarkOptions(new ChartMarkOptions(cssClass: "support-series", dataAttributes: new Dictionary<string, string> { ["data-release"] = key }))
.RowOptions(new ChartMarkOptions(href: summaryPage + "#" + key, accessibleLabel: name + (current ? ", current release" : ", support summary"),
cssClass: "support-row", dataAttributes: new Dictionary<string, string> { ["data-release"] = key }, current: current));
}
private static ChartColor Color(string token, ThemeMode mode) {
var dark = mode == ThemeMode.Dark;
return ChartColor.FromHex(token switch {
"--updates" => dark ? "#6EAEFF" : "#2A78D6",
"--publisher-notes" => dark ? "#F3B36B" : "#A95712",
_ => dark ? "#9CA7B5" : "#697789"
}).WithCssVariable(token);
}
}
#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 = ServerRenderedRecipe.Create("compact-support-schedule", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(390, 271)), theme, mode,
new VisualFrame("Open-ended release support", "An open fading task and an independently current row", showLegend: false, 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>Illustrative page charts with mark navigation, a current schedule row and a shared strip domain.</summary>
public static class ServerRenderedRecipe {
/// <summary>Creates a catalog model; page hosts can prepare the shared-strip variant with <see cref="SharedScale"/>.</summary>
public static Chart Create(string variant = "linked-columns", ThemeMode mode = ThemeMode.Light) => variant switch {
"linked-columns" or "compact-linked-columns" => LinkedColumns(mode, GalleryPage(mode)),
"support-schedule" or "compact-support-schedule" => SupportSchedule(mode, GalleryPage(mode)),
"shared-strip" or "compact-shared-strip" => CreateStrip(1, mode, GalleryPage(mode)),
_ => throw new ArgumentException("Unknown embedding example.", nameof(variant))
};
/// <summary>Creates five linked stacked columns. Publisher notes open separately from the local daily summaries.</summary>
public static Chart LinkedColumns(ThemeMode mode = ThemeMode.Light, string summaryPage = "") {
var updates = new[] { 8d, 12, 7, 16, 10 };
var notes = new[] { 2d, 3, 2, 4, 1 };
ChartPoint Point(int index, double value, bool publisher) {
var day = new DateTime(2026, 7, 13).AddDays(index).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
return new ChartPoint(index + 1, value).WithMarkOptions(new ChartMarkOptions(
href: publisher ? "https://github.com/EvotecIT/ChartForgeX/releases" : summaryPage + "#day-" + day,
linkTarget: publisher ? VisualSvgLinkTarget.NewContext : VisualSvgLinkTarget.SameContext,
tooltip: publisher ? "Open publisher release notes in a new tab" : "Read this day's update summary",
accessibleLabel: day + ": " + value.ToString("0", CultureInfo.InvariantCulture)
+ (publisher ? " publisher notes; opens in a new tab" : " updates; read the daily summary"),
cssClass: publisher ? "publisher-mark" : "activity-mark",
dataAttributes: new Dictionary<string, string> { ["data-day"] = day, ["data-kind"] = publisher ? "publisher" : "update" }));
}
var chart = Chart.Create().Theme(VisualTheme.Graphite()).ThemeMode(mode).Bars(b => b.Stacked().Style(ChartBarStyle.Flat))
.Legend(false).XLabels("Mon", "Tue", "Wed", "Thu", "Fri")
.YAxis(y => y.Bounds(0, 24)).YAxis(axis => { axis.TickCount = 4; axis.IntegerTicks = true; })
.AddBar("Updates", updates.Select((value, index) => Point(index, value, false)), Color("--updates", mode))
.AddBar("Publisher notes", notes.Select((value, index) => Point(index, value, true)), Color("--publisher-notes", mode));
chart.Series[0].MarkOptions(new ChartMarkOptions(cssClass: "activity-series",
dataAttributes: new Dictionary<string, string> { ["data-feed"] = "daily-updates" }));
chart.Series[1].MarkOptions(new ChartMarkOptions(cssClass: "publisher-series",
dataAttributes: new Dictionary<string, string> { ["data-feed"] = "publisher-notes" }));
return chart;
}
/// <summary>Creates three support rows, including an open task and independently current row metadata.</summary>
public static Chart SupportSchedule(ThemeMode mode = ThemeMode.Light, string summaryPage = "") {
var chart = Schedule(mode);
for (var row = 0; row < 3; row++) chart.AddSeries(SupportRow(row, mode, summaryPage));
return chart.GanttToday(new DateTime(2026, 7, 15));
}
/// <summary>Creates one support row for plot-only preparation; HTML owns the row label.</summary>
public static Chart CreateStrip(int row, ThemeMode mode = ThemeMode.Light, string summaryPage = "") =>
Schedule(mode).AddSeries(SupportRow(row, mode, summaryPage));
/// <summary>Creates an explicit 1 January 2026 to 1 January 2027 domain shared by every strip and the axis.</summary>
public static ChartStripScale SharedScale() {
var axis = new ChartAxis();
ConfigureTimeAxis(axis);
return new ChartStripScale(axis);
}
private static Chart Schedule(ThemeMode mode) => Chart.Create().Theme(VisualTheme.Graphite()).ThemeMode(mode)
.Legend(false).Gantt(g => g.OpenEndStyle(ChartGanttOpenEndStyle.Fade))
.XAxis(x => x.Bounds(new DateTime(2026, 1, 1).ToOADate(), new DateTime(2027, 1, 1).ToOADate()))
.XAxis(ConfigureTimeAxis);
private static void ConfigureTimeAxis(ChartAxis axis) {
axis.Min = new DateTime(2026, 1, 1).ToOADate(); axis.Max = new DateTime(2027, 1, 1).ToOADate();
axis.Scale = ChartScaleKind.Time; axis.TickCount = 3;
axis.ValueFormat = ChartValueFormat.Custom(value => DateTime.FromOADate(value).ToString("MMM yy", CultureInfo.InvariantCulture));
axis.Labels.Clear();
foreach (var date in new[] { new DateTime(2026, 1, 1), new DateTime(2026, 7, 1), new DateTime(2027, 1, 1) })
axis.Labels.Add(new ChartAxisLabel(date.ToOADate(), date.ToString("MMM yy", CultureInfo.InvariantCulture)));
}
private static string GalleryPage(ThemeMode mode) => "embedding/" + (mode == ThemeMode.Dark ? "dark" : "light") + ".html";
private static ChartSeries SupportRow(int row, ThemeMode mode, string summaryPage) {
var (name, key, start, end) = row switch {
0 => ("2025", "release-2025", new DateTime(2026, 1, 1), new DateTime(2026, 5, 31)),
1 => ("2026", "release-2026", new DateTime(2026, 3, 1), new DateTime(2027, 1, 1)),
2 => ("Next", "release-next", new DateTime(2026, 9, 1), new DateTime(2026, 12, 31)),
_ => throw new ArgumentOutOfRangeException(nameof(row))
};
var current = row == 1;
var item = current ? ChartGanttItem.OpenEnded(start) : new ChartGanttItem(start, end);
item = item.WithMarkOptions(new ChartMarkOptions(href: summaryPage + "#" + key,
tooltip: current ? "Current release; support has no fixed end date" : "Read this release's support summary",
accessibleLabel: name + (current ? ": support from March 2026, no fixed end date" : ": view support dates"),
cssClass: "support-mark", dataAttributes: new Dictionary<string, string> { ["data-release"] = key }));
return ChartSeries.CreateGanttTask(new ChartSeriesId(key), name, start, end, color: Color(current ? "--updates" : "--support", mode))
.ReplaceGanttItems(new[] { item })
.MarkOptions(new ChartMarkOptions(cssClass: "support-series", dataAttributes: new Dictionary<string, string> { ["data-release"] = key }))
.RowOptions(new ChartMarkOptions(href: summaryPage + "#" + key, accessibleLabel: name + (current ? ", current release" : ", support summary"),
cssClass: "support-row", dataAttributes: new Dictionary<string, string> { ["data-release"] = key }, current: current));
}
private static ChartColor Color(string token, ThemeMode mode) {
var dark = mode == ThemeMode.Dark;
return ChartColor.FromHex(token switch {
"--updates" => dark ? "#6EAEFF" : "#2A78D6",
"--publisher-notes" => dark ? "#F3B36B" : "#A95712",
_ => dark ? "#9CA7B5" : "#697789"
}).WithCssVariable(token);
}
}