← Gallery

Gauge

Pressure against operating bands

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

Preview
Pressure against operating bandsPressure against operating bands with 1 data series: Pressure.
Pressure against operating bands
Pressure against operating bandsPressure against operating bands with 1 data series: Pressure.
Pressure against operating bands
390 × 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 = CombinedGaugeRecipe.Create("compact", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(390, 360)), theme, mode,
    new VisualFrame("Pressure against operating bands", "Arc, needle and independently painted semantic bands", 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>A single reading shown with an arc, needle, explicit references and independently painted semantic bands.</summary>
public static class CombinedGaugeRecipe {
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "compact")) throw new ArgumentOutOfRangeException(nameof(variant));
        var compact = variant == "compact";
        var series = ChartSeries.CreateGauge(new ChartSeriesId("pressure"), "Pressure",
            new ChartGaugeValue(3.25, 2, 3, new[] { new ChartGaugeTarget(2.4, "Minimum"), new ChartGaugeTarget(2.8, "Target") }), ChartColor.FromHex("#176B88"))
            .ObservationId(0, new ChartObservationId("current"));
        return Chart.Create().Size(compact ? 390 : 760, compact ? 360 : 440).Title("Pressure against operating bands")
            .Theme(VisualTheme.Graphite()).ThemeMode(mode).Legend(false).AddSeries(series)
            .ValueFormat(ChartValueFormat.Number("0.00' MPa'"))
            .Gauge(options => {
                options.Form = ChartGaugeForm.ArcWithNeedle; options.StartAngleDegrees = 180; options.SweepAngleDegrees = 180;
                options.TickCount = 5; options.BandGap = 4; options.NeedleColor = ChartColor.FromHex("#9D3C20"); options.Caption = "Raw reading above the operating range";
                options.Bands.Add(new ChartGaugeBand(2, 2.4, ChartSeriesState.Warning, ChartColor.FromHex("#D4A72C"), .8));
                options.Bands.Add(new ChartGaugeBand(2.4, 2.8, ChartSeriesState.Success, ChartColor.FromHex("#178266")));
                options.Bands.Add(new ChartGaugeBand(2.8, 3, ChartSeriesState.Danger, ChartColor.FromHex("#C34D43"), .85));
            });
    }
}
#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 = CombinedGaugeRecipe.Create("compact", mode);
var context = new VisualRenderContext(
    new VisualLayoutOptions(new VisualSize(390, 360)), theme, mode,
    new VisualFrame("Pressure against operating bands", "Arc, needle and independently painted semantic bands", 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>A single reading shown with an arc, needle, explicit references and independently painted semantic bands.</summary>
public static class CombinedGaugeRecipe {
    public static Chart Create(string variant = "wide", ThemeMode mode = ThemeMode.Light) {
        if (variant is not ("wide" or "compact")) throw new ArgumentOutOfRangeException(nameof(variant));
        var compact = variant == "compact";
        var series = ChartSeries.CreateGauge(new ChartSeriesId("pressure"), "Pressure",
            new ChartGaugeValue(3.25, 2, 3, new[] { new ChartGaugeTarget(2.4, "Minimum"), new ChartGaugeTarget(2.8, "Target") }), ChartColor.FromHex("#176B88"))
            .ObservationId(0, new ChartObservationId("current"));
        return Chart.Create().Size(compact ? 390 : 760, compact ? 360 : 440).Title("Pressure against operating bands")
            .Theme(VisualTheme.Graphite()).ThemeMode(mode).Legend(false).AddSeries(series)
            .ValueFormat(ChartValueFormat.Number("0.00' MPa'"))
            .Gauge(options => {
                options.Form = ChartGaugeForm.ArcWithNeedle; options.StartAngleDegrees = 180; options.SweepAngleDegrees = 180;
                options.TickCount = 5; options.BandGap = 4; options.NeedleColor = ChartColor.FromHex("#9D3C20"); options.Caption = "Raw reading above the operating range";
                options.Bands.Add(new ChartGaugeBand(2, 2.4, ChartSeriesState.Warning, ChartColor.FromHex("#D4A72C"), .8));
                options.Bands.Add(new ChartGaugeBand(2.4, 2.8, ChartSeriesState.Success, ChartColor.FromHex("#178266")));
                options.Bands.Add(new ChartGaugeBand(2.8, 3, ChartSeriesState.Danger, ChartColor.FromHex("#C34D43"), .85));
            });
    }
}