Scale Sections Example for WPF

Nevron NOV Gauge for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF Gauge examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Scale Sections Example for WPF Description

The example demonstrates how to create scale sections. Scale sections allow you to modify the appearance of scale elements if they fall in certain range.


Scale Sections Example

C# Scale Sections Example Code for Nevron Gauge for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NScaleSectionsExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

        #region Example

		/// 
		/// 
		/// 
		/// 
        public NWidget CreateExampleContent()
		{
			NStackPanel stack = new NStackPanel();
			
			NStackPanel controlStack = new NStackPanel();
			controlStack.Direction = ENHVDirection.LeftToRight;
			stack.Add(controlStack);

			m_LinearGauge = new NLinearGauge();
			m_LinearGauge.Orientation = ENLinearGaugeOrientation.Vertical;
			m_LinearGauge.PreferredSize = defaultLinearVerticalGaugeSize;
			m_LinearGauge.BackgroundFill = new NStockGradientFill(NColor.DarkGray, NColor.Black);
			m_LinearGauge.CapEffect = new NGelCapEffect();
			m_LinearGauge.Border = CreateBorder();
			m_LinearGauge.Padding = new NMargins(20);
			m_LinearGauge.BorderThickness = new NMargins(6);

			controlStack.Add(m_LinearGauge);

			NMarkerValueIndicator markerIndicator = new NMarkerValueIndicator();
			m_LinearGauge.Indicators.Add(markerIndicator);

			InitSections(m_LinearGauge);

			// create the radial gauge
			m_RadialGauge = new NRadialGauge();
			m_RadialGauge.PreferredSize = defaultRadialGaugeSize;
			NEdgeDialRim dialRim = new NEdgeDialRim();
			dialRim.OuterBevelWidth = 2.0;
			dialRim.InnerBevelWidth = 2.0;
			dialRim.MiddleBevelWidth = 2.0;
			m_RadialGauge.Dial = new NDial(ENDialShape.CutCircle, dialRim);
			m_RadialGauge.Dial.BackgroundFill = new NStockGradientFill(NColor.DarkGray, NColor.Black);
			m_RadialGauge.InnerRadius = 15;

			NGlassCapEffect glassCapEffect = new NGlassCapEffect();
			glassCapEffect.LightDirection = new NAngle(130, NUnit.Degree);
			glassCapEffect.EdgeOffset = 0;
			glassCapEffect.EdgeDepth = 0.30;
			m_RadialGauge.CapEffect = glassCapEffect;

			controlStack.Add(m_RadialGauge);

			NNeedleValueIndicator needleIndicator = new NNeedleValueIndicator();
			m_RadialGauge.Indicators.Add(needleIndicator);
			m_RadialGauge.SweepAngle = new NAngle(180, NUnit.Degree);

			InitSections(m_RadialGauge);

			m_DataFeedTimer = new NTimer();
			m_DataFeedTimer.Tick += OnDataFeedTimerTick;
			m_DataFeedTimer.Start();

			return stack;
		}
		/// 
		/// 
		/// 
		protected void OnUnregistered()
		{
			base.OnUnregistered();

			m_DataFeedTimer.Stop();
		}
		/// 
		/// 
		/// 
		/// 
        public NWidget CreateExampleControls()
        {
			NStackPanel stack = new NStackPanel();

			NStackPanel propertyStack = new NStackPanel();
			stack.Add(new NUniSizeBoxGroup(propertyStack));

			m_BlueSectionBeginUpDown = CreateUpDown(0.0);
			propertyStack.Add(new NPairBox("Begin:", m_BlueSectionBeginUpDown, true));

			m_BlueSectionEndUpDown = CreateUpDown(20.0);
			propertyStack.Add(new NPairBox("End:", m_BlueSectionEndUpDown, true));

			m_RedSectionBeginUpDown = CreateUpDown(80.0);
			propertyStack.Add(new NPairBox("Begin:", m_RedSectionBeginUpDown, true));

			m_RedSectionEndUpDown = CreateUpDown(100.0);
			propertyStack.Add(new NPairBox("End:", m_RedSectionEndUpDown, true));

			m_StopStartTimerButton = new NButton("Stop Timer");
			propertyStack.Add(m_StopStartTimerButton);
		

			return stack;
        }

		public string GetExampleDescription()
		{
			return @"

The example demonstrates how to create scale sections. Scale sections allow you to modify the appearance of scale elements if they fall in certain range.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Scale Sections", "https://www.nevron.com/docs/openvision/scale-sections.html"), ("Gauges Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Scale Ticks", "https://www.nevron.com/docs/openvision/scale-ticks.html"), ("Scale Common Label Settings", "https://www.nevron.com/docs/openvision/scale-label-settings.html"), }; } #endregion #region Implementation /// /// /// /// /// private NNumericUpDown CreateUpDown(double value) { NNumericUpDown numericUpDown = new NNumericUpDown(); numericUpDown.Minimum = 0.0; numericUpDown.Maximum = 100.0; numericUpDown.Value = value; numericUpDown.ValueChanged += UpdateSections; return numericUpDown; } /// /// /// /// private void InitSections(NGauge gauge) { gauge.Axes.Clear(); NGaugeAxis axis = new NGaugeAxis(); gauge.Axes.Add(axis); axis.Anchor = new NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top); NStandardScale scale = (NStandardScale)axis.Scale; // init text style for regular labels scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.White); scale.Labels.Style.TextStyle.Font = new NFont("Arimo", 10, ENFontStyle.Bold); // init ticks scale.MajorGridLines.Visible = true; scale.MinTickDistance = 25; scale.MinorTickCount = 1; scale.SetPredefinedScale(ENPredefinedScaleStyle.Scientific); // create sections NScaleSection blueSection = new NScaleSection(); blueSection.Range = new NRange(0, 20); blueSection.RangeFill = new NColorFill(NColor.FromColor(NColor.Blue, 0.5f)); blueSection.MajorGridStroke = new NStroke(NColor.Blue); blueSection.MajorTickStroke = new NStroke(NColor.DarkBlue); blueSection.MinorTickStroke = new NStroke(1, NColor.Blue, ENDashStyle.Dot); NTextStyle labelStyle = new NTextStyle(); labelStyle.Fill = new NColorFill(NColor.Blue); labelStyle.Font = new NFont("Arimo", 10, ENFontStyle.Bold); blueSection.LabelTextStyle = labelStyle; scale.Sections.Add(blueSection); NScaleSection redSection = new NScaleSection(); redSection.Range = new NRange(80, 100); redSection.RangeFill = new NColorFill(NColor.FromColor(NColor.Red, 0.5f)); redSection.MajorGridStroke = new NStroke(NColor.Red); redSection.MajorTickStroke = new NStroke(NColor.DarkRed); redSection.MinorTickStroke = new NStroke(1, NColor.Red, ENDashStyle.Dot); labelStyle = new NTextStyle(); labelStyle.Fill = new NColorFill(NColor.Red); labelStyle.Font = new NFont("Arimo", 10.0, ENFontStyle.Bold); redSection.LabelTextStyle = labelStyle; scale.Sections.Add(redSection); } #endregion #region Event Handlers /// /// /// void OnDataFeedTimerTick() { // update linear gauge NGauge[] gauges = new NGauge[] { m_RadialGauge, m_LinearGauge }; for (int i = 0; i < gauges.Length; i++) { NGauge gauge = gauges[i]; NValueIndicator valueIndicator = (NValueIndicator)gauge.Indicators[0]; NStandardScale scale = (NStandardScale)gauge.Axes[0].Scale; NScaleSection blueSection = (NScaleSection)scale.Sections[0]; NScaleSection redSection = (NScaleSection)scale.Sections[1]; m_FirstIndicatorAngle += 0.02; valueIndicator.Value = 50.0 - Math.Cos(m_FirstIndicatorAngle) * 50.0; // FIX: Smart Shapes if (blueSection.Range.Contains(valueIndicator.Value)) { valueIndicator.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Blue); valueIndicator.Stroke = new NStroke(NColor.Blue); } else if (redSection.Range.Contains(valueIndicator.Value)) { valueIndicator.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red); valueIndicator.Stroke = new NStroke(NColor.Red); } else { valueIndicator.Fill = new NColorFill(NColor.LightGreen); valueIndicator.Stroke = new NStroke(NColor.DarkGreen); } } } /// /// /// /// /// void OnStopStartTimerButtonClick(object sender, System.EventArgs e) { if (this.m_DataFeedTimer.IsStarted) { this.m_DataFeedTimer.Stop(); m_StopStartTimerButton.Content = new NLabel("Start Timer"); } else { this.m_DataFeedTimer.Start(); m_StopStartTimerButton.Content = new NLabel("Stop Timer"); } } /// /// /// /// void UpdateSections(NValueChangeEventArgs arg) { NGauge[] gauges = new NGauge[] { m_RadialGauge, m_LinearGauge }; for (int i = 0; i < gauges.Length; i++) { NGauge gauge = gauges[i]; NGaugeAxis axis = (NGaugeAxis)gauge.Axes[0]; NStandardScale scale = (NStandardScale)axis.Scale; if (scale.Sections.Count == 2) { NScaleSection blueSection = (NScaleSection)scale.Sections[0]; blueSection.Range = new NRange(m_BlueSectionBeginUpDown.Value, m_BlueSectionEndUpDown.Value); NScaleSection redSection = (NScaleSection)scale.Sections[1]; redSection.Range = new NRange(m_RedSectionBeginUpDown.Value, m_RedSectionEndUpDown.Value); } } } #endregion #region Fields NNumericUpDown m_BlueSectionBeginUpDown; NNumericUpDown m_BlueSectionEndUpDown; NNumericUpDown m_RedSectionBeginUpDown; NNumericUpDown m_RedSectionEndUpDown; NRadialGauge m_RadialGauge; NLinearGauge m_LinearGauge; NTimer m_DataFeedTimer; NButton m_StopStartTimerButton; double m_FirstIndicatorAngle; #endregion #region Static Methods protected NBorder CreateBorder() { return NBorder.CreateThreeColorBorder(NColor.LightGray, NColor.White, NColor.DarkGray, 10, 10); } #endregion #region Constants private static readonly NSize defaultRadialGaugeSize = new NSize(300, 300); private static readonly NSize defaultLinearVerticalGaugeSize = new NSize(100, 300); #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Scale Sections Example for WPF Solution

VB.NET Scale Sections Example Code for Nevron Gauge for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System

Class MainWindow

#Region "Constructors"

	Public Sub New()
		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NScaleSectionsExample"

		' Create the NOV example and its controls
		Dim exampleContent As NWidget = CreateExampleContent()
		Dim exampleControls As NWidget = CreateExampleControls()
		If Not exampleControls Is Nothing Then
			exampleControls.PreferredWidth = 300
		End If

		' Place the example and its controls in a pair box
		Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
		pairBox.FillMode = ENStackFillMode.First
		pairBox.FitMode = ENStackFitMode.First
		pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)

		' Host the example in the form
		Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
		Content = host
	End Sub


