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.
#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 = LollipopHorizontalRecipe.Create("compact-horizontal", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
new VisualFrame("Orders at each delivery stage", "Delivery stages share a horizontal order-count axis", 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>Compares delivery-stage orders on a physical horizontal value axis.</summary>
public static class LollipopHorizontalRecipe {
/// <summary>Creates the horizontal example through the canonical lollipop and physical-axis owners.</summary>
public static Chart Create(string variant = "horizontal", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("horizontal" or "compact-horizontal")) throw new ArgumentOutOfRangeException(nameof(variant));
var points = Enumerable.Range(1, 6).Select(index => new ChartPoint(index, 20 + index * 7 % 29));
var orders = new ChartSeries(new ChartSeriesId("orders"), "Orders", ChartSeriesKind.Lollipop, points)
.ObservationIds(new[] { "received", "packed", "shipped", "transit", "delivered", "reviewed" }.Select(id => new ChartObservationId(id)));
var chart = Chart.Create().XLabels("Received", "Packed", "Shipped", "In transit", "Delivered", "Reviewed")
.XAxis(x => x.Title("Orders")).YAxis(y => y.Title("Delivery stage")).Legend(false).AddSeries(orders)
.ValueFormat(ChartValueFormat.Number("0", CultureInfo.InvariantCulture));
chart.Options.LollipopOrientation = ChartOrientation.Horizontal;
return chart;
}
}
#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 = LollipopHorizontalRecipe.Create("compact-horizontal", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
new VisualFrame("Orders at each delivery stage", "Delivery stages share a horizontal order-count axis", 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>Compares delivery-stage orders on a physical horizontal value axis.</summary>
public static class LollipopHorizontalRecipe {
/// <summary>Creates the horizontal example through the canonical lollipop and physical-axis owners.</summary>
public static Chart Create(string variant = "horizontal", ThemeMode mode = ThemeMode.Light) {
if (variant is not ("horizontal" or "compact-horizontal")) throw new ArgumentOutOfRangeException(nameof(variant));
var points = Enumerable.Range(1, 6).Select(index => new ChartPoint(index, 20 + index * 7 % 29));
var orders = new ChartSeries(new ChartSeriesId("orders"), "Orders", ChartSeriesKind.Lollipop, points)
.ObservationIds(new[] { "received", "packed", "shipped", "transit", "delivered", "reviewed" }.Select(id => new ChartObservationId(id)));
var chart = Chart.Create().XLabels("Received", "Packed", "Shipped", "In transit", "Delivered", "Reviewed")
.XAxis(x => x.Title("Orders")).YAxis(y => y.Title("Delivery stage")).Legend(false).AddSeries(orders)
.ValueFormat(ChartValueFormat.Number("0", CultureInfo.InvariantCulture));
chart.Options.LollipopOrientation = ChartOrientation.Horizontal;
return chart;
}
}