Axis Stripes 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.

Axis Stripes Example for WPF Description

This example demonstrates how to configure axis stripes.


Axis Stripes Example

C# Axis Stripes 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.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NAxisStripesExample";

			// 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 Stripes";

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

			// configure axes
			chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);

			// configure the y scale
			NLinearScale yScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;

			NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
			stripStyle.Interlaced = true;
			yScale.Strips.Add(stripStyle);

			yScale.MajorGridLines.Visible = true;

			// Create a point series
			NPointSeries point = new NPointSeries();
			point.InflateMargins = true;
			point.UseXValues = true;
			point.Name = "Series 1";
			chart.Series.Add(point);

			NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
			dataLabelStyle.Visible = false;
			point.DataLabelStyle = dataLabelStyle;

			// Add some data
			double[] yValues = new double[] { 31, 67, 12, 84, 90 };
			double[] xValues = new double[] { 5, 36, 51, 76, 93 };

			for (int i = 0; i < yValues.Length; i++)
			{
				point.DataPoints.Add(new NPointDataPoint(xValues[i], yValues[i]));
			}

			// Add a constline for the left axis
			m_XStripe = new NAxisStripe();
			m_XStripe.Fill = new NColorFill(NColor.FromColor(NColor.SteelBlue, 0.5f));
			m_XStripe.Range = new NRange (40, 60);
			m_XStripe.Text = "X Axis Stripe";
			chart.Axes[ENCartesianAxis.PrimaryX].Stripes.Add(m_XStripe);

			// Add a constline for the bottom axis
			m_YStripe = new NAxisStripe();
			m_YStripe.Fill = new NColorFill(NColor.FromColor(NColor.SteelBlue, 0.5f));
			m_YStripe.Range = new NRange(40, 60);
			m_YStripe.Text = "Y Axis Stripe";
			chart.Axes[ENCartesianAxis.PrimaryY].Stripes.Add(m_YStripe);

			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 Stripe"));

			NNumericUpDown yStripeBeginValueUpDown = new NNumericUpDown();
			yStripeBeginValueUpDown.ValueChanged += OnYStripeBeginValueUpDownValueChanged;
			yStripeBeginValueUpDown.Value = m_YStripe.Range.Begin;
			stack.Add(NPairBox.Create("Begin Value:", yStripeBeginValueUpDown));

			NNumericUpDown yStripeEndValueUpDown = new NNumericUpDown();
			yStripeEndValueUpDown.ValueChanged += OnYStripeEndValueUpDownValueChanged;
			yStripeEndValueUpDown.Value = m_YStripe.Range.End;
			stack.Add(NPairBox.Create("End Value:", yStripeEndValueUpDown));

			NCheckBox yStripeIncludeInAxisRangeCheckBox = new NCheckBox("Include in Axis Range");
			yStripeIncludeInAxisRangeCheckBox.Checked = false;
			yStripeIncludeInAxisRangeCheckBox.CheckedChanged += OnStripeIncludeInAxisRangeCheckBoxCheckedChanged;
			stack.Add(yStripeIncludeInAxisRangeCheckBox);

			NCheckBox yStripePaintAfterSeriesCheckBox = new NCheckBox("Paint After Series");
			yStripePaintAfterSeriesCheckBox.Checked = m_YStripe.PaintAfterChartContent;
			yStripePaintAfterSeriesCheckBox.CheckedChanged += OnYStripePaintAfterSeriesCheckBoxCheckedChanged;
			stack.Add(yStripePaintAfterSeriesCheckBox);

			NComboBox yTextAlignmentComboBox = new NComboBox();
			yTextAlignmentComboBox.Items.FillFromEnum();
			yTextAlignmentComboBox.SelectedIndex = (int)m_YStripe.TextAlignment;
			yTextAlignmentComboBox.SelectedIndexChanged += OnYTextAlignmentComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Text Alignment:", yTextAlignmentComboBox));

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

			NNumericUpDown xStripeBeginValueUpDown = new NNumericUpDown();
			xStripeBeginValueUpDown.Value = m_XStripe.Range.Begin;
			xStripeBeginValueUpDown.ValueChanged += OnXStripeBeginValueUpDownValueChanged;
			stack.Add(NPairBox.Create("Begin Value:", xStripeBeginValueUpDown));

			NNumericUpDown xStripeEndValueUpDown = new NNumericUpDown();
			xStripeEndValueUpDown.Value = m_XStripe.Range.End;
			xStripeEndValueUpDown.ValueChanged += OnXStripeEndValueUpDownValueChanged;
			stack.Add(NPairBox.Create("End Value:", xStripeEndValueUpDown));

			NCheckBox xStripeIncludeInAxisRangeCheckBox = new NCheckBox("Include in Axis Range");
			xStripeIncludeInAxisRangeCheckBox.Checked = false;
			xStripeIncludeInAxisRangeCheckBox.CheckedChanged += OnXStripeIncludeInAxisRangeCheckBoxCheckedChanged;
			stack.Add(xStripeIncludeInAxisRangeCheckBox);

			NCheckBox xStripePaintAfterSeriesCheckBox = new NCheckBox("Paint After Series");
			xStripePaintAfterSeriesCheckBox.Checked = m_XStripe.PaintAfterChartContent;
			xStripePaintAfterSeriesCheckBox.CheckedChanged += OnXStripePaintAfterSeriesCheckBoxCheckedChanged;
			stack.Add(xStripePaintAfterSeriesCheckBox);

			NComboBox xTextAlignmentComboBox = new NComboBox();
			xTextAlignmentComboBox.Items.FillFromEnum();
			xTextAlignmentComboBox.SelectedIndex = (int)m_XStripe.TextAlignment;
			xTextAlignmentComboBox.SelectedIndexChanged += OnXTextAlignmentComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Text Alignment:", xTextAlignmentComboBox));

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