#End Region

#Region "Example"

        ''' 
        ''' 
        ''' 
        ''' 
        Public Function CreateExampleContent() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            Dim controlStack As NStackPanel = New NStackPanel()
            controlStack.Direction = ENHVDirection.LeftToRight
            stack.Add(controlStack)

            m_LinearGauge = New NLinearGauge()
            m_LinearGauge.Orientation = ENLinearGaugeOrientation.Vertical
            m_LinearGauge.PreferredSize = defaultLinearVerticalGaugeSize
            m_LinearGauge.BackgroundFill = New NStockGradientFill(NColor.DarkGray, NColor.Black)
            m_LinearGauge.CapEffect = New NGelCapEffect()
            m_LinearGauge.Border = CreateBorder()
            m_LinearGauge.Padding = New NMargins(20)
            m_LinearGauge.BorderThickness = New NMargins(6)

            controlStack.Add(m_LinearGauge)

            Dim markerIndicator As NMarkerValueIndicator = New NMarkerValueIndicator()
            m_LinearGauge.Indicators.Add(markerIndicator)

            InitSections(m_LinearGauge)

            ' create the radial gauge
            m_RadialGauge = New NRadialGauge()
            m_RadialGauge.PreferredSize = defaultRadialGaugeSize
            Dim dialRim As NEdgeDialRim = New NEdgeDialRim()
            dialRim.OuterBevelWidth = 2.0
            dialRim.InnerBevelWidth = 2.0
            dialRim.MiddleBevelWidth = 2.0
            m_RadialGauge.Dial = New NDial(ENDialShape.CutCircle, dialRim)
            m_RadialGauge.Dial.BackgroundFill = New NStockGradientFill(NColor.DarkGray, NColor.Black)
            m_RadialGauge.InnerRadius = 15

            Dim glassCapEffect As NGlassCapEffect = New NGlassCapEffect()
            glassCapEffect.LightDirection = New NAngle(130, NUnit.Degree)
            glassCapEffect.EdgeOffset = 0
            glassCapEffect.EdgeDepth = 0.30
            m_RadialGauge.CapEffect = glassCapEffect

            controlStack.Add(m_RadialGauge)

            Dim needleIndicator As NNeedleValueIndicator = New NNeedleValueIndicator()
            m_RadialGauge.Indicators.Add(needleIndicator)
            m_RadialGauge.SweepAngle = New NAngle(180, NUnit.Degree)

            InitSections(m_RadialGauge)

            m_DataFeedTimer = New NTimer()
            Me.m_DataFeedTimer.Tick += AddressOf OnDataFeedTimerTick
            m_DataFeedTimer.Start()

            Return stack
        End Function
        ''' 
        ''' 
        ''' 
        Protected Sub OnUnregistered()
            MyBase.OnUnregistered()

            m_DataFeedTimer.Stop()
        End Sub
        ''' 
        ''' 
        ''' 
        ''' 
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            Dim propertyStack As NStackPanel = New NStackPanel()
            stack.Add(New NUniSizeBoxGroup(propertyStack))

            m_BlueSectionBeginUpDown = CreateUpDown(0.0)
            propertyStack.Add(New NPairBox("Begin:", m_BlueSectionBeginUpDown, True))

            m_BlueSectionEndUpDown = CreateUpDown(20.0)
            propertyStack.Add(New NPairBox("End:", m_BlueSectionEndUpDown, True))

            m_RedSectionBeginUpDown = CreateUpDown(80.0)
            propertyStack.Add(New NPairBox("Begin:", m_RedSectionBeginUpDown, True))

            m_RedSectionEndUpDown = CreateUpDown(100.0)
            propertyStack.Add(New NPairBox("End:", m_RedSectionEndUpDown, True))

            m_StopStartTimerButton = New NButton("Stop Timer")
            propertyStack.Add(m_StopStartTimerButton)


            Return stack
        End Function

        Public Function GetExampleDescription() As String
            Return "

The example demonstrates how to create scale sections. Scale sections allow you to modify the appearance of scale elements if they fall in certain range.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Scale Sections", "https://www.nevron.com/docs/openvision/scale-sections.html"), ("Gauges Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Scale Ticks", "https://www.nevron.com/docs/openvision/scale-ticks.html"), ("Scale Common Label Settings", "https://www.nevron.com/docs/openvision/scale-label-settings.html")} End Function #End Region #Region "Implementation" ''' ''' ''' ''' ''' Private Function CreateUpDown(value As Double) As NNumericUpDown Dim numericUpDown As NNumericUpDown = New NNumericUpDown() numericUpDown.Minimum = 0.0 numericUpDown.Maximum = 100.0 numericUpDown.Value = value numericUpDown.ValueChanged += AddressOf UpdateSections Return numericUpDown End Function ''' ''' ''' ''' Private Sub InitSections(gauge As NGauge) gauge.Axes.Clear() Dim axis As NGaugeAxis = New NGaugeAxis() gauge.Axes.Add(axis) axis.Anchor = New NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top) Dim scale = CType(axis.Scale, NStandardScale) ' init text style for regular labels scale.Labels.Style.TextStyle.Fill = New NColorFill(NColor.White) scale.Labels.Style.TextStyle.Font = New NFont("Arimo", 10, ENFontStyle.Bold) ' init ticks scale.MajorGridLines.Visible = True scale.MinTickDistance = 25 scale.MinorTickCount = 1 scale.SetPredefinedScale(ENPredefinedScaleStyle.Scientific) ' create sections Dim blueSection As NScaleSection = New NScaleSection() blueSection.Range = New NRange(0, 20) blueSection.RangeFill = New NColorFill(NColor.FromColor(NColor.Blue, 0.5F)) blueSection.MajorGridStroke = New NStroke(NColor.Blue) blueSection.MajorTickStroke = New NStroke(NColor.DarkBlue) blueSection.MinorTickStroke = New NStroke(1, NColor.Blue, ENDashStyle.Dot) Dim labelStyle As NTextStyle = New NTextStyle() labelStyle.Fill = New NColorFill(NColor.Blue) labelStyle.Font = New NFont("Arimo", 10, ENFontStyle.Bold) blueSection.LabelTextStyle = labelStyle scale.Sections.Add(blueSection) Dim redSection As NScaleSection = New NScaleSection() redSection.Range = New NRange(80, 100) redSection.RangeFill = New NColorFill(NColor.FromColor(NColor.Red, 0.5F)) redSection.MajorGridStroke = New NStroke(NColor.Red) redSection.MajorTickStroke = New NStroke(NColor.DarkRed) redSection.MinorTickStroke = New NStroke(1, NColor.Red, ENDashStyle.Dot) labelStyle = New NTextStyle() labelStyle.Fill = New NColorFill(NColor.Red) labelStyle.Font = New NFont("Arimo", 10.0, ENFontStyle.Bold) redSection.LabelTextStyle = labelStyle scale.Sections.Add(redSection) End Sub #End Region #Region "Event Handlers" ''' ''' ''' Private Sub OnDataFeedTimerTick() ' update linear gauge Dim gauges = New NGauge() {m_RadialGauge, m_LinearGauge} For i = 0 To gauges.Length - 1 Dim gauge = gauges(i) Dim valueIndicator = CType(gauge.Indicators(0), NValueIndicator) Dim scale = CType(gauge.Axes(0).Scale, NStandardScale) Dim blueSection = scale.Sections(0) Dim redSection = scale.Sections(1) m_FirstIndicatorAngle += 0.02 valueIndicator.Value = 50.0 - Math.Cos(m_FirstIndicatorAngle) * 50.0 ' FIX: Smart Shapes If blueSection.Range.Contains(valueIndicator.Value) Then valueIndicator.Fill = New NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Blue) valueIndicator.Stroke = New NStroke(NColor.Blue) ElseIf redSection.Range.Contains(valueIndicator.Value) Then valueIndicator.Fill = New NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red) valueIndicator.Stroke = New NStroke(NColor.Red) Else valueIndicator.Fill = New NColorFill(NColor.LightGreen) valueIndicator.Stroke = New NStroke(NColor.DarkGreen) End If Next End Sub ''' ''' ''' ''' ''' Private Sub OnStopStartTimerButtonClick(sender As Object, e As EventArgs) If m_DataFeedTimer.IsStarted Then m_DataFeedTimer.Stop() m_StopStartTimerButton.Content = New NLabel("Start Timer") Else m_DataFeedTimer.Start() m_StopStartTimerButton.Content = New NLabel("Stop Timer") End If End Sub ''' ''' ''' ''' Private Sub UpdateSections(arg As NValueChangeEventArgs) Dim gauges = New NGauge() {m_RadialGauge, m_LinearGauge} For i = 0 To gauges.Length - 1 Dim gauge = gauges(i) Dim axis = gauge.Axes(0) Dim scale = CType(axis.Scale, NStandardScale) If scale.Sections.Count = 2 Then Dim blueSection = scale.Sections(0) blueSection.Range = New NRange(m_BlueSectionBeginUpDown.Value, m_BlueSectionEndUpDown.Value) Dim redSection = scale.Sections(1) redSection.Range = New NRange(m_RedSectionBeginUpDown.Value, m_RedSectionEndUpDown.Value) End If Next End Sub #End Region #Region "Fields" Private m_BlueSectionBeginUpDown As NNumericUpDown Private m_BlueSectionEndUpDown As NNumericUpDown Private m_RedSectionBeginUpDown As NNumericUpDown Private m_RedSectionEndUpDown As NNumericUpDown Private m_RadialGauge As NRadialGauge Private m_LinearGauge As NLinearGauge Private m_DataFeedTimer As NTimer Private m_StopStartTimerButton As NButton Private m_FirstIndicatorAngle As Double #End Region #Region "Static Methods" Protected Function CreateBorder() As NBorder Return NBorder.CreateThreeColorBorder(NColor.LightGray, NColor.White, NColor.DarkGray, 10, 10) End Function #End Region #Region "Constants" Private Shared ReadOnly defaultRadialGaugeSize As NSize = New NSize(300, 300) Private Shared ReadOnly defaultLinearVerticalGaugeSize As NSize = New NSize(100, 300) #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Scale Sections Example for WPF Solution