Stacked Area 3D 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.

Stacked Area 3D Example for WPF Description

This example demonstrates how to create a 3D stacked area chart.


Stacked Area 3DExample

C# Stacked Area 3D 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;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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();
			m_ChartView = chartViewWithCommandBars.View;
			m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);

			// configure title
			m_ChartView.Surface.Titles[0].Text = "Stacked Area 3D";

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

			chart.Enable3D = true;
            chart.ModelWidth = 100;
            chart.ModelDepth = 20;
            chart.ModelHeight = 40;
            chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted);
			chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.BrightCameraLight);
            chart.Interactor = new NInteractor(new NTrackballTool());

            // setup X axis
            NOrdinalScale scaleX = (NOrdinalScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale;
			scaleX.InflateContentRange = false;

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

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

			// add the first area
			m_Area1 = new NAreaSeries();
			m_Area1.MultiAreaMode = ENMultiAreaMode.Series;
			m_Area1.Name = "Product A";
			m_Area1.DataLabelStyle = new NDataLabelStyle();
			chart.Series.Add(m_Area1);
			SetupDataLabels(m_Area1);

			// add the second Area
			m_Area2 = new NAreaSeries();
			m_Area2.MultiAreaMode = ENMultiAreaMode.Stacked;
			m_Area2.Name = "Product B";
			m_Area2.DataLabelStyle = new NDataLabelStyle();
			chart.Series.Add(m_Area2);
			SetupDataLabels(m_Area2);

			// add the third Area
			m_Area3 = new NAreaSeries();
			m_Area3.MultiAreaMode = ENMultiAreaMode.Stacked;
			m_Area3.Name = "Product C";
			m_Area3.DataLabelStyle = new NDataLabelStyle();
			chart.Series.Add(m_Area3);
			SetupDataLabels(m_Area3);

			// fill with random data
			Random random = new Random();
			for (int i = 0; i < 10; i++)
			{
				m_Area1.DataPoints.Add(new NAreaDataPoint(random.Next(20, 50)));
				m_Area2.DataPoints.Add(new NAreaDataPoint(random.Next(20, 50)));
				m_Area3.DataPoints.Add(new NAreaDataPoint(random.Next(20, 50)));
			}

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

			NComboBox stackModeComboBox = new NComboBox();
			stackModeComboBox.Items.Add(new NComboBoxItem("Stacked"));
			stackModeComboBox.Items.Add(new NComboBoxItem("Stacked Percent"));
			stackModeComboBox.SelectedIndex = 0;
			stackModeComboBox.SelectedIndexChanged += OnStackModeComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Stack Mode: ", stackModeComboBox));

			NCheckBox showDataLabelsCheckBox = new NCheckBox("Show Data Labels");
			showDataLabelsCheckBox.CheckedChanged += OnShowDataLabelsCheckedChanged;
			stack.Add(showDataLabelsCheckBox);
			
			m_Area1LabelFormatCombox = CreateLabelsCombo();
			m_Area1LabelFormatCombox.SelectedIndexChanged += OnArea1LabelFormatComboxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Area 1 Label Format: ", m_Area1LabelFormatCombox));

			m_Area2LabelFormatCombox = CreateLabelsCombo();
			m_Area2LabelFormatCombox.SelectedIndexChanged += OnArea2LabelFormatComboxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Area 2 Label Format: ", m_Area2LabelFormatCombox));

			m_Area3LabelFormatCombox = CreateLabelsCombo();
			m_Area3LabelFormatCombox.SelectedIndexChanged += OnArea3LabelFormatComboxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Area 3 Label Format: ", m_Area3LabelFormatCombox));

			showDataLabelsCheckBox.Checked = true;

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

This example demonstrates how to create a 3D stacked 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"), ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"), }; } #endregion #region Implementation private string GetFormatStringFromIndex(int index) { switch (index) { case 0: return ""; case 1: return ""; case 2: return ""; case 3: return ""; default: return ""; } } private NComboBox CreateLabelsCombo() { NComboBox comboBox = new NComboBox(); comboBox.Items.Add(new NComboBoxItem("Value")); comboBox.Items.Add(new NComboBoxItem("Total")); comboBox.Items.Add(new NComboBoxItem("Cumulative")); comboBox.Items.Add(new NComboBoxItem("Percent")); comboBox.SelectedIndex = 0; return comboBox; } private void SetupDataLabels(NAreaSeries area) { NDataLabelStyle dataLabel = area.DataLabelStyle; dataLabel.ArrowLength = 0; dataLabel.VertAlign = ENVerticalAlignment.Center; dataLabel.TextStyle.Background.Padding = new NMargins(5); dataLabel.TextStyle.Font = new NFont("Arial", 8, ENFontStyle.Bold); } #endregion #region Event Handlers void OnStackModeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { // configure chart NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0]; NLinearScale scale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale; switch (((NComboBox)arg.TargetNode).SelectedIndex) { case 0: m_Area2.MultiAreaMode = ENMultiAreaMode.Stacked; m_Area3.MultiAreaMode = ENMultiAreaMode.Stacked; scale.Labels.TextProvider = new NFormattedScaleLabelTextProvider(new NNumericValueFormatter(ENNumericValueFormat.General)); break; case 1: m_Area2.MultiAreaMode = ENMultiAreaMode.StackedPercent; m_Area3.MultiAreaMode = ENMultiAreaMode.StackedPercent; scale.Labels.TextProvider = new NFormattedScaleLabelTextProvider(new NNumericValueFormatter(ENNumericValueFormat.Percentage)); break; } } void OnShowDataLabelsCheckedChanged(NValueChangeEventArgs arg) { NCheckBox showDataLabelsCheckBox = (NCheckBox)arg.TargetNode; m_Area1.DataLabelStyle.Visible = showDataLabelsCheckBox.Checked; m_Area2.DataLabelStyle.Visible = showDataLabelsCheckBox.Checked; m_Area3.DataLabelStyle.Visible = showDataLabelsCheckBox.Checked; m_Area1LabelFormatCombox.Enabled = showDataLabelsCheckBox.Checked; m_Area2LabelFormatCombox.Enabled = showDataLabelsCheckBox.Checked; m_Area3LabelFormatCombox.Enabled = showDataLabelsCheckBox.Checked; } void OnArea1LabelFormatComboxSelectedIndexChanged(NValueChangeEventArgs arg) { m_Area1.DataLabelStyle.Format = GetFormatStringFromIndex(m_Area1LabelFormatCombox.SelectedIndex); } void OnArea2LabelFormatComboxSelectedIndexChanged(NValueChangeEventArgs arg) { m_Area2.DataLabelStyle.Format = GetFormatStringFromIndex(m_Area2LabelFormatCombox.SelectedIndex); } void OnArea3LabelFormatComboxSelectedIndexChanged(NValueChangeEventArgs arg) { m_Area3.DataLabelStyle.Format = GetFormatStringFromIndex(m_Area3LabelFormatCombox.SelectedIndex); } #endregion #region Fields private NChartView m_ChartView; private NAreaSeries m_Area1; private NAreaSeries m_Area2; private NAreaSeries m_Area3; private NComboBox m_Area1LabelFormatCombox; private NComboBox m_Area2LabelFormatCombox; private NComboBox m_Area3LabelFormatCombox; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Stacked Area 3D Example for WPF Solution

