Auto Adjusting Scale Example for Blazor

Auto Adjusting Scale Example for Blazor

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

Auto Adjusting Scale Example for Blazor Description


Auto Adjust Scale Example

C# Auto Adjusting Scale Example Code for Nevron Gauge for Blazor
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 - NAutoAdjustScaleExample";

			// 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();
            stack.Add(controlStack);

            // create the radial gauge
            m_RadialGauge = new NRadialGauge();
            m_RadialGauge.PreferredSize = defaultRadialGaugeSize;
            controlStack.Add(m_RadialGauge);

            m_RadialGauge.Dial = new NDial(ENDialShape.Circle, new NEdgeDialRim());
            m_RadialGauge.Dial.BackgroundFill = new NStockGradientFill(NColor.Black, NColor.Gray);

            NGelCapEffect gelEffect = new NGelCapEffect(ENCapEffectShape.Ellipse);
            gelEffect.Margins = new NMargins(0, 0, 0, 0.5);

            m_RadialGauge.Axes.Clear();

            // create the radial gauge
            m_RadialGauge.SweepAngle = new NAngle(180, NUnit.Degree);
            m_RadialGauge.BeginAngle = new NAngle(32, NUnit.Degree);

            // create the first axis
            NGaugeAxis axis1 = new NGaugeAxis();
            axis1.Anchor = new NDockGaugeAxisAnchor(ENGaugeAxisDockZone.Top, true, 30,180);
            
            m_RadialGauge.Axes.Add(axis1);

            //Cache the initial begin and end
            m_CurBegin = m_RadialGauge.Axes[0].Range.Begin;
            m_CurEnd = m_RadialGauge.Axes[0].Range.End;

            m_InitBegin =  m_CurBegin;
            m_InitEnd = m_CurEnd;

            // scale 
            m_Scale = (NStandardScale)axis1.Scale;
            m_Scale.SetPredefinedScale(ENPredefinedScaleStyle.PresentationNoStroke);
            m_Scale.MajorTickMode = ENMajorTickMode.AutoMaxCount;
            m_Scale.MaxTickCount = 9;
            m_Scale.MinorTickCount = 3;
            m_Scale.Ruler.Fill = new NColorFill(NColor.FromColor(NColor.White, 0.4f));
            m_Scale.OuterMajorTicks.Fill = new NColorFill(NColor.Orange);            
            m_Scale.Labels.Style.TextStyle.Font = new NFont("Arimo", 12, ENFontStyle.Bold);
            m_Scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.White);
            m_Scale.Labels.Style.Angle = new NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0);
            m_Scale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;

            // Value Indicator
            m_NeedleValueIndicator = new NNeedleValueIndicator();
            m_NeedleValueIndicator.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red);
            m_NeedleValueIndicator.Stroke.Color = NColor.Red;
            m_NeedleValueIndicator.OffsetFromScale = 2;
            m_NeedleValueIndicator.Shape = ENNeedleShape.Triangle;
            m_RadialGauge.SweepAngle = new NAngle(360, NUnit.Degree);

            m_RadialGauge.Indicators.Add(m_NeedleValueIndicator);

            // Timer
            m_Timer = new NTimer();
            m_Timer.Interval = 200;
            m_Timer.Tick += OnTimerTick;
            m_Timer.Start();

            m_Range = 100;

            // radio buttons
            m_StepAndRotateScaleRadioButton = new NRadioButton("Step and Rotate Scale");
            m_ContinuouslyRotateRadioButton = new NRadioButton("Continuously Rotate");
            m_ContinuouslyRotateRadioButton.Checked = true;

            return stack;
        }
        /// 
        /// 
        /// 
        /// 
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();

            NRadioButtonGroup dynamicScaleRotationStylesGroup = new NRadioButtonGroup(stack);
            dynamicScaleRotationStylesGroup.SelectedIndex = 0;
            
            stack.Add(m_StepAndRotateScaleRadioButton);
            stack.Add(m_ContinuouslyRotateRadioButton);

            return dynamicScaleRotationStylesGroup;
        }
        /// 
        /// 
        /// 
        /// 
        public string GetExampleDescription()
        {
            return @"

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Gauges Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Gauges Overview", "https://www.nevron.com/docs/openvision/gauges-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields NRadialGauge m_RadialGauge; NNeedleValueIndicator m_NeedleValueIndicator; NStandardScale m_Scale; NTimer m_Timer; NRadioButton m_StepAndRotateScaleRadioButton; NRadioButton m_ContinuouslyRotateRadioButton; #endregion #region Static Methods #endregion #region Constants private static readonly NSize defaultRadialGaugeSize = new NSize(300, 300); private Random rand = new Random(); private double m_CurBegin; private double m_CurEnd; private double m_InitBegin; private double m_InitEnd; double m_Range; double m_FirstIndicatorAngle; const double c_ScaleRange = 50; const double c_RotateIncrement = 2; bool m_Increase = true; int m_Direction = 1; bool m_MoveRange = false; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Auto Adjusting Scale Example for Blazor Solution