Scale Sections 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.

Scale Sections Example for Blazor Description

This example demonstrates axis sections. Axis sections allow you to alter the appearance of different axis elements if they fall in a specified range.


Scale Sections Example

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

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

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

			m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);

			// create a point series
			NPointSeries point = new NPointSeries();
			point.Name = "Point Series";
			point.DataLabelStyle = new NDataLabelStyle(false);
			point.Size = 5;

			Random random = new Random();

			for (int i = 0; i < 30; i++)
			{
				point.DataPoints.Add(new NPointDataPoint(random.Next(100), random.Next(100)));
			}

			point.InflateMargins = true;

			m_Chart.Series.Add(point);

			// tell the x axis to display major and minor grid lines
			NLinearScale linearScale = new NLinearScale();
			m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = linearScale;
			linearScale.MajorGridLines = new NScaleGridLines();
			linearScale.MajorGridLines.Stroke.DashStyle = ENDashStyle.Solid;
			linearScale.MinorGridLines = new NScaleGridLines();
			linearScale.MinorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
			linearScale.MinorTickCount = 1;

			// tell the y axis to display major and minor grid lines
			linearScale = new NLinearScale();
			m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale = linearScale;
			linearScale.MajorGridLines = new NScaleGridLines();
			linearScale.MajorGridLines.Stroke.DashStyle = ENDashStyle.Solid;
			linearScale.MinorGridLines = new NScaleGridLines();
			linearScale.MinorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
			linearScale.MinorTickCount = 1;

			NTextStyle labelStyle;

			// configure the first horizontal section
			m_FirstHorizontalSection = new NScaleSection();
			m_FirstHorizontalSection.Range = new NRange(2, 8);
			m_FirstHorizontalSection.RangeFill = new NColorFill(new NColor(NColor.Red, 60));
			m_FirstHorizontalSection.MajorGridStroke = new NStroke(NColor.Red);
			m_FirstHorizontalSection.MajorTickStroke = new NStroke(NColor.DarkRed);
			m_FirstHorizontalSection.MinorTickStroke = new NStroke(1, NColor.Red, ENDashStyle.Dot);

			labelStyle = new NTextStyle();
			labelStyle.Fill = new NStockGradientFill(NColor.Red, NColor.DarkRed);
			labelStyle.Font.Style = ENFontStyle.Bold;
			m_FirstHorizontalSection.LabelTextStyle = labelStyle;

			// configure the second horizontal section
			m_SecondHorizontalSection = new NScaleSection();
			m_SecondHorizontalSection.Range = new NRange(14, 18);
			m_SecondHorizontalSection.RangeFill = new NColorFill(new NColor(NColor.Green, 60));
			m_SecondHorizontalSection.MajorGridStroke = new NStroke(NColor.Green);
			m_SecondHorizontalSection.MajorTickStroke = new NStroke(NColor.DarkGreen);
			m_SecondHorizontalSection.MinorTickStroke = new NStroke(1, NColor.Green, ENDashStyle.Dot);

			labelStyle = new NTextStyle();
			labelStyle.Fill = new NStockGradientFill(NColor.Green, NColor.DarkGreen);
			labelStyle.Font.Style = ENFontStyle.Bold;
			m_SecondHorizontalSection.LabelTextStyle = labelStyle;

			// configure the first vertical section
			m_FirstVerticalSection = new NScaleSection();
			m_FirstVerticalSection.Range = new NRange(20, 40);
			m_FirstVerticalSection.RangeFill = new NColorFill(new NColor(NColor.Blue, 60));
			m_FirstVerticalSection.MajorGridStroke = new NStroke(NColor.Blue);
			m_FirstVerticalSection.MajorTickStroke = new NStroke(NColor.DarkBlue);
			m_FirstVerticalSection.MinorTickStroke= new NStroke(1, NColor.Blue, ENDashStyle.Dot);

			labelStyle = new NTextStyle();
			labelStyle.Fill = new NStockGradientFill(NColor.Blue, NColor.DarkBlue);
			labelStyle.Font.Style = ENFontStyle.Bold;
			m_FirstVerticalSection.LabelTextStyle = labelStyle;

			// configure the second vertical section
			m_SecondVerticalSection = new NScaleSection();
			m_SecondVerticalSection.Range = new NRange(70, 90);
			m_SecondVerticalSection.RangeFill = new NColorFill(new NColor(NColor.Orange, 60));
			m_SecondVerticalSection.MajorGridStroke = new NStroke(NColor.Orange);
			m_SecondVerticalSection.MajorTickStroke = new NStroke(NColor.DarkOrange);
			m_SecondVerticalSection.MinorTickStroke = new NStroke(1, NColor.Orange, ENDashStyle.Dot);

			labelStyle = new NTextStyle();
			labelStyle.Fill = new NStockGradientFill(NColor.Orange, NColor.DarkOrange);
			labelStyle.Font.Style = ENFontStyle.Bold;
			m_SecondVerticalSection.LabelTextStyle = labelStyle;

			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_ShowFirstYSectionCheckBox = new NCheckBox("Show Y Section [20, 40]");
			stack.Add(m_ShowFirstYSectionCheckBox);
			m_ShowFirstYSectionCheckBox.Checked = true;

			m_ShowSecondYSectionCheckBox = new NCheckBox("Show Y Section [70, 90]");
			stack.Add(m_ShowSecondYSectionCheckBox);
			m_ShowSecondYSectionCheckBox.Checked = true;

			m_ShowFirstXSectionCheckBox = new NCheckBox("Show X Section [2, 8]");
			stack.Add(m_ShowFirstXSectionCheckBox);
			m_ShowFirstXSectionCheckBox.Checked = true;

			m_ShowSecondXSectionCheckBox = new NCheckBox("Show X Section [14, 18]");
			stack.Add(m_ShowSecondXSectionCheckBox);
			m_ShowSecondXSectionCheckBox.Checked = true;

			m_ShowFirstYSectionCheckBox.CheckedChanged += OnUpdateSections;
			m_ShowSecondYSectionCheckBox.CheckedChanged += OnUpdateSections;
			m_ShowFirstXSectionCheckBox.CheckedChanged += OnUpdateSections;
			m_ShowSecondXSectionCheckBox.CheckedChanged += OnUpdateSections;

			OnUpdateSections(null);

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

