← Gallery

Error Bar

Delivery time and uncertainty

Explore the example, download the output or use the C# source in your own project.

Preview
Delivery time and uncertaintyChart with 2 data series: Domestic, International.
Delivery time and uncertainty
Delivery time and uncertaintyChart with 2 data series: Domestic, International.
Delivery time and uncertainty
800 × 440 pixels

Create this example

Create a console project, add the ChartForgeX and ChartForgeX.Interactivity.Html packages, 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 = ErrorBarRecipe.Create("wide", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Delivery time and uncertainty", "Median hours with the 10th\u201390th percentile range; same day is domestic only", 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>Builds domestic and international delivery times with their 10th to 90th percentile range.</summary>
public static class ErrorBarRecipe {
    /// <summary>Creates the selected error-bar example from typed measurements.</summary>
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "compact" or "sparse" or "options" or "compact-options"))
            throw new ArgumentOutOfRangeException(nameof(variant));
        var chart = Chart.Create().XLabels("Same day", "Premium", "Express", "Standard", "Return", "Bulk").YAxis(y => y.Title("Delivery time (hours)"));
        if (variant == "sparse") {
            return chart.AddSeries(ChartSeries.CreateErrorBar(new ChartSeriesId("domestic"), "Domestic", new[] {
                new ChartErrorBar(1, 7, yBounds: new ChartErrorBounds(5, 10)), new ChartErrorBar(2, 14, yBounds: new ChartErrorBounds(10, 20)) }));
        }
        // Median hours per service; each pair sits either side of its category. Same-day delivery is domestic only.
        var domestic = ChartSeries.CreateErrorBar(new ChartSeriesId("domestic"), "Domestic", new[] {
            new ChartErrorBar(.86, 7, yBounds: new ChartErrorBounds(5, 10)), new ChartErrorBar(1.86, 14, yBounds: new ChartErrorBounds(10, 20)),
            new ChartErrorBar(2.86, 26, yBounds: new ChartErrorBounds(19, 35)), new ChartErrorBar(3.86, 52, yBounds: new ChartErrorBounds(38, 70)),
            new ChartErrorBar(4.86, 61, yBounds: new ChartErrorBounds(44, 86)), new ChartErrorBar(5.86, 78, yBounds: new ChartErrorBounds(58, 104)) });
        var international = ChartSeries.CreateErrorBar(new ChartSeriesId("international"), "International", new[] {
            new ChartErrorBar(2.14, 33, yBounds: new ChartErrorBounds(24, 46)), new ChartErrorBar(3.14, 54, yBounds: new ChartErrorBounds(40, 74)),
            new ChartErrorBar(4.14, 118, yBounds: new ChartErrorBounds(86, 160)), new ChartErrorBar(5.14, 132, yBounds: new ChartErrorBounds(96, 180)),
            new ChartErrorBar(6.14, 160, yBounds: new ChartErrorBounds(120, 214)) });
        // Delivery takes no negative time, so the scale starts at zero rather than below the shortest range.
        chart.Options.YAxis.Min = 0;
        return chart.AddSeries(domestic).AddSeries(international);
    }
}
#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 = ErrorBarRecipe.Create("wide", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(800, 440)), theme, mode,
    new VisualFrame("Delivery time and uncertainty", "Median hours with the 10th\u201390th percentile range; same day is domestic only", 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>Builds domestic and international delivery times with their 10th to 90th percentile range.</summary>
public static class ErrorBarRecipe {
    /// <summary>Creates the selected error-bar example from typed measurements.</summary>
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "compact" or "sparse" or "options" or "compact-options"))
            throw new ArgumentOutOfRangeException(nameof(variant));
        var chart = Chart.Create().XLabels("Same day", "Premium", "Express", "Standard", "Return", "Bulk").YAxis(y => y.Title("Delivery time (hours)"));
        if (variant == "sparse") {
            return chart.AddSeries(ChartSeries.CreateErrorBar(new ChartSeriesId("domestic"), "Domestic", new[] {
                new ChartErrorBar(1, 7, yBounds: new ChartErrorBounds(5, 10)), new ChartErrorBar(2, 14, yBounds: new ChartErrorBounds(10, 20)) }));
        }
        // Median hours per service; each pair sits either side of its category. Same-day delivery is domestic only.
        var domestic = ChartSeries.CreateErrorBar(new ChartSeriesId("domestic"), "Domestic", new[] {
            new ChartErrorBar(.86, 7, yBounds: new ChartErrorBounds(5, 10)), new ChartErrorBar(1.86, 14, yBounds: new ChartErrorBounds(10, 20)),
            new ChartErrorBar(2.86, 26, yBounds: new ChartErrorBounds(19, 35)), new ChartErrorBar(3.86, 52, yBounds: new ChartErrorBounds(38, 70)),
            new ChartErrorBar(4.86, 61, yBounds: new ChartErrorBounds(44, 86)), new ChartErrorBar(5.86, 78, yBounds: new ChartErrorBounds(58, 104)) });
        var international = ChartSeries.CreateErrorBar(new ChartSeriesId("international"), "International", new[] {
            new ChartErrorBar(2.14, 33, yBounds: new ChartErrorBounds(24, 46)), new ChartErrorBar(3.14, 54, yBounds: new ChartErrorBounds(40, 74)),
            new ChartErrorBar(4.14, 118, yBounds: new ChartErrorBounds(86, 160)), new ChartErrorBar(5.14, 132, yBounds: new ChartErrorBounds(96, 180)),
            new ChartErrorBar(6.14, 160, yBounds: new ChartErrorBounds(120, 214)) });
        // Delivery takes no negative time, so the scale starts at zero rather than below the shortest range.
        chart.Options.YAxis.Min = 0;
        return chart.AddSeries(domestic).AddSeries(international);
    }
}