Multi Series line 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.

Multi Series line Example for WinForms Description

This example demonstrates how to create a multi-series line chart where lines occupy a specified percentage of their category.


Multi Series Line Example

C# Multi Series line 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 - NMultiSeriesLineExample";

			// 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 = "Multi Series Line Chart";

            // configure chart
            m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
            m_Chart.Interactor = new NInteractor(new NTrackballTool());

            // setup chart
            m_Chart.Enable3D = true;
            m_Chart.ModelWidth = 60;
            m_Chart.ModelHeight = 25;
            m_Chart.ModelDepth = 45;
            m_Chart.Projection.ProjectionType = ENProjectionType.Perspective;
            m_Chart.Projection.Elevation = 28;
            m_Chart.Projection.Rotation = -17;
            m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft);
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.Standard);

            // add interlaced stripe to the Y axis
            NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
            strip.SetShowAtWall(ENChartWall.Back, true);
            strip.SetShowAtWall(ENChartWall.Left, true);
            strip.Interlaced = true;
            ((NStandardScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).Strips.Add(strip);

            // show the X axis gridlines
            NOrdinalScale ordinalScale = m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale as NOrdinalScale;
            ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);
            ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);

            // add the first line
            m_Line1 = new NLineSeries();
            m_Chart.Series.Add(m_Line1);
            m_Line1.MultiLineMode = ENMultiLineMode.Series;
            m_Line1.LineSegmentShape = ENLineSegmentShape.Tape;
            m_Line1.DepthPercent = 50;
            m_Line1.Name = "Line 1";

            // add the second line
            m_Line2 = new NLineSeries();
            m_Chart.Series.Add(m_Line2);
            m_Line2.MultiLineMode = ENMultiLineMode.Series;
            m_Line2.LineSegmentShape = ENLineSegmentShape.Tape;
            m_Line2.DepthPercent = 50;
            m_Line2.Name = "Line 2";

            // add the third line
            m_Line3 = new NLineSeries();
            m_Chart.Series.Add(m_Line3);
            m_Line3.MultiLineMode = ENMultiLineMode.Series;
            m_Line3.LineSegmentShape = ENLineSegmentShape.Tape;
            m_Line3.DepthPercent = 50;
            m_Line3.Name = "Line 3";

            GenerateData();

            // apply style sheet
            chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Fresh, ENChartPaletteTarget.Series));

            return chartViewWithCommandBars;
        }

        private void GenerateData()
        {
            Random random = new Random();

            for (int i = 0; i < 7; i++)
            {
                m_Line1.DataPoints.Add(new NLineDataPoint(random.Next(100)));
                m_Line2.DataPoints.Add(new NLineDataPoint(random.Next(100)));
                m_Line3.DataPoints.Add(new NLineDataPoint(random.Next(100)));
            }
        }

        private void NewDataButton_Click(object sender, System.EventArgs e)
        {
            GenerateData();
        }

        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();
            NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);

            NHScrollBar chartDepthScrollBar = new NHScrollBar();
            chartDepthScrollBar.Value = m_Chart.ModelDepth;
            chartDepthScrollBar.ValueChanged += ChartDepthScrollBar_ValueChanged;
            stack.Add(NPairBox.Create("Chart Depth:", chartDepthScrollBar));

            NHScrollBar lineDepthScrollBar = new NHScrollBar();
            lineDepthScrollBar.Value = m_Line1.DepthPercent;
            lineDepthScrollBar.ValueChanged += LineDepthScrollBar_ValueChanged;
            stack.Add(NPairBox.Create("Line Depth:", lineDepthScrollBar));

            return group;
        }

        private void LineDepthScrollBar_ValueChanged(NValueChangeEventArgs arg)
        {
            float depthPercent = System.Convert.ToSingle(arg.NewValue);

            m_Line1.DepthPercent = depthPercent;
            m_Line2.DepthPercent = depthPercent;
            m_Line3.DepthPercent = depthPercent;
        }

        private void ChartDepthScrollBar_ValueChanged(NValueChangeEventArgs arg)
        {
            m_Chart.ModelDepth = System.Convert.ToSingle(arg.NewValue);
        }

        public string GetExampleDescription()
        {
            return @"

This example demonstrates how to create a multi-series line chart where lines occupy a specified percentage of their category.

"; } /// /// 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"), }; } #endregion #region Implementation #endregion #region Event Handlers #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) Multi Series line Example for WinForms Solution