This example demonstrates axis sections. Axis sections allow you to alter the appearance of different axis elements if they fall in a specified 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"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnUpdateSections(NValueChangeEventArgs arg) { NStandardScale standardScale; // configure horizontal axis sections standardScale = (NStandardScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale; standardScale.Sections.Clear(); if (m_ShowFirstXSectionCheckBox.Checked) { standardScale.Sections.Add(m_FirstHorizontalSection); } if (m_ShowSecondXSectionCheckBox.Checked) { standardScale.Sections.Add(m_SecondHorizontalSection); } // configure vertical axis sections standardScale = (NStandardScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale; standardScale.Sections.Clear(); if (m_ShowFirstYSectionCheckBox.Checked) { standardScale.Sections.Add(m_FirstVerticalSection); } if (m_ShowSecondYSectionCheckBox.Checked) { standardScale.Sections.Add(m_SecondVerticalSection); } } #endregion #region Fields private NCartesianChart m_Chart; private NCheckBox m_ShowFirstYSectionCheckBox; private NCheckBox m_ShowSecondYSectionCheckBox; private NCheckBox m_ShowFirstXSectionCheckBox; private NCheckBox m_ShowSecondXSectionCheckBox; private NScaleSection m_FirstVerticalSection; private NScaleSection m_SecondVerticalSection; private NScaleSection m_FirstHorizontalSection; private NScaleSection m_SecondHorizontalSection; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

Related Documentation Links