#region Setup 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 = CombinedGaugeRecipe.Create("wide", mode); var context = new VisualRenderContext( new VisualLayoutOptions(new VisualSize(760, 440)), 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 /// A single reading shown with an arc, needle, explicit references and independently painted semantic bands. public static class CombinedGaugeRecipe { public static Chart Create(string variant = "wide", VisualThemeMode mode = VisualThemeMode.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")) .WithObservationId(0, new ChartObservationId("current")); return Chart.Create().WithSize(compact ? 390 : 760, compact ? 360 : 440).WithTitle("Pressure against operating bands") .WithTheme(VisualTheme.Graphite(), mode).WithLegend(false).AddSeries(series) .WithValueFormat(ChartValueFormat.Number("0.00' MPa'")) .ConfigureGauge(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)); }); } }