Ordinal 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.

Ordinal Scale Example for Blazor Description

This example demonstrates how to create an ordinal scale.


Ordinal Scale Example

C# Ordinal Scale Example Code for Nevron Chart for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.DataStructures;
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 - NOrdinalScaleExample";

			// 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 = "Ordinal Scale";

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

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

            // add interlaced stripe to the Y axis
            NLinearScale linearScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
			NScaleStrip stripStyle = new NScaleStrip();
			stripStyle.Fill = new NColorFill(NColor.Beige);
			stripStyle.Interlaced = true;
			linearScale.Strips.Add(stripStyle);

			// add some series
			int dataItemsCount = 6;
			NBarSeries bar = new NBarSeries();

			bar.InflateMargins = true;
			bar.DataLabelStyle = new NDataLabelStyle(false);

			Random random = new Random();

			for (int i = 0; i < dataItemsCount; i++)
			{
				bar.DataPoints.Add(new NBarDataPoint(random.Next(10, 30)));
			}

			m_Chart.Series.Add(bar);

			NOrdinalScale ordinalScale = (NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale;
			ordinalScale.Labels.OverlapResolveLayouts = new NDomArray(new ENLevelLabelsLayout[] { ENLevelLabelsLayout.AutoScale });

			NList labels = new NList();
			for (int j = 0; j < dataItemsCount; j++)
			{
				labels.Add("Category " + j.ToString());
			}

			ordinalScale.Labels.TextProvider = new NOrdinalScaleLabelTextProvider(labels);

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

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

			NCheckBox displayDataPointsBetweenTicksCheckBox = new NCheckBox("Display Data Points Between Ticks");
			displayDataPointsBetweenTicksCheckBox.CheckedChanged += OnDisplayDataPointsBetweenTicksCheckBoxCheckedChanged;
			displayDataPointsBetweenTicksCheckBox.Checked = true;
			stack.Add(displayDataPointsBetweenTicksCheckBox);

			NCheckBox autoLabelsCheckBox = new NCheckBox("Auto Labels");
			autoLabelsCheckBox.CheckedChanged += OnAutoLabelsCheckBoxCheckedChanged;
			autoLabelsCheckBox.Checked = true;
			stack.Add(autoLabelsCheckBox);

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

			return boxGroup;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create an ordinal scale.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnAutoLabelsCheckBoxCheckedChanged(NValueChangeEventArgs arg) { if (((NCheckBox)arg.TargetNode).Checked) { ((NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).Labels.TextProvider = new NFormattedScaleLabelTextProvider(new NNumericValueFormatter()); } else { NList labels = new NList(); int dataPointCount = ((NBarSeries)m_Chart.Series[0]).DataPoints.Count; for (int j = 0; j < dataPointCount; j++) { labels.Add("Category " + j.ToString()); } ((NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).Labels.TextProvider = new NOrdinalScaleLabelTextProvider(labels); } } void OnDisplayDataPointsBetweenTicksCheckBoxCheckedChanged(NValueChangeEventArgs arg) { ((NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).DisplayDataPointsBetweenTicks = ((NCheckBox)arg.TargetNode).Checked; } void OnInvertedCheckBoxCheckedChanged(NValueChangeEventArgs arg) { ((NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).Invert = ((NCheckBox)arg.TargetNode).Checked; } #endregion #region Fields NCartesianChart m_Chart; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

Related Documentation Links