Hierarchical Scale Example for Blazor

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

Hierarchical Scale Example for Blazor Description

This example demonstrates how to create a hierarchical scale.


Hierarchical Scale Example

C# Hierarchical 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 - NHierarchicalScaleExample";

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

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

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

            // add the first bar
            m_Bar1 = new NBarSeries();
			m_Chart.Series.Add(m_Bar1);
			m_Bar1.Name = "Coca Cola";
			m_Bar1.MultiBarMode = ENMultiBarMode.Series;
			m_Bar1.DataLabelStyle = new NDataLabelStyle(false);

			// add the second bar
			m_Bar2 = new NBarSeries();
			m_Chart.Series.Add(m_Bar2);
			m_Bar2.Name = "Pepsi";
			m_Bar2.MultiBarMode = ENMultiBarMode.Clustered;
			m_Bar2.DataLabelStyle = new NDataLabelStyle(false);

			// add custom labels to the Y axis
			NLinearScale linearScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;

			// add interlace stripe
			NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
			stripStyle.Interlaced = true;
			linearScale.Strips.Add(stripStyle);

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

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

			m_FirstRowGridStyleComboBox = new NComboBox();
			m_FirstRowGridStyleComboBox.Items.FillFromEnum();
			m_FirstRowGridStyleComboBox.SelectedIndexChanged += OnUpdateScale;
			stack.Add(NPairBox.Create("Grid Style:", m_FirstRowGridStyleComboBox));
			
			m_FirstRowTickModeComboBox = new NComboBox();
			m_FirstRowTickModeComboBox.Items.FillFromEnum();
			m_FirstRowTickModeComboBox.SelectedIndexChanged += OnUpdateScale;
			stack.Add(NPairBox.Create("Tick Mode:", m_FirstRowTickModeComboBox));

			m_GroupRowGridStyleComboBox = new NComboBox();
			m_GroupRowGridStyleComboBox.Items.FillFromEnum();
			m_GroupRowGridStyleComboBox.SelectedIndexChanged += OnUpdateScale;
			stack.Add(NPairBox.Create("Grid Style:", m_GroupRowGridStyleComboBox));

			m_GroupRowTickModeComboBox = new NComboBox();
			m_GroupRowTickModeComboBox.Items.FillFromEnum();
			m_GroupRowTickModeComboBox.SelectedIndexChanged += OnUpdateScale;
			stack.Add(NPairBox.Create("Tick Mode:", m_GroupRowTickModeComboBox));
																 
			m_CreateSeparatorForEachLevelCheckBox = new NCheckBox("Create Separator For Each Level");
			m_CreateSeparatorForEachLevelCheckBox.CheckedChanged += OnUpdateScale;
			stack.Add(m_CreateSeparatorForEachLevelCheckBox);

			NButton changeDataButton = new NButton("Change Data");
			changeDataButton.Click += OnChangeDataButtonClick;
			stack.Add(changeDataButton);

			m_FirstRowGridStyleComboBox.SelectedIndex = (int)ENFirstRowGridStyle.Individual;
			m_FirstRowTickModeComboBox.SelectedIndex = (int)ENRangeLabelTickMode.Separators;
			m_GroupRowGridStyleComboBox.SelectedIndex = (int)ENGroupRowGridStyle.Individual;
			m_GroupRowTickModeComboBox.SelectedIndex = (int)ENRangeLabelTickMode.Separators;
			m_CreateSeparatorForEachLevelCheckBox.Checked = true;

			OnChangeDataButtonClick(null);
			OnUpdateScale(null);

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

This example demonstrates how to create a hierarchical scale.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Hierarchical Scale", "https://www.nevron.com/docs/openvision/hierarchical-scale.html"), ("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnChangeDataButtonClick(NEventArgs arg) { // fill with random data m_Bar1.DataPoints.Clear(); m_Bar2.DataPoints.Clear(); Random random = new Random(); for (int i = 0; i < 24; i++) { m_Bar1.DataPoints.Add(new NBarDataPoint(random.Next(10, 200))); m_Bar2.DataPoints.Add(new NBarDataPoint(random.Next(10, 300))); } } void OnUpdateScale(NValueChangeEventArgs arg) { // add custom labels to the X axis NHierarchicalScale scale = new NHierarchicalScale(); scale.FirstRowGridStyle = (ENFirstRowGridStyle)m_FirstRowGridStyleComboBox.SelectedIndex; scale.GroupRowGridStyle = (ENGroupRowGridStyle)m_GroupRowGridStyleComboBox.SelectedIndex; scale.InnerMajorTicks.Visible = false; scale.OuterMajorTicks.Visible = false; string[] months = new string[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; for (int i = 0; i < 2; i++) { NHierarchicalScaleNode yearNode = new NHierarchicalScaleNode(0, (i + DateTime.Now.Year - 2).ToString()); yearNode.LabelStyle.TickMode = (ENRangeLabelTickMode)m_GroupRowTickModeComboBox.SelectedIndex; scale.ChildNodes.Add(yearNode); for (int j = 0; j < 4; j++) { NHierarchicalScaleNode quarterNode = new NHierarchicalScaleNode(3, "Q" + (j + 1).ToString()); quarterNode.LabelStyle.TickMode = (ENRangeLabelTickMode)m_GroupRowTickModeComboBox.SelectedIndex; yearNode.ChildNodes.Add(quarterNode); for (int k = 0; k < 3; k++) { NHierarchicalScaleNode monthNode = new NHierarchicalScaleNode(1, months[j * 3 + k]); monthNode.LabelStyle.Angle = new NScaleLabelAngle(90); monthNode.LabelStyle.TickMode = (ENRangeLabelTickMode)m_FirstRowTickModeComboBox.SelectedIndex; quarterNode.ChildNodes.Add(monthNode); } } } // update control state m_FirstRowTickModeComboBox.Enabled = ((ENFirstRowGridStyle)m_FirstRowGridStyleComboBox.SelectedIndex) == ENFirstRowGridStyle.Individual; m_GroupRowTickModeComboBox.Enabled = ((ENGroupRowGridStyle)m_GroupRowGridStyleComboBox.SelectedIndex) == ENGroupRowGridStyle.Individual; scale.CreateSeparatorForEachLevel = m_CreateSeparatorForEachLevelCheckBox.Checked; m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = scale; } #endregion #region Fields NCartesianChart m_Chart; NBarSeries m_Bar1; NBarSeries m_Bar2; NComboBox m_FirstRowGridStyleComboBox; NComboBox m_FirstRowTickModeComboBox; NComboBox m_GroupRowGridStyleComboBox; NComboBox m_GroupRowTickModeComboBox; NCheckBox m_CreateSeparatorForEachLevelCheckBox; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

Related Documentation Links