Axis Reference Lines 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 Reference Lines Example for WPF Description

This example demonstrates how to add axis reference lines.


Axis Reference Lines Example

C# Axis Reference Lines 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 - NAxisReferenceLinesExample";

			// 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 Reference Lines";

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

			chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);

			// 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_XReferenceLine = new NAxisReferenceLine();
			m_XReferenceLine.Stroke = new NStroke(1, NColor.Red);
			m_XReferenceLine.Value = 40;
			m_XReferenceLine.Text = "X Reference Line";
			m_XReferenceLine.TextStyle = new NTextStyle();
            m_XReferenceLine.TextStyle.Fill = new NColorFill(NColor.Red);
            chart.Axes[ENCartesianAxis.PrimaryX].ReferenceLines.Add(m_XReferenceLine);

			// Add a constline for the bottom axis
			m_YReferenceLine = new NAxisReferenceLine();
			m_YReferenceLine.Stroke = new NStroke(1, NColor.Green);
			m_YReferenceLine.Value = 60;
			m_YReferenceLine.Text = "Y Reference Line";
			m_YReferenceLine.TextStyle = new NTextStyle();
            m_YReferenceLine.TextStyle.Fill = new NColorFill(NColor.Green);
            chart.Axes[ENCartesianAxis.PrimaryY].ReferenceLines.Add(m_YReferenceLine);

			// apply style sheet
			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 Reference Line"));

			NNumericUpDown yReferenceLineValueUpDown = new NNumericUpDown();
			yReferenceLineValueUpDown.ValueChanged +=OnYReferenceLineValueUpDownValueChanged;
			yReferenceLineValueUpDown.Value = m_YReferenceLine.Value;
			stack.Add(NPairBox.Create("Value:", yReferenceLineValueUpDown));

			NCheckBox yReferenceLineIncludeInAxisRangeCheckBox = new NCheckBox("Include Value in Axis Range");
			yReferenceLineIncludeInAxisRangeCheckBox.Checked = m_YReferenceLine.IncludeValueInAxisRange;
			yReferenceLineIncludeInAxisRangeCheckBox.CheckedChanged += OnYReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged;
			stack.Add(yReferenceLineIncludeInAxisRangeCheckBox);

			NCheckBox yReferenceLinePaintAfterSeriesCheckBox = new NCheckBox("Paint After Series");
			yReferenceLinePaintAfterSeriesCheckBox.Checked = m_YReferenceLine.PaintAfterChartContent;
			yReferenceLinePaintAfterSeriesCheckBox.CheckedChanged += OnYReferenceLinePaintAfterSeriesCheckBoxCheckedChanged;
			stack.Add(yReferenceLinePaintAfterSeriesCheckBox);

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

			stack.Add(new NLabel("X Axis Reference Line"));

			NNumericUpDown xReferenceLineValueUpDown = new NNumericUpDown();
			xReferenceLineValueUpDown.Value = m_XReferenceLine.Value;
			xReferenceLineValueUpDown.ValueChanged += OnXReferenceLineValueUpDownValueChanged;
			stack.Add(NPairBox.Create("Value:", xReferenceLineValueUpDown));

			NCheckBox xReferenceLinePaintAfterSeriesCheckBox = new NCheckBox("Paint After Series");
			xReferenceLinePaintAfterSeriesCheckBox.Checked = m_XReferenceLine.PaintAfterChartContent;
			xReferenceLinePaintAfterSeriesCheckBox.CheckedChanged += OnXReferenceLinePaintAfterSeriesCheckBoxCheckedChanged;
			stack.Add(xReferenceLinePaintAfterSeriesCheckBox);

			NCheckBox xReferenceLineIncludeInAxisRangeCheckBox = new NCheckBox("Include Value in Axis Range");
			xReferenceLineIncludeInAxisRangeCheckBox.Checked = m_YReferenceLine.IncludeValueInAxisRange;
			xReferenceLineIncludeInAxisRangeCheckBox.CheckedChanged += OnXReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged;
			stack.Add(xReferenceLineIncludeInAxisRangeCheckBox);

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

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

This example demonstrates how to add axis reference lines.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnXReferenceLineValueUpDownValueChanged(NValueChangeEventArgs arg) { m_XReferenceLine.Value = ((NNumericUpDown)arg.TargetNode).Value; } void OnXReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_XReferenceLine.IncludeValueInAxisRange = ((NCheckBox)arg.TargetNode).Checked; } void OnXReferenceLinePaintAfterSeriesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_XReferenceLine.PaintAfterChartContent = ((NCheckBox)arg.TargetNode).Checked; } void OnXTextAlignmentComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_XReferenceLine.TextAlignment = (ENContentAlignment)((NComboBox)arg.TargetNode).SelectedIndex; } void OnYReferenceLineValueUpDownValueChanged(NValueChangeEventArgs arg) { m_YReferenceLine.Value = ((NNumericUpDown)arg.TargetNode).Value; } void OnYReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_YReferenceLine.IncludeValueInAxisRange = ((NCheckBox)arg.TargetNode).Checked; } void OnYReferenceLinePaintAfterSeriesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_YReferenceLine.PaintAfterChartContent = ((NCheckBox)arg.TargetNode).Checked; } void OnYTextAlignmentComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_YReferenceLine.TextAlignment = (ENContentAlignment)((NComboBox)arg.TargetNode).SelectedIndex; } #endregion #region Fields NAxisReferenceLine m_XReferenceLine; NAxisReferenceLine m_YReferenceLine; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