VB.NET Stacked Area 3D Example Code for Nevron Chart for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Chart.Tools
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System

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

		' 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()
            m_ChartView = chartViewWithCommandBars.View
            m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)

            ' configure title
            m_ChartView.Surface.Titles(0).Text = "Stacked Area 3D"

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

            chart.Enable3D = True
            chart.ModelWidth = 100
            chart.ModelDepth = 20
            chart.ModelHeight = 40
            chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)
            chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.BrightCameraLight)
            chart.Interactor = New NInteractor(New NTrackballTool())

            ' setup X axis
            Dim scaleX As NOrdinalScale = chart.Axes(ENCartesianAxis.PrimaryX).Scale
            scaleX.InflateContentRange = False

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

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

            ' add the first area
            m_Area1 = New NAreaSeries()
            m_Area1.MultiAreaMode = ENMultiAreaMode.Series
            m_Area1.Name = "Product A"
            m_Area1.DataLabelStyle = New NDataLabelStyle()
            chart.Series.Add(m_Area1)
            SetupDataLabels(m_Area1)

            ' add the second Area
            m_Area2 = New NAreaSeries()
            m_Area2.MultiAreaMode = ENMultiAreaMode.Stacked
            m_Area2.Name = "Product B"
            m_Area2.DataLabelStyle = New NDataLabelStyle()
            chart.Series.Add(m_Area2)
            SetupDataLabels(m_Area2)

            ' add the third Area
            m_Area3 = New NAreaSeries()
            m_Area3.MultiAreaMode = ENMultiAreaMode.Stacked
            m_Area3.Name = "Product C"
            m_Area3.DataLabelStyle = New NDataLabelStyle()
            chart.Series.Add(m_Area3)
            SetupDataLabels(m_Area3)

            ' fill with random data
            Dim random As Random = New Random()
            For i = 0 To 9
                m_Area1.DataPoints.Add(New NAreaDataPoint(random.Next(20, 50)))
                m_Area2.DataPoints.Add(New NAreaDataPoint(random.Next(20, 50)))
                m_Area3.DataPoints.Add(New NAreaDataPoint(random.Next(20, 50)))
            Next

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

            Dim stackModeComboBox As NComboBox = New NComboBox()
            stackModeComboBox.Items.Add(New NComboBoxItem("Stacked"))
            stackModeComboBox.Items.Add(New NComboBoxItem("Stacked Percent"))
            stackModeComboBox.SelectedIndex = 0
            stackModeComboBox.SelectedIndexChanged += AddressOf OnStackModeComboBoxSelectedIndexChanged
            stack.Add(NPairBox.Create("Stack Mode: ", stackModeComboBox))

            Dim showDataLabelsCheckBox As NCheckBox = New NCheckBox("Show Data Labels")
            showDataLabelsCheckBox.CheckedChanged += AddressOf OnShowDataLabelsCheckedChanged
            stack.Add(showDataLabelsCheckBox)

            m_Area1LabelFormatCombox = CreateLabelsCombo()
            Me.m_Area1LabelFormatCombox.SelectedIndexChanged += AddressOf OnArea1LabelFormatComboxSelectedIndexChanged
            stack.Add(NPairBox.Create("Area 1 Label Format: ", m_Area1LabelFormatCombox))

            m_Area2LabelFormatCombox = CreateLabelsCombo()
            Me.m_Area2LabelFormatCombox.SelectedIndexChanged += AddressOf OnArea2LabelFormatComboxSelectedIndexChanged
            stack.Add(NPairBox.Create("Area 2 Label Format: ", m_Area2LabelFormatCombox))

            m_Area3LabelFormatCombox = CreateLabelsCombo()
            Me.m_Area3LabelFormatCombox.SelectedIndexChanged += AddressOf OnArea3LabelFormatComboxSelectedIndexChanged
            stack.Add(NPairBox.Create("Area 3 Label Format: ", m_Area3LabelFormatCombox))

            showDataLabelsCheckBox.Checked = True

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

