Contour Chart 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.

Contour Chart Example for WinForms Description

This example demonstrates how to create a contour chart.


Contour Chart Example

C# Contour Chart 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 - NContourChartExample";

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

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

			m_HeatMap = new NHeatMapSeries();
			chart.Series.Add(m_HeatMap);

			m_HeatMap.Palette = new NColorValuePalette(new NColorValuePair[] { new NColorValuePair(0.0, NColor.Purple),
																	new NColorValuePair(1.5, NColor.MediumSlateBlue),
																	new NColorValuePair(3.0, NColor.CornflowerBlue),
																	new NColorValuePair(4.5, NColor.LimeGreen),
																	new NColorValuePair(6.0, NColor.LightGreen),
																	new NColorValuePair(7.5, NColor.Yellow),
																	new NColorValuePair(9.0, NColor.Orange),
																	new NColorValuePair(10.5, NColor.Red) });

/*			m_HeatMap.Palette = new NColorValuePalette(new NColorValuePair[] { new NColorValuePair(-5.0, NColor.Purple),
                                                        new NColorValuePair(1, NColor.MediumSlateBlue),
                                                        new NColorValuePair(10.0, NColor.CornflowerBlue) });*/

			m_HeatMap.ContourDisplayMode = ENContourDisplayMode.Contour;
			m_HeatMap.LegendView.Mode = ENSeriesLegendMode.SeriesLogic;
			m_HeatMap.LegendView.Format = "";

			GenerateData();

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

            NNumericUpDown originXUpDown = new NNumericUpDown();
            originXUpDown.ValueChanged += OnOriginXUpDownValueChanged;
            originXUpDown.Value = 0;
            stack.Add(NPairBox.Create("Origin X:", originXUpDown));

            NNumericUpDown originYUpDown = new NNumericUpDown();
            originYUpDown.ValueChanged += OnOriginYUpDownValueChanged;
            originYUpDown.Value = 0;
            stack.Add(NPairBox.Create("Origin Y:", originYUpDown));

            NNumericUpDown GridStepXUpDown = new NNumericUpDown();
            GridStepXUpDown.ValueChanged += OnGridStepXUpDownValueChanged;
            GridStepXUpDown.Value = 1.0;
            stack.Add(NPairBox.Create("Grid Step X:", GridStepXUpDown));

            NNumericUpDown GridStepYUpDown = new NNumericUpDown();
            GridStepYUpDown.ValueChanged += OnGridStepYUpDownValueChanged;
            GridStepYUpDown.Value = 1.0;
            stack.Add(NPairBox.Create("Grid Step Y:", GridStepYUpDown));

            NComboBox contourDisplayModeCombo = new NComboBox();
            contourDisplayModeCombo.Items.FillFromEnum();
            contourDisplayModeCombo.SelectedIndexChanged += OnContourDisplayModeComboSelectedIndexChanged;
            contourDisplayModeCombo.SelectedIndex = (int)ENContourDisplayMode.Contour;
            stack.Add(NPairBox.Create("Contour Display Mode:", contourDisplayModeCombo));

            NComboBox contourColorModeCombo = new NComboBox();
            contourColorModeCombo.Items.FillFromEnum();
            contourColorModeCombo.SelectedIndexChanged += OnContourColorModeComboSelectedIndexChanged;
            contourColorModeCombo.SelectedIndex = (int)ENContourColorMode.Uniform;
            stack.Add(NPairBox.Create("Contour Color Mode:", contourColorModeCombo));

            NCheckBox showFillCheckBox = new NCheckBox("Show Fill");
            showFillCheckBox.CheckedChanged += OnShowFillCheckBoxCheckedChanged;
            showFillCheckBox.Checked = true;
            stack.Add(showFillCheckBox);

            NCheckBox smoothPaletteCheckBox = new NCheckBox("Smooth Palette");
            smoothPaletteCheckBox.CheckedChanged += OnSmoothPaletteCheckBoxCheckedChanged;
            smoothPaletteCheckBox.Checked = true;
            stack.Add(smoothPaletteCheckBox);

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

