← Gallery

Line

Requests, X 2–8

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

Preview
Requests, X 2–8Chart with 1 data series: Observed.
Requests, X 2–8
Requests, X 2–8Chart with 1 data series: Observed.
Requests, X 2–8
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 = LineViewportRecipe.Create("compact-x-viewport", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Requests, X 2\u20138", "Full-data Y; gap at 6; labels in X 2\u20138", showLegend: false, showSurface: false));
var prepared = model.Prepare(context, new ChartCartesianViewport(x: new ChartAxisWindow(2, 8)));
File.WriteAllText("visual.svg", prepared.ToSvg());
File.WriteAllBytes("visual.png", prepared.ToPng());
File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Chart).ToHtmlPage());
#endregion

/// <summary>Authored requests and utilization retain outside observations while selecting X 2–8 for rendering.</summary>
public static class LineViewportRecipe {
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        var compact = variant.StartsWith("compact", StringComparison.Ordinal);
        var observed = new ChartSeries(new ChartSeriesId("observed"), "Observed", ChartSeriesKind.Line,
            Points(88, 44, 34, 56, 46, 64, 42, 58, 50, 38, 82)).Markers(markers => markers.Radius = 3);

        var chart = Chart.Create().XAxis(x => x.Title("Sample")).YAxis(y => y.Title("Requests")).XAxis(x => x.Bounds(0, 10)).DataLabels().AddSeries(observed);
        if (!compact) {
            observed.ShowDataLabels(false);
            var utilization = new ChartSeries(new ChartSeriesId("utilization"), "Utilization", ChartSeriesKind.Line,
                Points(96, 72, 48, 61, 55, 76, 49, 67, 59, 84, 100))
                .SecondaryAxis().Markers(markers => markers.Radius = 3);

            chart.AddSeries(utilization).SecondaryYAxis(s => s.Title("Utilization (%)"));
            chart.Options.SecondaryYAxis.TickCount = 4;
        }
        chart.Options.XAxis.Reversed(false);
        chart.Options.XAxis.TickCount = 4; chart.Options.YAxis.TickCount = 4;
        return chart;
    }

    private static ChartPoint[] Points(params double[] values) => values.Select((value, index) =>
        new ChartPoint(index == 1 ? 1.99 : index == 9 ? 8.01 : index, value, index == 6)).ToArray();
}
#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 = LineViewportRecipe.Create("compact-x-viewport", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(360, 360)), theme, mode,
    new VisualFrame("Requests, X 2\u20138", "Full-data Y; gap at 6; labels in X 2\u20138", showLegend: false, showSurface: false));
var prepared = model.Prepare(context, new ChartCartesianViewport(x: new ChartAxisWindow(2, 8)));
File.WriteAllText("visual.svg", prepared.ToSvg());
File.WriteAllBytes("visual.png", prepared.ToPng());
File.WriteAllText("visual.html", prepared.ToArtifact("example", VisualArtifactKind.Chart).ToHtmlPage());
#endregion

/// <summary>Authored requests and utilization retain outside observations while selecting X 2–8 for rendering.</summary>
public static class LineViewportRecipe {
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        var compact = variant.StartsWith("compact", StringComparison.Ordinal);
        var observed = new ChartSeries(new ChartSeriesId("observed"), "Observed", ChartSeriesKind.Line,
            Points(88, 44, 34, 56, 46, 64, 42, 58, 50, 38, 82)).Markers(markers => markers.Radius = 3);

        var chart = Chart.Create().XAxis(x => x.Title("Sample")).YAxis(y => y.Title("Requests")).XAxis(x => x.Bounds(0, 10)).DataLabels().AddSeries(observed);
        if (!compact) {
            observed.ShowDataLabels(false);
            var utilization = new ChartSeries(new ChartSeriesId("utilization"), "Utilization", ChartSeriesKind.Line,
                Points(96, 72, 48, 61, 55, 76, 49, 67, 59, 84, 100))
                .SecondaryAxis().Markers(markers => markers.Radius = 3);

            chart.AddSeries(utilization).SecondaryYAxis(s => s.Title("Utilization (%)"));
            chart.Options.SecondaryYAxis.TickCount = 4;
        }
        chart.Options.XAxis.Reversed(false);
        chart.Options.XAxis.TickCount = 4; chart.Options.YAxis.TickCount = 4;
        return chart;
    }

    private static ChartPoint[] Points(params double[] values) => values.Select((value, index) =>
        new ChartPoint(index == 1 ? 1.99 : index == 9 ? 8.01 : index, value, index == 6)).ToArray();
}