Combo Chart 1 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.

Combo Chart 1 Example for WinForms Description

This example demonstrates how to create a combo chart consisting of two series (NOV Chart supports an unlimited number of series).


Combo Chart Example 1

C# Combo Chart 1 Example Code for Nevron Chart for WinForms
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.DataStructures;
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 - NComboChartExample1";

			// 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 = "Combo Chart";

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

			m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);

			// Setup the primary Y axis
			m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale.Title.Text = "Number of Occurences";

			// add interlace stripe
			NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
			strip.Interlaced = true;
			m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale.Strips.Add(strip);

			// Setup the secondary Y axis
			NLinearScale scaleY2 = new NLinearScale();
			scaleY2.Labels.TextProvider = new NFormattedScaleLabelTextProvider(new NNumericValueFormatter("0%"));
			scaleY2.Title.Text = "Cumulative Percent";

			NCartesianAxis axisY2 = m_Chart.Axes[ENCartesianAxis.SecondaryY];

			axisY2.Visible = true;
			axisY2.Scale = scaleY2;
			axisY2.ViewRangeMode = ENAxisViewRangeMode.FixedRange;
			axisY2.MinViewRangeValue = 0;
			axisY2.MaxViewRangeValue = 1;

			// add the bar series
			NBarSeries bar = new NBarSeries();
			m_Chart.Series.Add(bar);
			bar.Name = "Bar Series";
			bar.DataLabelStyle = new NDataLabelStyle(false);

			// add the line series
			NLineSeries line = new NLineSeries();
			m_Chart.Series.Add(line);
			line.Name = "Cumulative %";
			line.DataLabelStyle = new NDataLabelStyle(false);

			NMarkerStyle markerStyle = new NMarkerStyle();
			markerStyle.Visible = true;
			markerStyle.Shape = ENPointShape3D.Ellipse;
			markerStyle.Size = new NSize(10, 10);
			markerStyle.Fill = new NColorFill(NColor.Orange);

			line.MarkerStyle = markerStyle;

			line.VerticalAxis = axisY2;

			// fill with random data and sort in descending order
			int count = 10;
			NList randomValues = new NList();
			Random random = new Random();
			for (int i = 0; i < count; i++)
			{
				randomValues.Add(random.Next(100, 700));
			}

			randomValues.Sort();

			for (int i = 0; i < randomValues.Count; i++)
			{
				bar.DataPoints.Add(new NBarDataPoint(randomValues[i]));
			}

			// calculate cumulative sum of the bar values
			double cs = 0;
			double[] arrCumulative = new double[count];

			for (int i = 0; i < count; i++)
			{
				cs += randomValues[i];
				arrCumulative[i] = cs;
			}

			if (cs > 0)
			{
				for (int i = 0; i < count; i++)
				{
					arrCumulative[i] /= cs;
					line.DataPoints.Add(new NLineDataPoint(arrCumulative[i]));
				}
			}

			chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));

			return chartViewWithCommandBars;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
			
			return group;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create a combo chart consisting of two series (NOV Chart supports an unlimited number of series).

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Cartesian Chart", "https://www.nevron.com/docs/openvision/cartesian-chart.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), ("Bar Series", "https://www.nevron.com/docs/openvision/bar-chart-series.html"), ("Line Series", "https://www.nevron.com/docs/openvision/line-chart-series.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), }; } #endregion #region Implementation private NComboBox CreateLegendFormatCombo() { NComboBox comboBox = new NComboBox(); NComboBoxItem item = new NComboBoxItem("Value and Label"); item.Tag = "

Download a fully functional C# (.cs) Combo Chart 1 Example for WinForms Solution

VB.NET Combo Chart 1 Example Code for Nevron Chart for WinForms
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.DataStructures
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 - NComboChartExample1"

        ' 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 = "Combo Chart"

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

            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)

            ' Setup the primary Y axis
            m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale.Title.Text = "Number of Occurences"

            ' add interlace stripe
            Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            strip.Interlaced = True
            m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale.Strips.Add(strip)

            ' Setup the secondary Y axis
            Dim scaleY2 As NLinearScale = New NLinearScale()
            scaleY2.Labels.TextProvider = New NFormattedScaleLabelTextProvider(New NNumericValueFormatter("0%"))
            scaleY2.Title.Text = "Cumulative Percent"

            Dim axisY2 = m_Chart.Axes(ENCartesianAxis.SecondaryY)

            axisY2.Visible = True
            axisY2.Scale = scaleY2
            axisY2.ViewRangeMode = ENAxisViewRangeMode.FixedRange
            axisY2.MinViewRangeValue = 0
            axisY2.MaxViewRangeValue = 1

            ' add the bar series
            Dim bar As NBarSeries = New NBarSeries()
            m_Chart.Series.Add(bar)
            bar.Name = "Bar Series"
            bar.DataLabelStyle = New NDataLabelStyle(False)

            ' add the line series
            Dim line As NLineSeries = New NLineSeries()
            m_Chart.Series.Add(line)
            line.Name = "Cumulative %"
            line.DataLabelStyle = New NDataLabelStyle(False)

            Dim markerStyle As NMarkerStyle = New NMarkerStyle()
            markerStyle.Visible = True
            markerStyle.Shape = ENPointShape3D.Ellipse
            markerStyle.Size = New NSize(10, 10)
            markerStyle.Fill = New NColorFill(NColor.Orange)

            line.MarkerStyle = markerStyle

            line.VerticalAxis = axisY2

            ' fill with random data and sort in descending order
            Dim count = 10
            Dim randomValues As NList(Of Double) = New NList(Of Double)()
            Dim random As Random = New Random()
            For i = 0 To count - 1
                randomValues.Add(random.Next(100, 700))
            Next

            randomValues.Sort()

            For i = 0 To randomValues.Count - 1
                bar.DataPoints.Add(New NBarDataPoint(randomValues(i)))
            Next

            ' calculate cumulative sum of the bar values
            Dim cs As Double = 0
            Dim arrCumulative = New Double(count - 1) {}

            For i = 0 To count - 1
                cs += randomValues(i)
                arrCumulative(i) = cs
            Next

            If cs > 0 Then
                For i = 0 To count - 1
                    arrCumulative(i) /= cs
                    line.DataPoints.Add(New NLineDataPoint(arrCumulative(i)))
                Next
            End If

            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 group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)

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

This example demonstrates how to create a combo chart consisting of two series (NOV Chart supports an unlimited number of series).

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Cartesian Chart", "https://www.nevron.com/docs/openvision/cartesian-chart.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), ("Bar Series", "https://www.nevron.com/docs/openvision/bar-chart-series.html"), ("Line Series", "https://www.nevron.com/docs/openvision/line-chart-series.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html")} End Function #End Region #Region "Implementation" Private Function CreateLegendFormatCombo() As NComboBox Dim comboBox As NComboBox = New NComboBox() Dim item As NComboBoxItem = New NComboBoxItem("Value and Label") item.Tag = "

Download a fully functional VB.NET (.vb) Combo Chart 1 Example for WinForms Solution