Axis Grid Lines 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.

Axis Grid Lines Example for WinForms Description

This example demonstrates how to configure the axis gridllines.


Axis Grid Lines Example

C# Axis Grid Lines 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 - NAxisGridLinesExample";

			// 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 = "Axis Gridlines";

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

			// configure axes
			m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
			NLinearScale scaleY = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;

			// add interlaced stripe
			NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
			strip.Interlaced = true;
			scaleY.Strips.Add(strip);

			// enable the major y grid lines
			scaleY.MajorGridLines = new NScaleGridLines();

			NOrdinalScale scaleX = (NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale;

			// enable the major x grid lines
			scaleX.MajorGridLines = new NScaleGridLines();

			// create dummy data
			NBarSeries bar = new NBarSeries();
			bar.Name = "Bars";
			bar.DataLabelStyle = new NDataLabelStyle(false);
			Random random = new Random();
			for (int i = 0; i < 10; i++)
			{
				bar.DataPoints.Add(new NBarDataPoint(random.Next(100)));
			}

            m_Chart.Series.Add(bar);

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

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

			stack.Add(new NLabel("Y Axis Grid"));

			NNumericUpDown yAxisGridWidth = new NNumericUpDown();
			yAxisGridWidth.Minimum = 0;
            yAxisGridWidth.Maximum = 10;
			yAxisGridWidth.Value = 1;
            yAxisGridWidth.ValueChanged += OnYAxisGridWidthValueChanged;
            stack.Add(NPairBox.Create("Width:", yAxisGridWidth));

            NColorBox yAxisGridColor = new NColorBox();
			yAxisGridColor.SelectedColorChanged += OnYAxisGridColorSelectedColorChanged;
			stack.Add(NPairBox.Create("Color", yAxisGridColor));
			yAxisGridColor.SelectedColor = NColor.Black;

			NComboBox yAxisGridStyle = new NComboBox();
			yAxisGridStyle.Items.FillFromEnum();
			yAxisGridStyle.SelectedIndexChanged += OnYAxisGridStyleSelectedIndexChanged;
			stack.Add(NPairBox.Create("Style:", yAxisGridStyle));
			yAxisGridStyle.SelectedIndex = (int)ENDashStyle.Solid;

			stack.Add(new NLabel("X Axis Grid"));

            NNumericUpDown xAxisGridWidth = new NNumericUpDown();
            xAxisGridWidth.Minimum = 0;
            xAxisGridWidth.Maximum = 10;
			xAxisGridWidth.Value = 1;
            xAxisGridWidth.ValueChanged += OnXAxisGridWidthValueChanged;
            stack.Add(NPairBox.Create("Width:", xAxisGridWidth));

            NColorBox xAxisGridColor = new NColorBox();
			xAxisGridColor.SelectedColorChanged += OnXAxisGridColorSelectedColorChanged;
			stack.Add(NPairBox.Create("Color", xAxisGridColor));
			xAxisGridColor.SelectedColor = NColor.Black;

			NComboBox xAxisGridStyle = new NComboBox();
			xAxisGridStyle.Items.FillFromEnum();
			xAxisGridStyle.SelectedIndexChanged += OnXAxisGridStyleSelectedIndexChanged;
			stack.Add(NPairBox.Create("Style:", xAxisGridStyle));
			xAxisGridStyle.SelectedIndex = (int)ENDashStyle.Solid;

			return boxGroup;
		}

        public string GetExampleDescription()
		{
			return @"

This example demonstrates how to configure the axis gridllines.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Scale Grid Lines", "https://www.nevron.com/docs/openvision/scale-grid-lines.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnXAxisGridWidthValueChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale.MajorGridLines.Stroke.Width = (double)((NNumericUpDown)arg.TargetNode).Value; } void OnXAxisGridStyleSelectedIndexChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale.MajorGridLines.Stroke.DashStyle = (ENDashStyle)((NComboBox)arg.TargetNode).SelectedIndex; } void OnXAxisGridColorSelectedColorChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale.MajorGridLines.Stroke.Color = ((NColorBox)arg.TargetNode).SelectedColor; } private void OnYAxisGridWidthValueChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale.MajorGridLines.Stroke.Width = (double)((NNumericUpDown)arg.TargetNode).Value; } void OnYAxisGridStyleSelectedIndexChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale.MajorGridLines.Stroke.DashStyle = (ENDashStyle)((NComboBox)arg.TargetNode).SelectedIndex; } void OnYAxisGridColorSelectedColorChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale.MajorGridLines.Stroke.Color = ((NColorBox)arg.TargetNode).SelectedColor; } #endregion #region Fields NCartesianChart m_Chart; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Axis Grid Lines Example for WinForms Solution

VB.NET Axis Grid Lines 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 - NAxisGridLinesExample"

        ' 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 = "Axis Gridlines"

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

            ' configure axes
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
            Dim scaleY As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale

            ' add interlaced stripe
            Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            strip.Interlaced = True
            scaleY.Strips.Add(strip)

            ' enable the major y grid lines
            scaleY.MajorGridLines = New NScaleGridLines()

            Dim scaleX As NOrdinalScale = m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale

            ' enable the major x grid lines
            scaleX.MajorGridLines = New NScaleGridLines()

            ' create dummy data
            Dim bar As NBarSeries = New NBarSeries()
            bar.Name = "Bars"
            bar.DataLabelStyle = New NDataLabelStyle(False)
            Dim random As Random = New Random()
            For i = 0 To 9
                bar.DataPoints.Add(New NBarDataPoint(random.Next(100)))
            Next

            m_Chart.Series.Add(bar)

            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)

            stack.Add(New NLabel("Y Axis Grid"))

            Dim yAxisGridWidth As NNumericUpDown = New NNumericUpDown()
            yAxisGridWidth.Minimum = 0
            yAxisGridWidth.Maximum = 10
            yAxisGridWidth.Value = 1
            yAxisGridWidth.ValueChanged += AddressOf OnYAxisGridWidthValueChanged
            stack.Add(NPairBox.Create("Width:", yAxisGridWidth))

            Dim yAxisGridColor As NColorBox = New NColorBox()
            yAxisGridColor.SelectedColorChanged += AddressOf OnYAxisGridColorSelectedColorChanged
            stack.Add(NPairBox.Create("Color", yAxisGridColor))
            yAxisGridColor.SelectedColor = NColor.Black

            Dim yAxisGridStyle As NComboBox = New NComboBox()
            yAxisGridStyle.Items.FillFromEnum(Of ENDashStyle)()
            yAxisGridStyle.SelectedIndexChanged += AddressOf OnYAxisGridStyleSelectedIndexChanged
            stack.Add(NPairBox.Create("Style:", yAxisGridStyle))
            yAxisGridStyle.SelectedIndex = CInt(ENDashStyle.Solid)

            stack.Add(New NLabel("X Axis Grid"))

            Dim xAxisGridWidth As NNumericUpDown = New NNumericUpDown()
            xAxisGridWidth.Minimum = 0
            xAxisGridWidth.Maximum = 10
            xAxisGridWidth.Value = 1
            xAxisGridWidth.ValueChanged += AddressOf OnXAxisGridWidthValueChanged
            stack.Add(NPairBox.Create("Width:", xAxisGridWidth))

            Dim xAxisGridColor As NColorBox = New NColorBox()
            xAxisGridColor.SelectedColorChanged += AddressOf OnXAxisGridColorSelectedColorChanged
            stack.Add(NPairBox.Create("Color", xAxisGridColor))
            xAxisGridColor.SelectedColor = NColor.Black

            Dim xAxisGridStyle As NComboBox = New NComboBox()
            xAxisGridStyle.Items.FillFromEnum(Of ENDashStyle)()
            xAxisGridStyle.SelectedIndexChanged += AddressOf OnXAxisGridStyleSelectedIndexChanged
            stack.Add(NPairBox.Create("Style:", xAxisGridStyle))
            xAxisGridStyle.SelectedIndex = CInt(ENDashStyle.Solid)

            Return boxGroup
        End Function

        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to configure the axis gridllines.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Scale Grid Lines", "https://www.nevron.com/docs/openvision/scale-grid-lines.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnXAxisGridWidthValueChanged(arg As NValueChangeEventArgs) m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale.MajorGridLines.Stroke.Width = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnXAxisGridStyleSelectedIndexChanged(arg As NValueChangeEventArgs) m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale.MajorGridLines.Stroke.DashStyle = CType(arg.TargetNode, NComboBox).SelectedIndex End Sub Private Sub OnXAxisGridColorSelectedColorChanged(arg As NValueChangeEventArgs) m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale.MajorGridLines.Stroke.Color = CType(arg.TargetNode, NColorBox).SelectedColor End Sub Private Sub OnYAxisGridWidthValueChanged(arg As NValueChangeEventArgs) m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale.MajorGridLines.Stroke.Width = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnYAxisGridStyleSelectedIndexChanged(arg As NValueChangeEventArgs) m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale.MajorGridLines.Stroke.DashStyle = CType(arg.TargetNode, NComboBox).SelectedIndex End Sub Private Sub OnYAxisGridColorSelectedColorChanged(arg As NValueChangeEventArgs) m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale.MajorGridLines.Stroke.Color = CType(arg.TargetNode, NColorBox).SelectedColor End Sub #End Region #Region "Fields" Private m_Chart As NCartesianChart #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) Axis Grid Lines Example for WinForms Solution

Related Documentation Links