This example demonstrates how to create a contour chart.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Heat Map Series", "https://www.nevron.com/docs/openvision/heat-map-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), ("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html"), ("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html"), }; } #endregion #region Implementation /* private void GenerateData() { NGridData data = m_HeatMap.Data; int GridStepX = 10; int GridStepY = 10; data.Size = new NSizeI(GridStepX, GridStepY); for (int row = 0; row < GridStepX; row++) { for (int col = 0; col < GridStepY; col++) { int dx = 2 - row; int dy = 2 - col; double distance = Math.Sqrt(dx * dx + dy * dy); data.SetValue(row, col, 5 - distance); } } }*/ private void GenerateData() { NHeatMapData data = m_HeatMap.Data; int GridStepX = 300; int GridStepY = 300; data.Size = new NSizeI(GridStepX, GridStepY); const double dIntervalX = 10.0; const double dIntervalZ = 10.0; double dIncrementX = (dIntervalX / GridStepX); double dIncrementZ = (dIntervalZ / GridStepY); double y, x, z; z = -(dIntervalZ / 2); for (int col = 0; col < GridStepX; col++, z += dIncrementZ) { x = -(dIntervalX / 2); for (int row = 0; row < GridStepY; row++, x += dIncrementX) { y = 10 - Math.Sqrt((x * x) + (z * z) + 2); y += 3.0 * Math.Sin(x) * Math.Cos(z); data.SetValue(row, col, y); } } } #endregion #region Event Handlers void OnOriginYUpDownValueChanged(NValueChangeEventArgs arg) { m_HeatMap.Data.OriginY = ((NNumericUpDown)arg.TargetNode).Value; } void OnOriginXUpDownValueChanged(NValueChangeEventArgs arg) { m_HeatMap.Data.OriginX = ((NNumericUpDown)arg.TargetNode).Value; } void OnGridStepYUpDownValueChanged(NValueChangeEventArgs arg) { m_HeatMap.Data.StepY = ((NNumericUpDown)arg.TargetNode).Value; } void OnGridStepXUpDownValueChanged(NValueChangeEventArgs arg) { m_HeatMap.Data.StepX = ((NNumericUpDown)arg.TargetNode).Value; } void OnShowFillCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_HeatMap.ShowFill = ((NCheckBox)arg.TargetNode).Checked; } void OnContourColorModeComboSelectedIndexChanged(NValueChangeEventArgs arg) { m_HeatMap.ContourColorMode = (ENContourColorMode)((NComboBox)arg.TargetNode).SelectedIndex; } void OnContourDisplayModeComboSelectedIndexChanged(NValueChangeEventArgs arg) { m_HeatMap.ContourDisplayMode = (ENContourDisplayMode)((NComboBox)arg.TargetNode).SelectedIndex; } void OnSmoothPaletteCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_HeatMap.Palette.InterpolateColors = ((NCheckBox)arg.TargetNode).Checked; } #endregion #region Fields NHeatMapSeries m_HeatMap; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

VB.NET Contour Chart 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 - NContourChartExample"

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

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

            m_HeatMap = New NHeatMapSeries()
            chart.Series.Add(m_HeatMap)

            m_HeatMap.Palette = New NColorValuePalette(New NColorValuePair() {New NColorValuePair(0.0, NColor.Purple), New NColorValuePair(1.5, NColor.MediumSlateBlue), New NColorValuePair(3.0, NColor.CornflowerBlue), New NColorValuePair(4.5, NColor.LimeGreen), New NColorValuePair(6.0, NColor.LightGreen), New NColorValuePair(7.5, NColor.Yellow), New NColorValuePair(9.0, NColor.Orange), New NColorValuePair(10.5, NColor.Red)})

            ' 			m_HeatMap.Palette = new NColorValuePalette(new NColorValuePair[] { new NColorValuePair(-5.0, NColor.Purple),
            ' new NColorValuePair(1, NColor.MediumSlateBlue),
            ' new NColorValuePair(10.0, NColor.CornflowerBlue) });

            m_HeatMap.ContourDisplayMode = ENContourDisplayMode.Contour
            m_HeatMap.LegendView.Mode = ENSeriesLegendMode.SeriesLogic
            m_HeatMap.LegendView.Format = ""

            GenerateData()

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

            Dim originXUpDown As NNumericUpDown = New NNumericUpDown()
            originXUpDown.ValueChanged += AddressOf OnOriginXUpDownValueChanged
            originXUpDown.Value = 0
            stack.Add(NPairBox.Create("Origin X:", originXUpDown))

            Dim originYUpDown As NNumericUpDown = New NNumericUpDown()
            originYUpDown.ValueChanged += AddressOf OnOriginYUpDownValueChanged
            originYUpDown.Value = 0
            stack.Add(NPairBox.Create("Origin Y:", originYUpDown))

            Dim GridStepXUpDown As NNumericUpDown = New NNumericUpDown()
            GridStepXUpDown.ValueChanged += AddressOf OnGridStepXUpDownValueChanged
            GridStepXUpDown.Value = 1.0
            stack.Add(NPairBox.Create("Grid Step X:", GridStepXUpDown))

            Dim GridStepYUpDown As NNumericUpDown = New NNumericUpDown()
            GridStepYUpDown.ValueChanged += AddressOf OnGridStepYUpDownValueChanged
            GridStepYUpDown.Value = 1.0
            stack.Add(NPairBox.Create("Grid Step Y:", GridStepYUpDown))

            Dim contourDisplayModeCombo As NComboBox = New NComboBox()
            contourDisplayModeCombo.Items.FillFromEnum(Of ENContourDisplayMode)()
            contourDisplayModeCombo.SelectedIndexChanged += AddressOf OnContourDisplayModeComboSelectedIndexChanged
            contourDisplayModeCombo.SelectedIndex = CInt(ENContourDisplayMode.Contour)
            stack.Add(NPairBox.Create("Contour Display Mode:", contourDisplayModeCombo))

            Dim contourColorModeCombo As NComboBox = New NComboBox()
            contourColorModeCombo.Items.FillFromEnum(Of ENContourColorMode)()
            contourColorModeCombo.SelectedIndexChanged += AddressOf OnContourColorModeComboSelectedIndexChanged
            contourColorModeCombo.SelectedIndex = CInt(ENContourColorMode.Uniform)
            stack.Add(NPairBox.Create("Contour Color Mode:", contourColorModeCombo))

            Dim showFillCheckBox As NCheckBox = New NCheckBox("Show Fill")
            showFillCheckBox.CheckedChanged += AddressOf OnShowFillCheckBoxCheckedChanged
            showFillCheckBox.Checked = True
            stack.Add(showFillCheckBox)

            Dim smoothPaletteCheckBox As NCheckBox = New NCheckBox("Smooth Palette")
            smoothPaletteCheckBox.CheckedChanged += AddressOf OnSmoothPaletteCheckBoxCheckedChanged
            smoothPaletteCheckBox.Checked = True
            stack.Add(smoothPaletteCheckBox)

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

