Scale Sections Example for WinForms

Nevron NOV Chart for WinForms ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WinForms 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.

Scale Sections Example for WinForms 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 WinForms
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 WinForms Solution

VB.NET Scale Sections Example Code for Nevron Chart for WinForms
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.Forms
Imports System

Public Class Form1

#Region "Constructors"

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

        ' Add any initialization after the InitializeComponent() call.

        ' Set form title
        Text = "NOV WinForms - NScaleSectionsExample"

        ' 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)
        host.Dock = DockStyle.Fill
        Controls.Add(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 = "Scale Sections"

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

            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear)

            ' create a point series
            Dim point As NPointSeries = New NPointSeries()
            point.Name = "Point Series"
            point.DataLabelStyle = New NDataLabelStyle(False)
            point.Size = 5

            Dim random As Random = New Random()

            For i = 0 To 29
                point.DataPoints.Add(New NPointDataPoint(random.Next(100), random.Next(100)))
            Next

            point.InflateMargins = True

            m_Chart.Series.Add(point)

            ' tell the x axis to display major and minor grid lines
            Dim linearScale As NLinearScale = 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

            Dim labelStyle As NTextStyle

            ' 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
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            Dim boxGroup As NUniSizeBoxGroup = 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

            Me.m_ShowFirstYSectionCheckBox.CheckedChanged += AddressOf OnUpdateSections
            Me.m_ShowSecondYSectionCheckBox.CheckedChanged += AddressOf OnUpdateSections
            Me.m_ShowFirstXSectionCheckBox.CheckedChanged += AddressOf OnUpdateSections
            Me.m_ShowSecondXSectionCheckBox.CheckedChanged += AddressOf OnUpdateSections

            OnUpdateSections(Nothing)

            Return boxGroup
        End Function
        Public Function GetExampleDescription() As String
            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.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Scale Sections", "https://www.nevron.com/docs/openvision/scale-sections.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnUpdateSections(arg As NValueChangeEventArgs) Dim standardScale As NStandardScale ' configure horizontal axis sections standardScale = m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale standardScale.Sections.Clear() If m_ShowFirstXSectionCheckBox.Checked Then standardScale.Sections.Add(m_FirstHorizontalSection) End If If m_ShowSecondXSectionCheckBox.Checked Then standardScale.Sections.Add(m_SecondHorizontalSection) End If ' configure vertical axis sections standardScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale standardScale.Sections.Clear() If m_ShowFirstYSectionCheckBox.Checked Then standardScale.Sections.Add(m_FirstVerticalSection) End If If m_ShowSecondYSectionCheckBox.Checked Then standardScale.Sections.Add(m_SecondVerticalSection) End If End Sub #End Region #Region "Fields" Private m_Chart As NCartesianChart Private m_ShowFirstYSectionCheckBox As NCheckBox Private m_ShowSecondYSectionCheckBox As NCheckBox Private m_ShowFirstXSectionCheckBox As NCheckBox Private m_ShowSecondXSectionCheckBox As NCheckBox Private m_FirstVerticalSection As NScaleSection Private m_SecondVerticalSection As NScaleSection Private m_FirstHorizontalSection As NScaleSection Private m_SecondHorizontalSection As NScaleSection #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) Scale Sections Example for WinForms Solution

Related Documentation Links