VB.NET Multi Series line 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 - NMultiSeriesLineExample"

        ' 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 = "Multi Series Line Chart"

            ' configure chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
            m_Chart.Interactor = New NInteractor(New NTrackballTool())

            ' setup chart
            m_Chart.Enable3D = True
            m_Chart.ModelWidth = 60
            m_Chart.ModelHeight = 25
            m_Chart.ModelDepth = 45
            m_Chart.Projection.ProjectionType = ENProjectionType.Perspective
            m_Chart.Projection.Elevation = 28
            m_Chart.Projection.Rotation = -17
            m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft)
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.Standard)

            ' add interlaced stripe to the Y axis
            Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            strip.SetShowAtWall(ENChartWall.Back, True)
            strip.SetShowAtWall(ENChartWall.Left, True)
            strip.Interlaced = True
            CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NStandardScale).Strips.Add(strip)

            ' show the X axis gridlines
            Dim ordinalScale As NOrdinalScale = TryCast(m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale, NOrdinalScale)
            ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)
            ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)

            ' add the first line
            m_Line1 = New NLineSeries()
            m_Chart.Series.Add(m_Line1)
            m_Line1.MultiLineMode = ENMultiLineMode.Series
            m_Line1.LineSegmentShape = ENLineSegmentShape.Tape
            m_Line1.DepthPercent = 50
            m_Line1.Name = "Line 1"

            ' add the second line
            m_Line2 = New NLineSeries()
            m_Chart.Series.Add(m_Line2)
            m_Line2.MultiLineMode = ENMultiLineMode.Series
            m_Line2.LineSegmentShape = ENLineSegmentShape.Tape
            m_Line2.DepthPercent = 50
            m_Line2.Name = "Line 2"

            ' add the third line
            m_Line3 = New NLineSeries()
            m_Chart.Series.Add(m_Line3)
            m_Line3.MultiLineMode = ENMultiLineMode.Series
            m_Line3.LineSegmentShape = ENLineSegmentShape.Tape
            m_Line3.DepthPercent = 50
            m_Line3.Name = "Line 3"

            GenerateData()

            ' apply style sheet
            chartView.Document.StyleSheets.ApplyTheme(New NChartTheme(ENChartPalette.Fresh, ENChartPaletteTarget.Series))

            Return chartViewWithCommandBars
        End Function

        Private Sub GenerateData()
            Dim random As Random = New Random()

            For i = 0 To 6
                m_Line1.DataPoints.Add(New NLineDataPoint(random.Next(100)))
                m_Line2.DataPoints.Add(New NLineDataPoint(random.Next(100)))
                m_Line3.DataPoints.Add(New NLineDataPoint(random.Next(100)))
            Next
        End Sub

        Private Sub NewDataButton_Click(sender As Object, e As EventArgs)
            GenerateData()
        End Sub

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

            Dim chartDepthScrollBar As NHScrollBar = New NHScrollBar()
            chartDepthScrollBar.Value = m_Chart.ModelDepth
            chartDepthScrollBar.ValueChanged += AddressOf ChartDepthScrollBar_ValueChanged
            stack.Add(NPairBox.Create("Chart Depth:", chartDepthScrollBar))

            Dim lineDepthScrollBar As NHScrollBar = New NHScrollBar()
            lineDepthScrollBar.Value = m_Line1.DepthPercent
            lineDepthScrollBar.ValueChanged += AddressOf LineDepthScrollBar_ValueChanged
            stack.Add(NPairBox.Create("Line Depth:", lineDepthScrollBar))

            Return group
        End Function

        Private Sub LineDepthScrollBar_ValueChanged(arg As NValueChangeEventArgs)
            Dim depthPercent = Convert.ToSingle(arg.NewValue)

            m_Line1.DepthPercent = depthPercent
            m_Line2.DepthPercent = depthPercent
            m_Line3.DepthPercent = depthPercent
        End Sub

        Private Sub ChartDepthScrollBar_ValueChanged(arg As NValueChangeEventArgs)
            m_Chart.ModelDepth = Convert.ToSingle(arg.NewValue)
        End Sub

        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create a multi-series line chart where lines occupy a specified percentage of their category.

" 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")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" #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) Multi Series line Example for WinForms Solution

Related Documentation Links