This example demonstrates how to configure axis stripes.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Scale Strip Lines", "https://www.nevron.com/docs/openvision/scale-strip-lines.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnXStripeBeginValueUpDownValueChanged(NValueChangeEventArgs arg) { m_XStripe.Range = new NRange(((NNumericUpDown)arg.TargetNode).Value, m_XStripe.Range.End); } void OnXStripeEndValueUpDownValueChanged(NValueChangeEventArgs arg) { m_XStripe.Range = new NRange(m_XStripe.Range.Begin, ((NNumericUpDown)arg.TargetNode).Value); } void OnXStripeIncludeInAxisRangeCheckBoxCheckedChanged(NValueChangeEventArgs arg) { bool isChecked = ((NCheckBox)arg.TargetNode).Checked; m_XStripe.IncludeRangeBeginInAxisRange = isChecked; m_XStripe.IncludeRangeEndInAxisRange = isChecked; } void OnXStripePaintAfterSeriesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_XStripe.PaintAfterChartContent = ((NCheckBox)arg.TargetNode).Checked; } void OnXTextAlignmentComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_XStripe.TextAlignment = (ENContentAlignment)((NComboBox)arg.TargetNode).SelectedIndex; } void OnYStripeBeginValueUpDownValueChanged(NValueChangeEventArgs arg) { m_YStripe.Range = new NRange(((NNumericUpDown)arg.TargetNode).Value, m_YStripe.Range.End); } void OnYStripeEndValueUpDownValueChanged(NValueChangeEventArgs arg) { m_YStripe.Range = new NRange(m_YStripe.Range.Begin, ((NNumericUpDown)arg.TargetNode).Value); } void OnStripeIncludeInAxisRangeCheckBoxCheckedChanged(NValueChangeEventArgs arg) { bool isChecked = ((NCheckBox)arg.TargetNode).Checked; m_YStripe.IncludeRangeBeginInAxisRange = isChecked; m_YStripe.IncludeRangeEndInAxisRange = isChecked; } void OnYStripePaintAfterSeriesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_YStripe.PaintAfterChartContent = ((NCheckBox)arg.TargetNode).Checked; } void OnYTextAlignmentComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_YStripe.TextAlignment = (ENContentAlignment)((NComboBox)arg.TargetNode).SelectedIndex; } #endregion #region Fields NAxisStripe m_XStripe; NAxisStripe m_YStripe; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Axis Stripes Example for WPF Solution

