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

Stacked Line 3D Example for WinForms Description

This example demonstrates how to create a stacked line chart.


Stacked Line 3DExample

C# Stacked Line 3D Example Code for Nevron Chart for WinForms
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 - NStackedLine3DExample";

			// 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 = "Stacked Line 3D";

			// configure chart
			m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
            m_Chart.Enable3D = true;
            m_Chart.ModelWidth = 65;
            m_Chart.ModelHeight = 40;

            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.Standard);
            m_Chart.Projection.SetPredefinedProjection(ENPredefinedProjection.Perspective2);
            m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft);
			m_Chart.Interactor = new NInteractor(new NTrackballTool());

            // add interlaced stripe to the Y axis
            NScaleStrip stripStyle = new NScaleStrip(new NColorFill(ENNamedColor.Beige), null, true, 0, 0, 1, 1);
			stripStyle.Interlaced = true;
			m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale.Strips.Add(stripStyle);

			// add the first line
			m_Line1 = CreateLineSeries("Line 1", ENMultiLineMode.Series);
			m_Line1.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility;
			m_Chart.Series.Add(m_Line1);

			// add the second line
			m_Line2 = CreateLineSeries("Line 2", ENMultiLineMode.Stacked);
			m_Line2.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility;
			m_Chart.Series.Add(m_Line2);

			// add the third line
			m_Line3 = CreateLineSeries("Line 3", ENMultiLineMode.Stacked);
			m_Line3.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility;
			m_Chart.Series.Add(m_Line3);

			// positive data
			OnPositiveDataButtonClick(null);

			return chartViewWithCommandBars;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
			
			NButton positiveDataButton = new NButton("Positive Values");
			positiveDataButton.Click += OnPositiveDataButtonClick;
			stack.Add(positiveDataButton);

			NButton positiveAndNegativeDataButton = new NButton("Positive and Negative Values");
			positiveAndNegativeDataButton.Click += OnPositiveAndNegativeDataButtonClick;
			stack.Add(positiveAndNegativeDataButton);

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

This example demonstrates how to create a stacked line chart.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Line Series", "https://www.nevron.com/docs/openvision/line-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 /// /// Creates a new line series /// /// /// /// private NLineSeries CreateLineSeries(string name, ENMultiLineMode multiLineMode) { NLineSeries line = new NLineSeries(); line.Name = name; line.LineSegmentShape = ENLineSegmentShape.Tape; line.MultiLineMode = multiLineMode; NDataLabelStyle dataLabelStyle = new NDataLabelStyle(); dataLabelStyle.ArrowLength = 0; line.DataLabelStyle = dataLabelStyle; return line; } #endregion #region Event Handlers void OnPositiveAndNegativeDataButtonClick(NEventArgs arg) { m_Line1.DataPoints.Clear(); m_Line2.DataPoints.Clear(); m_Line3.DataPoints.Clear(); Random random = new Random(); for (int i = 0; i < 12; i++) { m_Line1.DataPoints.Add(new NLineDataPoint(random.Next(100) - 50)); m_Line2.DataPoints.Add(new NLineDataPoint(random.Next(100) - 50)); m_Line3.DataPoints.Add(new NLineDataPoint(random.Next(100) - 50)); } } void OnPositiveDataButtonClick(NEventArgs arg) { m_Line1.DataPoints.Clear(); m_Line2.DataPoints.Clear(); m_Line3.DataPoints.Clear(); Random random = new Random(); for (int i = 0; i < 12; i++) { m_Line1.DataPoints.Add(new NLineDataPoint(random.Next(90) + 10)); m_Line2.DataPoints.Add(new NLineDataPoint(random.Next(90) + 10)); m_Line3.DataPoints.Add(new NLineDataPoint(random.Next(90) + 10)); } } #endregion #region Fields NCartesianChart m_Chart; NLineSeries m_Line1; NLineSeries m_Line2; NLineSeries m_Line3; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

