XY Scatter Area 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.

XY Scatter Area Example for WinForms Description

This example demonstrates how to create an XY scatter area chart.


XYScatter Area Example

C# XY Scatter Area Example Code for Nevron Chart for WinForms
Language: C#

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

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

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

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

            // show the x axis grid lines
			linearScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale;

			NScaleGridLines majorGrid = new NScaleGridLines();
			majorGrid.Visible = true;
			linearScale.MajorGridLines = majorGrid;

			// add the area series
			m_Area = new NAreaSeries();
			m_Area.Name = "Area Series";

			NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
			dataLabelStyle.Visible = true;
			dataLabelStyle.ArrowStroke.Width = 0;
			dataLabelStyle.Format = "";
			m_Area.DataLabelStyle = dataLabelStyle;

			m_Area.UseXValues = true;

			// add xy values
			m_Area.DataPoints.Add(new NAreaDataPoint(12, 10));
			m_Area.DataPoints.Add(new NAreaDataPoint(25, 23));
			m_Area.DataPoints.Add(new NAreaDataPoint(45, 12));
			m_Area.DataPoints.Add(new NAreaDataPoint(55, 24));
			m_Area.DataPoints.Add(new NAreaDataPoint(61, 16));
			m_Area.DataPoints.Add(new NAreaDataPoint(69, 19));
			m_Area.DataPoints.Add(new NAreaDataPoint(78, 17));

			chart.Series.Add(m_Area);

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

			NButton changeXValuesButton = new NButton("Change X Values");
			changeXValuesButton.Click += OnChangeXValuesButtonClick;
			stack.Add(changeXValuesButton);

			NCheckBox xAxisRoundToTickCheckBox = new NCheckBox("X Axis Round To Tick");
			xAxisRoundToTickCheckBox.CheckedChanged += OnXAxisRoundToTickCheckBoxCheckedChanged;
			stack.Add(xAxisRoundToTickCheckBox);

			NCheckBox invertXAxisCheckBox = new NCheckBox("Invert X Axis");
			invertXAxisCheckBox.CheckedChanged += OnInvertXAxisCheckBoxCheckedChanged;
			stack.Add(invertXAxisCheckBox);

			NCheckBox invertYAxisCheckBox = new NCheckBox("Invert Y Axis");
			invertYAxisCheckBox.CheckedChanged += OnInvertYAxisCheckBoxCheckedChanged;
			stack.Add(invertYAxisCheckBox);

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

This example demonstrates how to create an XY scatter 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"), ("Linear Scale", "https://www.nevron.com/docs/openvision/linear-scale.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnChangeXValuesButtonClick(NEventArgs arg) { Random random = new Random(); int dataPointCount = m_Area.DataPoints.Count; m_Area.DataPoints[0].X = (double)random.Next(10); for (int i = 1; i < dataPointCount; i++) { m_Area.DataPoints[i].X = m_Area.DataPoints[i - 1].X + random.Next(1, 10); } } void OnInvertXAxisCheckBoxCheckedChanged(NValueChangeEventArgs arg) { NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0]; chart.Axes[ENCartesianAxis.PrimaryX].Scale.Invert = ((NCheckBox)arg.TargetNode).Checked; } void OnInvertYAxisCheckBoxCheckedChanged(NValueChangeEventArgs arg) { NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0]; chart.Axes[ENCartesianAxis.PrimaryY].Scale.Invert = ((NCheckBox)arg.TargetNode).Checked; } void OnXAxisRoundToTickCheckBoxCheckedChanged(NValueChangeEventArgs arg) { NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0]; NLinearScale linearScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale; if ((arg.TargetNode as NCheckBox).Checked) { linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.MajorTick; linearScale.InflateViewRangeBegin = true; linearScale.InflateViewRangeEnd = true; } else { linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.Logical; } } #endregion #region Fields private NChartView m_ChartView; private NAreaSeries m_Area; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) XY Scatter Area Example for WinForms Solution