VB.NET Axis Reference Lines 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 - NAxisReferenceLinesExample"

		' 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 Reference Lines"

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

            chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear)

            ' 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_XReferenceLine = New NAxisReferenceLine()
            m_XReferenceLine.Stroke = New NStroke(1, NColor.Red)
            m_XReferenceLine.Value = 40
            m_XReferenceLine.Text = "X Reference Line"
            m_XReferenceLine.TextStyle = New NTextStyle()
            m_XReferenceLine.TextStyle.Fill = New NColorFill(NColor.Red)
            chart.Axes(ENCartesianAxis.PrimaryX).ReferenceLines.Add(m_XReferenceLine)

            ' Add a constline for the bottom axis
            m_YReferenceLine = New NAxisReferenceLine()
            m_YReferenceLine.Stroke = New NStroke(1, NColor.Green)
            m_YReferenceLine.Value = 60
            m_YReferenceLine.Text = "Y Reference Line"
            m_YReferenceLine.TextStyle = New NTextStyle()
            m_YReferenceLine.TextStyle.Fill = New NColorFill(NColor.Green)
            chart.Axes(ENCartesianAxis.PrimaryY).ReferenceLines.Add(m_YReferenceLine)

            ' apply style sheet
            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 Reference Line"))

            Dim yReferenceLineValueUpDown As NNumericUpDown = New NNumericUpDown()
            yReferenceLineValueUpDown.ValueChanged += AddressOf OnYReferenceLineValueUpDownValueChanged
            yReferenceLineValueUpDown.Value = m_YReferenceLine.Value
            stack.Add(NPairBox.Create("Value:", yReferenceLineValueUpDown))

            Dim yReferenceLineIncludeInAxisRangeCheckBox As NCheckBox = New NCheckBox("Include Value in Axis Range")
            yReferenceLineIncludeInAxisRangeCheckBox.Checked = m_YReferenceLine.IncludeValueInAxisRange
            yReferenceLineIncludeInAxisRangeCheckBox.CheckedChanged += AddressOf OnYReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged
            stack.Add(yReferenceLineIncludeInAxisRangeCheckBox)

            Dim yReferenceLinePaintAfterSeriesCheckBox As NCheckBox = New NCheckBox("Paint After Series")
            yReferenceLinePaintAfterSeriesCheckBox.Checked = m_YReferenceLine.PaintAfterChartContent
            yReferenceLinePaintAfterSeriesCheckBox.CheckedChanged += AddressOf OnYReferenceLinePaintAfterSeriesCheckBoxCheckedChanged
            stack.Add(yReferenceLinePaintAfterSeriesCheckBox)

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

            stack.Add(New NLabel("X Axis Reference Line"))

            Dim xReferenceLineValueUpDown As NNumericUpDown = New NNumericUpDown()
            xReferenceLineValueUpDown.Value = m_XReferenceLine.Value
            xReferenceLineValueUpDown.ValueChanged += AddressOf OnXReferenceLineValueUpDownValueChanged
            stack.Add(NPairBox.Create("Value:", xReferenceLineValueUpDown))

            Dim xReferenceLinePaintAfterSeriesCheckBox As NCheckBox = New NCheckBox("Paint After Series")
            xReferenceLinePaintAfterSeriesCheckBox.Checked = m_XReferenceLine.PaintAfterChartContent
            xReferenceLinePaintAfterSeriesCheckBox.CheckedChanged += AddressOf OnXReferenceLinePaintAfterSeriesCheckBoxCheckedChanged
            stack.Add(xReferenceLinePaintAfterSeriesCheckBox)

            Dim xReferenceLineIncludeInAxisRangeCheckBox As NCheckBox = New NCheckBox("Include Value in Axis Range")
            xReferenceLineIncludeInAxisRangeCheckBox.Checked = m_YReferenceLine.IncludeValueInAxisRange
            xReferenceLineIncludeInAxisRangeCheckBox.CheckedChanged += AddressOf OnXReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged
            stack.Add(xReferenceLineIncludeInAxisRangeCheckBox)

            Dim xTextAlignmentComboBox As NComboBox = New NComboBox()
            xTextAlignmentComboBox.Items.FillFromEnum(Of ENContentAlignment)()
            xTextAlignmentComboBox.SelectedIndex = m_XReferenceLine.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 add axis reference lines.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnXReferenceLineValueUpDownValueChanged(arg As NValueChangeEventArgs) m_XReferenceLine.Value = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnXReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_XReferenceLine.IncludeValueInAxisRange = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnXReferenceLinePaintAfterSeriesCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_XReferenceLine.PaintAfterChartContent = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnXTextAlignmentComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) m_XReferenceLine.TextAlignment = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENContentAlignment) End Sub Private Sub OnYReferenceLineValueUpDownValueChanged(arg As NValueChangeEventArgs) m_YReferenceLine.Value = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnYReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_YReferenceLine.IncludeValueInAxisRange = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnYReferenceLinePaintAfterSeriesCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_YReferenceLine.PaintAfterChartContent = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnYTextAlignmentComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) m_YReferenceLine.TextAlignment = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENContentAlignment) End Sub #End Region #Region "Fields" Private m_XReferenceLine As NAxisReferenceLine Private m_YReferenceLine As NAxisReferenceLine #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 Reference Lines Example for WPF Solution