Preview


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 = BubbleColorDimensionRecipe.Create("color-dimension", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
new VisualFrame("Workload, requests and 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());
/// <summary>Formats bubble temperature separately from processing time and request volume.</summary>
public static class BubbleColorDimensionRecipe {
/// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
public static Chart Create(string variant = "color-dimension", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("color-dimension" or "compact-color-dimension")) throw new ArgumentOutOfRangeException(nameof(variant));
return ColorDimension(mode);
}
private static Chart ColorDimension(VisualThemeMode mode) {
var colors = VisualTheme.Graphite().Resolve(mode);
var minutes = new[] { 18d, 30, 24, 44, 32 };
var temperatures = new double?[] { -12, 0, null, 2.5, 22.5 };
var sizes = new[] { 9d, 36, 81, 49, 25 };
var recorded = ChartSeries.CreateBubble(new ChartSeriesId("recorded-batches"), "Recorded batches", temperatures.Select((value, index) =>
new ChartBubble((index + 1) * 16, minutes[index], sizes[index]).WithColorValue(value)));
recorded.WithColorScale(ChartColorScale.Discrete(new[] {
new ChartColorBand(0, colors.Palette[0], "Cold"),
new ChartColorBand(15, colors.Status.Medium.Fill, "Mild"),
new ChartColorBand(null, colors.Status.Critical.Fill, "Warm")
}).WithNoDataColor(colors.Border)).ConfigureColorDimension(options => {
options.Name = "Temperature";
options.ValueFormat = ChartValueFormat.Number("0.0 '°C'", CultureInfo.GetCultureInfo("pl-PL"));
options.LegendStyle = ChartColorLegendStyle.Auto;
});
return NumericAxes().ConfigureLabels(labels => labels.NoData = "Not sampled")
.WithValueFormat(ChartValueFormat.Number("0.0 'min'", CultureInfo.InvariantCulture)).AddSeries(recorded);
}
private static Chart NumericAxes() => Chart.Create().WithXAxis("Batch size (items)").WithYAxis("Processing time (minutes)")
.WithXAxisBounds(0, 100).WithYAxisBounds(0, 60).WithDataLabels(false);
}
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 = BubbleColorDimensionRecipe.Create("color-dimension", mode);
var context = new VisualRenderContext(
new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
new VisualFrame("Workload, requests and 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());
/// <summary>Formats bubble temperature separately from processing time and request volume.</summary>
public static class BubbleColorDimensionRecipe {
/// <summary>Creates the selected example without choosing a renderer or export backend.</summary>
public static Chart Create(string variant = "color-dimension", VisualThemeMode mode = VisualThemeMode.Light) {
if (variant is not ("color-dimension" or "compact-color-dimension")) throw new ArgumentOutOfRangeException(nameof(variant));
return ColorDimension(mode);
}
private static Chart ColorDimension(VisualThemeMode mode) {
var colors = VisualTheme.Graphite().Resolve(mode);
var minutes = new[] { 18d, 30, 24, 44, 32 };
var temperatures = new double?[] { -12, 0, null, 2.5, 22.5 };
var sizes = new[] { 9d, 36, 81, 49, 25 };
var recorded = ChartSeries.CreateBubble(new ChartSeriesId("recorded-batches"), "Recorded batches", temperatures.Select((value, index) =>
new ChartBubble((index + 1) * 16, minutes[index], sizes[index]).WithColorValue(value)));
recorded.WithColorScale(ChartColorScale.Discrete(new[] {
new ChartColorBand(0, colors.Palette[0], "Cold"),
new ChartColorBand(15, colors.Status.Medium.Fill, "Mild"),
new ChartColorBand(null, colors.Status.Critical.Fill, "Warm")
}).WithNoDataColor(colors.Border)).ConfigureColorDimension(options => {
options.Name = "Temperature";
options.ValueFormat = ChartValueFormat.Number("0.0 '°C'", CultureInfo.GetCultureInfo("pl-PL"));
options.LegendStyle = ChartColorLegendStyle.Auto;
});
return NumericAxes().ConfigureLabels(labels => labels.NoData = "Not sampled")
.WithValueFormat(ChartValueFormat.Number("0.0 'min'", CultureInfo.InvariantCulture)).AddSeries(recorded);
}
private static Chart NumericAxes() => Chart.Create().WithXAxis("Batch size (items)").WithYAxis("Processing time (minutes)")
.WithXAxisBounds(0, 100).WithYAxisBounds(0, 60).WithDataLabels(false);
}