VB.NET XY Scatter Area Example Code for Nevron Chart for WinForms
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.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 - NXYScatterAreaExample"

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

            ' configure title
            m_ChartView.Surface.Titles(0).Text = "XY Scatter Area"

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

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

            ' show the x axis grid lines
            linearScale = chart.Axes(ENCartesianAxis.PrimaryX).Scale

            Dim majorGrid As NScaleGridLines = New NScaleGridLines()
            majorGrid.Visible = True
            linearScale.MajorGridLines = majorGrid

            ' add the area series
            m_Area = New NAreaSeries()
            m_Area.Name = "Area Series"

            Dim dataLabelStyle As NDataLabelStyle = New NDataLabelStyle()
            dataLabelStyle.Visible = True
            dataLabelStyle.ArrowStroke.Width = 0
            dataLabelStyle.Format = ""
            m_Area.DataLabelStyle = dataLabelStyle

            m_Area.UseXValues = True

            ' add xy values
            m_Area.DataPoints.Add(New NAreaDataPoint(12, 10))
            m_Area.DataPoints.Add(New NAreaDataPoint(25, 23))
            m_Area.DataPoints.Add(New NAreaDataPoint(45, 12))
            m_Area.DataPoints.Add(New NAreaDataPoint(55, 24))
            m_Area.DataPoints.Add(New NAreaDataPoint(61, 16))
            m_Area.DataPoints.Add(New NAreaDataPoint(69, 19))
            m_Area.DataPoints.Add(New NAreaDataPoint(78, 17))

            chart.Series.Add(m_Area)

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

            Dim changeXValuesButton As NButton = New NButton("Change X Values")
            changeXValuesButton.Click += AddressOf OnChangeXValuesButtonClick
            stack.Add(changeXValuesButton)

            Dim xAxisRoundToTickCheckBox As NCheckBox = New NCheckBox("X Axis Round To Tick")
            xAxisRoundToTickCheckBox.CheckedChanged += AddressOf OnXAxisRoundToTickCheckBoxCheckedChanged
            stack.Add(xAxisRoundToTickCheckBox)

            Dim invertXAxisCheckBox As NCheckBox = New NCheckBox("Invert X Axis")
            invertXAxisCheckBox.CheckedChanged += AddressOf OnInvertXAxisCheckBoxCheckedChanged
            stack.Add(invertXAxisCheckBox)

            Dim invertYAxisCheckBox As NCheckBox = New NCheckBox("Invert Y Axis")
            invertYAxisCheckBox.CheckedChanged += AddressOf OnInvertYAxisCheckBoxCheckedChanged
            stack.Add(invertYAxisCheckBox)


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

This example demonstrates how to create an XY scatter 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"), ("Linear Scale", "https://www.nevron.com/docs/openvision/linear-scale.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnChangeXValuesButtonClick(arg As NEventArgs) Dim random As Random = New Random() Dim dataPointCount = m_Area.DataPoints.Count m_Area.DataPoints(0).X = random.Next(10) For i = 1 To dataPointCount - 1 m_Area.DataPoints(i).X = m_Area.DataPoints(i - 1).X + random.Next(1, 10) Next End Sub Private Sub OnInvertXAxisCheckBoxCheckedChanged(arg As NValueChangeEventArgs) Dim chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart) chart.Axes(ENCartesianAxis.PrimaryX).Scale.Invert = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnInvertYAxisCheckBoxCheckedChanged(arg As NValueChangeEventArgs) Dim chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart) chart.Axes(ENCartesianAxis.PrimaryY).Scale.Invert = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnXAxisRoundToTickCheckBoxCheckedChanged(arg As NValueChangeEventArgs) Dim chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart) Dim linearScale As NLinearScale = chart.Axes(ENCartesianAxis.PrimaryX).Scale If TryCast(arg.TargetNode, NCheckBox).Checked Then linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.MajorTick linearScale.InflateViewRangeBegin = True linearScale.InflateViewRangeEnd = True Else linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.Logical End If End Sub #End Region #Region "Fields" Private m_ChartView As NChartView Private m_Area As NAreaSeries #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) XY Scatter Area Example for WinForms Solution