VB.NET Axis Stripes 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

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 - NAxisStripesExample"

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

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

            ' configure axes
            chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)

            ' configure the y scale
            Dim yScale As NLinearScale = chart.Axes(ENCartesianAxis.PrimaryY).Scale

            Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            stripStyle.Interlaced = True
            yScale.Strips.Add(stripStyle)

            yScale.MajorGridLines.Visible = True

            ' Create a point series
            Dim point As NPointSeries = New NPointSeries()
            point.InflateMargins = True
            point.UseXValues = True
            point.Name = "Series 1"
            chart.Series.Add(point)

            Dim dataLabelStyle As NDataLabelStyle = New NDataLabelStyle()
            dataLabelStyle.Visible = False
            point.DataLabelStyle = dataLabelStyle

            ' Add some data
            Dim yValues = New Double() {31, 67, 12, 84, 90}
            Dim xValues = New Double() {5, 36, 51, 76, 93}

            For i = 0 To yValues.Length - 1
                point.DataPoints.Add(New NPointDataPoint(xValues(i), yValues(i)))
            Next

            ' Add a constline for the left axis
            m_XStripe = New NAxisStripe()
            m_XStripe.Fill = New NColorFill(NColor.FromColor(NColor.SteelBlue, 0.5F))
            m_XStripe.Range = New NRange(40, 60)
            m_XStripe.Text = "X Axis Stripe"
            chart.Axes(ENCartesianAxis.PrimaryX).Stripes.Add(m_XStripe)

            ' Add a constline for the bottom axis
            m_YStripe = New NAxisStripe()
            m_YStripe.Fill = New NColorFill(NColor.FromColor(NColor.SteelBlue, 0.5F))
            m_YStripe.Range = New NRange(40, 60)
            m_YStripe.Text = "Y Axis Stripe"
            chart.Axes(ENCartesianAxis.PrimaryY).Stripes.Add(m_YStripe)

            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 Stripe"))

            Dim yStripeBeginValueUpDown As NNumericUpDown = New NNumericUpDown()
            yStripeBeginValueUpDown.ValueChanged += AddressOf OnYStripeBeginValueUpDownValueChanged
            yStripeBeginValueUpDown.Value = m_YStripe.Range.Begin
            stack.Add(NPairBox.Create("Begin Value:", yStripeBeginValueUpDown))

            Dim yStripeEndValueUpDown As NNumericUpDown = New NNumericUpDown()
            yStripeEndValueUpDown.ValueChanged += AddressOf OnYStripeEndValueUpDownValueChanged
            yStripeEndValueUpDown.Value = m_YStripe.Range.End
            stack.Add(NPairBox.Create("End Value:", yStripeEndValueUpDown))

            Dim yStripeIncludeInAxisRangeCheckBox As NCheckBox = New NCheckBox("Include in Axis Range")
            yStripeIncludeInAxisRangeCheckBox.Checked = False
            yStripeIncludeInAxisRangeCheckBox.CheckedChanged += AddressOf OnStripeIncludeInAxisRangeCheckBoxCheckedChanged
            stack.Add(yStripeIncludeInAxisRangeCheckBox)

            Dim yStripePaintAfterSeriesCheckBox As NCheckBox = New NCheckBox("Paint After Series")
            yStripePaintAfterSeriesCheckBox.Checked = m_YStripe.PaintAfterChartContent
            yStripePaintAfterSeriesCheckBox.CheckedChanged += AddressOf OnYStripePaintAfterSeriesCheckBoxCheckedChanged
            stack.Add(yStripePaintAfterSeriesCheckBox)

            Dim yTextAlignmentComboBox As NComboBox = New NComboBox()
            yTextAlignmentComboBox.Items.FillFromEnum(Of ENContentAlignment)()
            yTextAlignmentComboBox.SelectedIndex = m_YStripe.TextAlignment
            yTextAlignmentComboBox.SelectedIndexChanged += AddressOf OnYTextAlignmentComboBoxSelectedIndexChanged
            stack.Add(NPairBox.Create("Text Alignment:", yTextAlignmentComboBox))

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

            Dim xStripeBeginValueUpDown As NNumericUpDown = New NNumericUpDown()
            xStripeBeginValueUpDown.Value = m_XStripe.Range.Begin
            xStripeBeginValueUpDown.ValueChanged += AddressOf OnXStripeBeginValueUpDownValueChanged
            stack.Add(NPairBox.Create("Begin Value:", xStripeBeginValueUpDown))

            Dim xStripeEndValueUpDown As NNumericUpDown = New NNumericUpDown()
            xStripeEndValueUpDown.Value = m_XStripe.Range.End
            xStripeEndValueUpDown.ValueChanged += AddressOf OnXStripeEndValueUpDownValueChanged
            stack.Add(NPairBox.Create("End Value:", xStripeEndValueUpDown))

            Dim xStripeIncludeInAxisRangeCheckBox As NCheckBox = New NCheckBox("Include in Axis Range")
            xStripeIncludeInAxisRangeCheckBox.Checked = False
            xStripeIncludeInAxisRangeCheckBox.CheckedChanged += AddressOf OnXStripeIncludeInAxisRangeCheckBoxCheckedChanged
            stack.Add(xStripeIncludeInAxisRangeCheckBox)

            Dim xStripePaintAfterSeriesCheckBox As NCheckBox = New NCheckBox("Paint After Series")
            xStripePaintAfterSeriesCheckBox.Checked = m_XStripe.PaintAfterChartContent
            xStripePaintAfterSeriesCheckBox.CheckedChanged += AddressOf OnXStripePaintAfterSeriesCheckBoxCheckedChanged
            stack.Add(xStripePaintAfterSeriesCheckBox)

            Dim xTextAlignmentComboBox As NComboBox = New NComboBox()
            xTextAlignmentComboBox.Items.FillFromEnum(Of ENContentAlignment)()
            xTextAlignmentComboBox.SelectedIndex = m_XStripe.TextAlignment
            xTextAlignmentComboBox.SelectedIndexChanged += AddressOf OnXTextAlignmentComboBoxSelectedIndexChanged
            stack.Add(NPairBox.Create("Text Alignment:", xTextAlignmentComboBox))

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

