Hierarchical Scale Example for WPF

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

Hierarchical Scale Example for WPF Description

This example demonstrates how to create a hierarchical scale.


Hierarchical Scale Example

C# Hierarchical Scale Example Code for Nevron Chart for WPF
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 WPF Solution

VB.NET Hierarchical Scale Example Code for Nevron Chart for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System

Class MainWindow

#Region "Constructors"

	Public Sub New()
		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NHierarchicalScaleExample"

		' Create the NOV example and its controls
		Dim exampleContent As NWidget = CreateExampleContent()
		Dim exampleControls As NWidget = CreateExampleControls()
		If Not exampleControls Is Nothing Then
			exampleControls.PreferredWidth = 300
		End If

		' Place the example and its controls in a pair box
		Dim pairBox As NPairBox = 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
		Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
		Content = host
	End Sub


#End Region

#Region "Example"

        ''' 
        ''' 
        ''' 
        ''' 
        Public Function CreateExampleContent() As NWidget
            Dim chartViewWithCommandBars As NChartViewWithCommandBars = New NChartViewWithCommandBars()
            Dim chartView = chartViewWithCommandBars.View
            chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)

            ' configure title
            chartView.Surface.Titles(0).Text = "Hierarchical Scale"

            ' configure chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)

            ' 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
            Dim linearScale As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale

            ' add interlace stripe
            Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            stripStyle.Interlaced = True
            linearScale.Strips.Add(stripStyle)

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

            Return chartViewWithCommandBars
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)

            m_FirstRowGridStyleComboBox = New NComboBox()
            m_FirstRowGridStyleComboBox.Items.FillFromEnum(Of ENFirstRowGridStyle)()
            Me.m_FirstRowGridStyleComboBox.SelectedIndexChanged += AddressOf OnUpdateScale
            stack.Add(NPairBox.Create("Grid Style:", m_FirstRowGridStyleComboBox))

            m_FirstRowTickModeComboBox = New NComboBox()
            m_FirstRowTickModeComboBox.Items.FillFromEnum(Of ENRangeLabelTickMode)()
            Me.m_FirstRowTickModeComboBox.SelectedIndexChanged += AddressOf OnUpdateScale
            stack.Add(NPairBox.Create("Tick Mode:", m_FirstRowTickModeComboBox))

            m_GroupRowGridStyleComboBox = New NComboBox()
            m_GroupRowGridStyleComboBox.Items.FillFromEnum(Of ENGroupRowGridStyle)()
            Me.m_GroupRowGridStyleComboBox.SelectedIndexChanged += AddressOf OnUpdateScale
            stack.Add(NPairBox.Create("Grid Style:", m_GroupRowGridStyleComboBox))

            m_GroupRowTickModeComboBox = New NComboBox()
            m_GroupRowTickModeComboBox.Items.FillFromEnum(Of ENRangeLabelTickMode)()
            Me.m_GroupRowTickModeComboBox.SelectedIndexChanged += AddressOf OnUpdateScale
            stack.Add(NPairBox.Create("Tick Mode:", m_GroupRowTickModeComboBox))

            m_CreateSeparatorForEachLevelCheckBox = New NCheckBox("Create Separator For Each Level")
            Me.m_CreateSeparatorForEachLevelCheckBox.CheckedChanged += AddressOf OnUpdateScale
            stack.Add(m_CreateSeparatorForEachLevelCheckBox)

            Dim changeDataButton As NButton = New NButton("Change Data")
            changeDataButton.Click += AddressOf OnChangeDataButtonClick
            stack.Add(changeDataButton)

            m_FirstRowGridStyleComboBox.SelectedIndex = CInt(ENFirstRowGridStyle.Individual)
            m_FirstRowTickModeComboBox.SelectedIndex = CInt(ENRangeLabelTickMode.Separators)
            m_GroupRowGridStyleComboBox.SelectedIndex = CInt(ENGroupRowGridStyle.Individual)
            m_GroupRowTickModeComboBox.SelectedIndex = CInt(ENRangeLabelTickMode.Separators)
            m_CreateSeparatorForEachLevelCheckBox.Checked = True

            OnChangeDataButtonClick(Nothing)
            OnUpdateScale(Nothing)

            Return boxGroup
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create a hierarchical scale.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Hierarchical Scale", "https://www.nevron.com/docs/openvision/hierarchical-scale.html"), ("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnChangeDataButtonClick(arg As NEventArgs) ' fill with random data m_Bar1.DataPoints.Clear() m_Bar2.DataPoints.Clear() Dim random As Random = New Random() For i = 0 To 23 m_Bar1.DataPoints.Add(New NBarDataPoint(random.Next(10, 200))) m_Bar2.DataPoints.Add(New NBarDataPoint(random.Next(10, 300))) Next End Sub Private Sub OnUpdateScale(arg As NValueChangeEventArgs) ' add custom labels to the X axis Dim scale As NHierarchicalScale = New NHierarchicalScale() scale.FirstRowGridStyle = CType(m_FirstRowGridStyleComboBox.SelectedIndex, ENFirstRowGridStyle) scale.GroupRowGridStyle = CType(m_GroupRowGridStyleComboBox.SelectedIndex, ENGroupRowGridStyle) scale.InnerMajorTicks.Visible = False scale.OuterMajorTicks.Visible = False Dim months = New String() {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"} For i = 0 To 1 Dim yearNode As NHierarchicalScaleNode = New NHierarchicalScaleNode(0, (i + Date.Now.Year - 2).ToString()) yearNode.LabelStyle.TickMode = CType(m_GroupRowTickModeComboBox.SelectedIndex, ENRangeLabelTickMode) scale.ChildNodes.Add(yearNode) For j = 0 To 3 Dim quarterNode As NHierarchicalScaleNode = New NHierarchicalScaleNode(3, "Q" & (j + 1).ToString()) quarterNode.LabelStyle.TickMode = CType(m_GroupRowTickModeComboBox.SelectedIndex, ENRangeLabelTickMode) yearNode.ChildNodes.Add(quarterNode) For k = 0 To 2 Dim monthNode As NHierarchicalScaleNode = New NHierarchicalScaleNode(1, months(j * 3 + k)) monthNode.LabelStyle.Angle = New NScaleLabelAngle(90) monthNode.LabelStyle.TickMode = CType(m_FirstRowTickModeComboBox.SelectedIndex, ENRangeLabelTickMode) quarterNode.ChildNodes.Add(monthNode) Next Next Next ' update control state m_FirstRowTickModeComboBox.Enabled = m_FirstRowGridStyleComboBox.SelectedIndex Is ENFirstRowGridStyle.Individual m_GroupRowTickModeComboBox.Enabled = m_GroupRowGridStyleComboBox.SelectedIndex Is ENGroupRowGridStyle.Individual scale.CreateSeparatorForEachLevel = m_CreateSeparatorForEachLevelCheckBox.Checked m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale = scale End Sub #End Region #Region "Fields" Private m_Chart As NCartesianChart Private m_Bar1 As NBarSeries Private m_Bar2 As NBarSeries Private m_FirstRowGridStyleComboBox As NComboBox Private m_FirstRowTickModeComboBox As NComboBox Private m_GroupRowGridStyleComboBox As NComboBox Private m_GroupRowTickModeComboBox As NComboBox Private m_CreateSeparatorForEachLevelCheckBox As NCheckBox #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Hierarchical Scale Example for WPF Solution

Related Documentation Links