Step Area 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.

Step Area Example for WPF Description

This example demonstrates how to create a standard area chart.


Step Area Example

C# Step Area Example Code for Nevron Chart for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Chart.Tools;
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 - NStepAreaExample";

			// 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 = "Step Area";

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

            // setup X axis
            NOrdinalScale scaleX = (NOrdinalScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale;
			scaleX.InflateContentRange = false;
			scaleX.MajorTickMode = ENMajorTickMode.AutoMaxCount;
			scaleX.DisplayDataPointsBetweenTicks = false;
			scaleX.Labels.Visible = false;

			for (int i = 0; i < monthLetters.Length; i++)
			{
				scaleX.CustomLabels.Add(new NCustomValueLabel(i, monthLetters[i]));
			}

			// add interlaced stripe for Y axis
			NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
			stripStyle.Interlaced = true;

			NLinearScale scaleY = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;
			scaleY.Strips.Add(stripStyle);

			// setup area series
			m_Area = new NAreaSeries();
			m_Area.OriginMode = ENSeriesOriginMode.CustomOrigin;
			m_Area.CustomOrigin = 18;
            chart.Series.Add(m_Area);
            m_Area.Name = "Area Series";
			m_Area.Stroke = new NStroke(1, NColor.Black);

            NDataLabelStyle dataLabelStyle = new NDataLabelStyle();

			dataLabelStyle.Visible = true;
			dataLabelStyle.Format = "";

			m_Area.DataLabelStyle = dataLabelStyle;

			for (int i = 0; i < monthValues.Length; i++)
			{
				m_Area.DataPoints.Add(new NAreaDataPoint(monthValues[i]));
			}

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

			NComboBox originModeComboBox = new NComboBox();
			originModeComboBox.Items.FillFromEnum();
			originModeComboBox.SelectedIndexChanged += OnOriginModeComboBoxSelectedIndexChanged;
			originModeComboBox.SelectedIndex = (int)m_Area.OriginMode; 
			stack.Add(NPairBox.Create("Origin Mode: ", originModeComboBox));

            NNumericUpDown customOriginUpDown = new NNumericUpDown();
			customOriginUpDown.ValueChanged += OnCustomOriginUpDownValueChanged;
			stack.Add(NPairBox.Create("Custom Origin: ", customOriginUpDown));
			customOriginUpDown.Value = m_Area.CustomOrigin;

            NComboBox areaSegmentModeComboBox = new NComboBox();
            areaSegmentModeComboBox.Items.FillFromEnum();
            areaSegmentModeComboBox.SelectedIndexChanged += OnStepAreaSegmentModeComboBoxIndexChanged;
            stack.Add(NPairBox.Create("Segment Mode: ", areaSegmentModeComboBox));
            areaSegmentModeComboBox.SelectedIndex = (int)ENAreaSegmentMode.HVHStep;

            NCheckBox showDropLinesCheckBox = new NCheckBox();
            showDropLinesCheckBox.CheckedChanged += OnShowDropLinesCheckBoxCheckedChanged;
            stack.Add(NPairBox.Create("Show Droplines: ", showDropLinesCheckBox));

            return boxGroup;
		}

        public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create a standard area chart.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Area Series", "https://www.nevron.com/docs/openvision/area-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnCustomOriginUpDownValueChanged(NValueChangeEventArgs arg) { m_Area.CustomOrigin = (double)((NNumericUpDown)arg.TargetNode).Value; } void OnOriginModeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_Area.OriginMode = (ENSeriesOriginMode)((NComboBox)arg.TargetNode).SelectedIndex; } void OnStepAreaSegmentModeComboBoxIndexChanged(NValueChangeEventArgs arg) { m_Area.SegmentMode = (ENAreaSegmentMode)((NComboBox)arg.TargetNode).SelectedIndex; } private void OnShowDropLinesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_Area.ShowDropLines = (bool)arg.NewValue; } #endregion #region Fields NAreaSeries m_Area; #endregion #region Static Methods #endregion #region Constants internal static readonly double[] monthValues = new double[] { 16, 19, 16, 15, 18, 19, 24, 21, 22, 17, 19, 15 }; internal static readonly string[] monthLetters = new string[] { "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D" }; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Step Area Example for WPF Solution