This example demonstrates how to configure axis stripes.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Scale Strip Lines", "https://www.nevron.com/docs/openvision/scale-strip-lines.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 OnXStripeBeginValueUpDownValueChanged(arg As NValueChangeEventArgs) m_XStripe.Range = New NRange(CType(arg.TargetNode, NNumericUpDown).Value, m_XStripe.Range.End) End Sub Private Sub OnXStripeEndValueUpDownValueChanged(arg As NValueChangeEventArgs) m_XStripe.Range = New NRange(m_XStripe.Range.Begin, CType(arg.TargetNode, NNumericUpDown).Value) End Sub Private Sub OnXStripeIncludeInAxisRangeCheckBoxCheckedChanged(arg As NValueChangeEventArgs) Dim isChecked = CType(arg.TargetNode, NCheckBox).Checked m_XStripe.IncludeRangeBeginInAxisRange = isChecked m_XStripe.IncludeRangeEndInAxisRange = isChecked End Sub Private Sub OnXStripePaintAfterSeriesCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_XStripe.PaintAfterChartContent = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnXTextAlignmentComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) m_XStripe.TextAlignment = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENContentAlignment) End Sub Private Sub OnYStripeBeginValueUpDownValueChanged(arg As NValueChangeEventArgs) m_YStripe.Range = New NRange(CType(arg.TargetNode, NNumericUpDown).Value, m_YStripe.Range.End) End Sub Private Sub OnYStripeEndValueUpDownValueChanged(arg As NValueChangeEventArgs) m_YStripe.Range = New NRange(m_YStripe.Range.Begin, CType(arg.TargetNode, NNumericUpDown).Value) End Sub Private Sub OnStripeIncludeInAxisRangeCheckBoxCheckedChanged(arg As NValueChangeEventArgs) Dim isChecked = CType(arg.TargetNode, NCheckBox).Checked m_YStripe.IncludeRangeBeginInAxisRange = isChecked m_YStripe.IncludeRangeEndInAxisRange = isChecked End Sub Private Sub OnYStripePaintAfterSeriesCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_YStripe.PaintAfterChartContent = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnYTextAlignmentComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) m_YStripe.TextAlignment = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENContentAlignment) End Sub #End Region #Region "Fields" Private m_XStripe As NAxisStripe Private m_YStripe As NAxisStripe #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 Stripes Example for WPF Solution

Related Documentation Links