This example demonstrates how to create a 3D stacked 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"), ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html")} End Function #End Region #Region "Implementation" Private Function GetFormatStringFromIndex(index As Integer) As String Select Case index Case 0 Return "" Case 1 Return "" Case 2 Return "" Case 3 Return "" Case Else Return "" End Select End Function Private Function CreateLabelsCombo() As NComboBox Dim comboBox As NComboBox = New NComboBox() comboBox.Items.Add(New NComboBoxItem("Value")) comboBox.Items.Add(New NComboBoxItem("Total")) comboBox.Items.Add(New NComboBoxItem("Cumulative")) comboBox.Items.Add(New NComboBoxItem("Percent")) comboBox.SelectedIndex = 0 Return comboBox End Function Private Sub SetupDataLabels(area As NAreaSeries) Dim dataLabel = area.DataLabelStyle dataLabel.ArrowLength = 0 dataLabel.VertAlign = ENVerticalAlignment.Center dataLabel.TextStyle.Background.Padding = New NMargins(5) dataLabel.TextStyle.Font = New NFont("Arial", 8, ENFontStyle.Bold) End Sub #End Region #Region "Event Handlers" Private Sub OnStackModeComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) ' configure chart Dim chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart) Dim scale As NLinearScale = chart.Axes(ENCartesianAxis.PrimaryY).Scale Select Case CType(arg.TargetNode, NComboBox).SelectedIndex Case 0 m_Area2.MultiAreaMode = ENMultiAreaMode.Stacked m_Area3.MultiAreaMode = ENMultiAreaMode.Stacked scale.Labels.TextProvider = New NFormattedScaleLabelTextProvider(New NNumericValueFormatter(ENNumericValueFormat.General)) Case 1 m_Area2.MultiAreaMode = ENMultiAreaMode.StackedPercent m_Area3.MultiAreaMode = ENMultiAreaMode.StackedPercent scale.Labels.TextProvider = New NFormattedScaleLabelTextProvider(New NNumericValueFormatter(ENNumericValueFormat.Percentage)) End Select End Sub Private Sub OnShowDataLabelsCheckedChanged(arg As NValueChangeEventArgs) Dim showDataLabelsCheckBox = CType(arg.TargetNode, NCheckBox) m_Area1.DataLabelStyle.Visible = showDataLabelsCheckBox.Checked m_Area2.DataLabelStyle.Visible = showDataLabelsCheckBox.Checked m_Area3.DataLabelStyle.Visible = showDataLabelsCheckBox.Checked m_Area1LabelFormatCombox.Enabled = showDataLabelsCheckBox.Checked m_Area2LabelFormatCombox.Enabled = showDataLabelsCheckBox.Checked m_Area3LabelFormatCombox.Enabled = showDataLabelsCheckBox.Checked End Sub Private Sub OnArea1LabelFormatComboxSelectedIndexChanged(arg As NValueChangeEventArgs) m_Area1.DataLabelStyle.Format = GetFormatStringFromIndex(m_Area1LabelFormatCombox.SelectedIndex) End Sub Private Sub OnArea2LabelFormatComboxSelectedIndexChanged(arg As NValueChangeEventArgs) m_Area2.DataLabelStyle.Format = GetFormatStringFromIndex(m_Area2LabelFormatCombox.SelectedIndex) End Sub Private Sub OnArea3LabelFormatComboxSelectedIndexChanged(arg As NValueChangeEventArgs) m_Area3.DataLabelStyle.Format = GetFormatStringFromIndex(m_Area3LabelFormatCombox.SelectedIndex) End Sub #End Region #Region "Fields" Private m_ChartView As NChartView Private m_Area1 As NAreaSeries Private m_Area2 As NAreaSeries Private m_Area3 As NAreaSeries Private m_Area1LabelFormatCombox As NComboBox Private m_Area2LabelFormatCombox As NComboBox Private m_Area3LabelFormatCombox As NComboBox #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) Stacked Area 3D Example for WPF Solution