VB.NET Stacked Line 3D Example Code for Nevron Chart for WinForms
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.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 - NStackedLine3DExample"

        ' 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 = "Stacked Line 3D"

            ' configure chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
            m_Chart.Enable3D = True
            m_Chart.ModelWidth = 65
            m_Chart.ModelHeight = 40

            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.Standard)
            m_Chart.Projection.SetPredefinedProjection(ENPredefinedProjection.Perspective2)
            m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft)
            m_Chart.Interactor = New NInteractor(New NTrackballTool())

            ' add interlaced stripe to the Y axis
            Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(ENNamedColor.Beige), Nothing, True, 0, 0, 1, 1)
            stripStyle.Interlaced = True
            m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale.Strips.Add(stripStyle)

            ' add the first line
            m_Line1 = CreateLineSeries("Line 1", ENMultiLineMode.Series)
            m_Line1.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility
            m_Chart.Series.Add(m_Line1)

            ' add the second line
            m_Line2 = CreateLineSeries("Line 2", ENMultiLineMode.Stacked)
            m_Line2.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility
            m_Chart.Series.Add(m_Line2)

            ' add the third line
            m_Line3 = CreateLineSeries("Line 3", ENMultiLineMode.Stacked)
            m_Line3.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility
            m_Chart.Series.Add(m_Line3)

            ' positive data
            OnPositiveDataButtonClick(Nothing)

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

            Dim positiveDataButton As NButton = New NButton("Positive Values")
            positiveDataButton.Click += AddressOf OnPositiveDataButtonClick
            stack.Add(positiveDataButton)

            Dim positiveAndNegativeDataButton As NButton = New NButton("Positive and Negative Values")
            positiveAndNegativeDataButton.Click += AddressOf OnPositiveAndNegativeDataButtonClick
            stack.Add(positiveAndNegativeDataButton)

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

This example demonstrates how to create a stacked line chart.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Line Series", "https://www.nevron.com/docs/openvision/line-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" ''' ''' Creates a new line series ''' ''' ''' ''' Private Function CreateLineSeries(name As String, multiLineMode As ENMultiLineMode) As NLineSeries Dim line As NLineSeries = New NLineSeries() line.Name = name line.LineSegmentShape = ENLineSegmentShape.Tape line.MultiLineMode = multiLineMode Dim dataLabelStyle As NDataLabelStyle = New NDataLabelStyle() dataLabelStyle.ArrowLength = 0 line.DataLabelStyle = dataLabelStyle Return line End Function #End Region #Region "Event Handlers" Private Sub OnPositiveAndNegativeDataButtonClick(arg As NEventArgs) m_Line1.DataPoints.Clear() m_Line2.DataPoints.Clear() m_Line3.DataPoints.Clear() Dim random As Random = New Random() For i = 0 To 11 m_Line1.DataPoints.Add(New NLineDataPoint(random.Next(100) - 50)) m_Line2.DataPoints.Add(New NLineDataPoint(random.Next(100) - 50)) m_Line3.DataPoints.Add(New NLineDataPoint(random.Next(100) - 50)) Next End Sub Private Sub OnPositiveDataButtonClick(arg As NEventArgs) m_Line1.DataPoints.Clear() m_Line2.DataPoints.Clear() m_Line3.DataPoints.Clear() Dim random As Random = New Random() For i = 0 To 11 m_Line1.DataPoints.Add(New NLineDataPoint(random.Next(90) + 10)) m_Line2.DataPoints.Add(New NLineDataPoint(random.Next(90) + 10)) m_Line3.DataPoints.Add(New NLineDataPoint(random.Next(90) + 10)) Next End Sub #End Region #Region "Fields" Private m_Chart As NCartesianChart Private m_Line1 As NLineSeries Private m_Line2 As NLineSeries Private m_Line3 As NLineSeries #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 Line 3D Example for WinForms Solution