Linear Scale Example for Blazor

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

Linear Scale Example for Blazor Description

This example demonstrates how to create a linear (numeric) scale.


Linear Scale Example

C# Linear Scale Example Code for Nevron Chart 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 - NLinearScaleExample";

			// 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()
		{
			NChartViewWithCommandBars chartViewWithCommandBars = new NChartViewWithCommandBars();
			NChartView chartView = chartViewWithCommandBars.View;
			chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);

			// configure title
			chartView.Surface.Titles[0].Text = "Linear Scale";

			// configure chart
			m_Chart = (NCartesianChart)chartView.Surface.Charts[0];

			// configure axes
			m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
            m_Chart.SetPredefinedInteractor(ENPredefinedInteractor.DataZoomingAndScrolling);

            // configure the y axis
            NLinearScale linearScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;

            m_Chart.Axes[ENCartesianAxis.PrimaryY].MinViewRangeValue = (double)-100;
            m_Chart.Axes[ENCartesianAxis.PrimaryY].MaxViewRangeValue = (double)100;
            m_Chart.Axes[ENCartesianAxis.PrimaryY].ViewRangeMode = ENAxisViewRangeMode.FixedRange;

			NScaleGridLines majorGrid = new NScaleGridLines();
			majorGrid.Stroke = new NStroke(1, NColor.DarkGray, ENDashStyle.Dot);
			linearScale.MajorGridLines = majorGrid;

			// add a strip line style
			NScaleStrip strip = new NScaleStrip();
			strip.Fill = new NColorFill(NColor.Beige);
			strip.Interlaced = true;
			linearScale.Strips.Add(strip);

			NLineSeries line = new NLineSeries();
			m_Chart.Series.Add(line);

			Random random = new Random();
			for (int i = 0; i < 7; i++)
			{
				line.DataPoints.Add(new NLineDataPoint(random.Next(-100, 100)));
			}

			line.LegendView.Mode = ENSeriesLegendMode.None;
			line.InflateMargins = true;

			// assign marker
			NMarkerStyle markerStyle = new NMarkerStyle();

			markerStyle.Visible = true;
			markerStyle.Shape = ENPointShape3D.Ellipse;
			markerStyle.Size = new NSize(6, 6);

			line.MarkerStyle = markerStyle;

			// assign data label style
			NDataLabelStyle dataLabelStyle = new NDataLabelStyle();

			dataLabelStyle.Format = "";
			dataLabelStyle.ArrowStroke.Color = NColor.CornflowerBlue;

			line.DataLabelStyle = dataLabelStyle;

			chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));

			return chartViewWithCommandBars;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);

			m_MajorTickModeComboBox = new NComboBox();
			m_MajorTickModeComboBox.Items.FillFromEnum();
			m_MajorTickModeComboBox.SelectedIndexChanged += OnMajorTickModeComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Major Tick Mode:", m_MajorTickModeComboBox));

			m_MinDistanceUpDown = new NNumericUpDown();
			m_MinDistanceUpDown.ValueChanged += OnMinDistanceUpDownValueChanged;
			stack.Add(NPairBox.Create("Min Distance:", m_MinDistanceUpDown));
			m_MinDistanceUpDown.Value = 25;

			m_MaxCountNumericUpDown = new NNumericUpDown();
			m_MaxCountNumericUpDown.ValueChanged += OnMaxCountNumericUpDownValueChanged;
			stack.Add(NPairBox.Create("Max Count:", m_MaxCountNumericUpDown));
			m_MaxCountNumericUpDown.Value = 10;
			
			m_CustomStepUpDown = new NNumericUpDown();
			m_CustomStepUpDown.ValueChanged += OnCustomStepUpDownValueChanged;
			stack.Add(NPairBox.Create("Custom Step:", m_CustomStepUpDown));
			m_CustomStepUpDown.Value = 1;

			NCheckBox invertedCheckBox = new NCheckBox("Inverted");
			invertedCheckBox.CheckedChanged += OnInvertedCheckBoxCheckedChanged;
			invertedCheckBox.Checked = false;
			stack.Add(invertedCheckBox);

			NButton generateRandomDataButton = new NButton("Generate Random Data");
			generateRandomDataButton.Click += OnGenerateRandomDataButtonClick;
			stack.Add(generateRandomDataButton);

			m_MajorTickModeComboBox.SelectedIndex = (int)ENMajorTickMode.AutoMinDistance;
			OnMajorTickModeComboBoxSelectedIndexChanged(null);
			
			return boxGroup;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create a linear (numeric) scale.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Linear Scale", "https://www.nevron.com/docs/openvision/linear-scale.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnInvertedCheckBoxCheckedChanged(NValueChangeEventArgs arg) { ((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).Invert = ((NCheckBox)arg.TargetNode).Checked; } void OnGenerateRandomDataButtonClick(NEventArgs arg) { NLineSeries line = (NLineSeries)m_Chart.Series[0]; line.DataPoints.Clear(); Random random = new Random(); for (int i = 0; i < 10; i++) { line.DataPoints.Add(new NLineDataPoint(random.Next(100))); } } void OnCustomStepUpDownValueChanged(NValueChangeEventArgs arg) { ((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).CustomStep = ((NNumericUpDown)arg.TargetNode).Value; } void OnMinDistanceUpDownValueChanged(NValueChangeEventArgs arg) { ((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).MinTickDistance = (int)((NNumericUpDown)arg.TargetNode).Value; } void OnMaxCountNumericUpDownValueChanged(NValueChangeEventArgs arg) { ((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).MaxTickCount = (int)((NNumericUpDown)arg.TargetNode).Value; } void OnMajorTickModeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { ENMajorTickMode majorTickMode = (ENMajorTickMode)m_MajorTickModeComboBox.SelectedIndex; m_MaxCountNumericUpDown.Enabled = majorTickMode == ENMajorTickMode.AutoMaxCount; m_MinDistanceUpDown.Enabled = majorTickMode == ENMajorTickMode.AutoMinDistance; m_CustomStepUpDown.Enabled = majorTickMode == ENMajorTickMode.CustomStep; ((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).MajorTickMode = majorTickMode; } #endregion #region Fields NCartesianChart m_Chart; NComboBox m_MajorTickModeComboBox; NNumericUpDown m_MaxCountNumericUpDown; NNumericUpDown m_MinDistanceUpDown; NNumericUpDown m_CustomStepUpDown; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

Related Documentation Links