VB.NET Step Area 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 - NStepAreaExample"

		' 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 = "Step Area"

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

            ' setup X axis
            Dim scaleX As NOrdinalScale = chart.Axes(ENCartesianAxis.PrimaryX).Scale
            scaleX.InflateContentRange = False
            scaleX.MajorTickMode = ENMajorTickMode.AutoMaxCount
            scaleX.DisplayDataPointsBetweenTicks = False
            scaleX.Labels.Visible = False

            For i = 0 To monthLetters.Length - 1
                scaleX.CustomLabels.Add(New NCustomValueLabel(i, monthLetters(i)))
            Next

            ' add interlaced stripe for Y axis
            Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            stripStyle.Interlaced = True

            Dim scaleY As NLinearScale = chart.Axes(ENCartesianAxis.PrimaryY).Scale
            scaleY.Strips.Add(stripStyle)

            ' setup area series
            m_Area = New NAreaSeries()
            m_Area.OriginMode = ENSeriesOriginMode.CustomOrigin
            m_Area.CustomOrigin = 18
            chart.Series.Add(m_Area)
            m_Area.Name = "Area Series"
            m_Area.Stroke = New NStroke(1, NColor.Black)

            Dim dataLabelStyle As NDataLabelStyle = New NDataLabelStyle()

            dataLabelStyle.Visible = True
            dataLabelStyle.Format = ""

            m_Area.DataLabelStyle = dataLabelStyle

            For i = 0 To monthValues.Length - 1
                m_Area.DataPoints.Add(New NAreaDataPoint(monthValues(i)))
            Next

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

            Dim originModeComboBox As NComboBox = New NComboBox()
            originModeComboBox.Items.FillFromEnum(Of ENSeriesOriginMode)()
            originModeComboBox.SelectedIndexChanged += AddressOf OnOriginModeComboBoxSelectedIndexChanged
            originModeComboBox.SelectedIndex = m_Area.OriginMode
            stack.Add(NPairBox.Create("Origin Mode: ", originModeComboBox))

            Dim customOriginUpDown As NNumericUpDown = New NNumericUpDown()
            customOriginUpDown.ValueChanged += AddressOf OnCustomOriginUpDownValueChanged
            stack.Add(NPairBox.Create("Custom Origin: ", customOriginUpDown))
            customOriginUpDown.Value = m_Area.CustomOrigin

            Dim areaSegmentModeComboBox As NComboBox = New NComboBox()
            areaSegmentModeComboBox.Items.FillFromEnum(Of ENAreaSegmentMode)()
            areaSegmentModeComboBox.SelectedIndexChanged += AddressOf OnStepAreaSegmentModeComboBoxIndexChanged
            stack.Add(NPairBox.Create("Segment Mode: ", areaSegmentModeComboBox))
            areaSegmentModeComboBox.SelectedIndex = CInt(ENAreaSegmentMode.HVHStep)

            Dim showDropLinesCheckBox As NCheckBox = New NCheckBox()
            showDropLinesCheckBox.CheckedChanged += AddressOf OnShowDropLinesCheckBoxCheckedChanged
            stack.Add(NPairBox.Create("Show Droplines: ", showDropLinesCheckBox))

            Return boxGroup
        End Function

        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create a standard area chart.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Area Series", "https://www.nevron.com/docs/openvision/area-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnCustomOriginUpDownValueChanged(arg As NValueChangeEventArgs) m_Area.CustomOrigin = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnOriginModeComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) m_Area.OriginMode = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENSeriesOriginMode) End Sub Private Sub OnStepAreaSegmentModeComboBoxIndexChanged(arg As NValueChangeEventArgs) m_Area.SegmentMode = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENAreaSegmentMode) End Sub Private Sub OnShowDropLinesCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_Area.ShowDropLines = CBool(arg.NewValue) End Sub #End Region #Region "Fields" Private m_Area As NAreaSeries #End Region #Region "Static Methods" #End Region #Region "Constants" Friend Shared ReadOnly monthValues As Double() = New Double() {16, 19, 16, 15, 18, 19, 24, 21, 22, 17, 19, 15} Friend Shared ReadOnly monthLetters As String() = New String() {"J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"} #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Step Area Example for WPF Solution

Related Documentation Links