This example demonstrates how to create a contour chart.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Heat Map Series", "https://www.nevron.com/docs/openvision/heat-map-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), ("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html"), ("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html")} End Function #End Region #Region "Implementation" ' private void GenerateData() ' { ' NGridData data = m_HeatMap.Data; ' ' int GridStepX = 10; ' int GridStepY = 10; ' data.Size = new NSizeI(GridStepX, GridStepY); ' ' for (int row = 0; row < GridStepX; row++) ' { ' for (int col = 0; col < GridStepY; col++) ' { ' int dx = 2 - row; ' int dy = 2 - col; ' double distance = Math.Sqrt(dx * dx + dy * dy); ' ' data.SetValue(row, col, 5 - distance); ' } ' } ' } Private Sub GenerateData() Dim data = m_HeatMap.Data Dim GridStepX = 300 Dim GridStepY = 300 data.Size = New NSizeI(GridStepX, GridStepY) Const dIntervalX = 10.0 Const dIntervalZ = 10.0 Dim dIncrementX = dIntervalX / GridStepX Dim dIncrementZ = dIntervalZ / GridStepY Dim y, x, z As Double z = -(dIntervalZ / 2) Dim col = 0 While col < GridStepX x = -(dIntervalX / 2) Dim row = 0 While row < GridStepY y = 10 - Math.Sqrt(x * x + z * z + 2) y += 3.0 * Math.Sin(x) * Math.Cos(z) data.SetValue(row, col, y) row += 1 x += dIncrementX End While col += 1 z += dIncrementZ End While End Sub #End Region #Region "Event Handlers" Private Sub OnOriginYUpDownValueChanged(arg As NValueChangeEventArgs) m_HeatMap.Data.OriginY = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnOriginXUpDownValueChanged(arg As NValueChangeEventArgs) m_HeatMap.Data.OriginX = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnGridStepYUpDownValueChanged(arg As NValueChangeEventArgs) m_HeatMap.Data.StepY = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnGridStepXUpDownValueChanged(arg As NValueChangeEventArgs) m_HeatMap.Data.StepX = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnShowFillCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_HeatMap.ShowFill = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnContourColorModeComboSelectedIndexChanged(arg As NValueChangeEventArgs) m_HeatMap.ContourColorMode = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENContourColorMode) End Sub Private Sub OnContourDisplayModeComboSelectedIndexChanged(arg As NValueChangeEventArgs) m_HeatMap.ContourDisplayMode = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENContourDisplayMode) End Sub Private Sub OnSmoothPaletteCheckBoxCheckedChanged(arg As NValueChangeEventArgs) m_HeatMap.Palette.InterpolateColors = CType(arg.TargetNode, NCheckBox).Checked End Sub #End Region #Region "Fields" Private m_HeatMap As NHeatMapSeries #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) Contour Chart Example for WinForms Solution