Grid Surface Spacing Example for WPF

Nevron NOV Chart for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF 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.

Grid Surface Spacing Example for WPF Description

This example demonstrates how to control the spacing between the grid cells in a grid surface series.


Grid Surface Spacing Example

C# Grid Surface Spacing Example Code for Nevron Chart for WPF
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 - NGridSurfaceSpacingExample";

			// 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 = "Grid Surface Grid Spacing";

            // setup chart
            NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
            chart.Enable3D = true;
            chart.ModelWidth = 55.0f;
            chart.ModelDepth = 55.0f;
            chart.ModelHeight = 45.0f;
            chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted);
            chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.SoftCameraLight);
            chart.Interactor = new NInteractor(new NTrackballTool());

            // add a surface series
            m_Surface = new NGridSurfaceSeries();
            chart.Series.Add(m_Surface);
            m_Surface.Name = "Surface";
            m_Surface.LegendView.Mode = ENSeriesLegendMode.None;
            m_Surface.Fill = new NColorFill(NColor.FromRGB(160, 170, 212));
            m_Surface.FillColorMode = ENColorMode.Uniform;
            m_Surface.ShowFrame = true;
            m_Surface.FrameMode = ENSurfaceFrameMode.Mesh;
            m_Surface.CellTriangulationMode = ENSurfaceCellTriangulationMode.Diagonal1;
            m_Surface.Data.SetGridSize(500, 500);

            // setup axes
            NLinearScale scaleX = new NLinearScale();
            chart.Axes[ENCartesianAxis.PrimaryX].Scale = scaleX;
            scaleX.MajorGridLines.ShowAtWalls = ENChartWall.Bottom |ENChartWall.Back;
            scaleX.InflateViewRangeBegin = false;
            scaleX.InflateViewRangeEnd = false;

            NLinearScale scaleZ = new NLinearScale();
            chart.Axes[ENCartesianAxis.Depth].Scale = scaleZ;
            scaleZ.MajorGridLines.ShowAtWalls = ENChartWall.Bottom | ENChartWall.Left;
            scaleZ.InflateViewRangeBegin = false;
            scaleZ.InflateViewRangeEnd = false;

            // add interlace stripe to the Y axis
            NLinearScale linearScale = chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLinearScale;
            NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
            stripStyle.Interlaced = true;
            stripStyle.SetShowAtWall(ENChartWall.Back, true);
            stripStyle.SetShowAtWall(ENChartWall.Left, true);
            linearScale.Strips.Add(stripStyle);

            // specify that the surface should use custom X and Z values
            m_Surface.XValuesMode = ENGridSurfaceValuesMode.CustomValues;
            m_Surface.ZValuesMode = ENGridSurfaceValuesMode.CustomValues;

            m_Surface.Data.SetGridSize(40, 40);

            GenerateCustomXValues(m_Surface);
            GenerateCustomZValues(m_Surface);
            FillData(m_Surface);

            return chartViewWithCommandBars;
        }

        private void GenerateCustomXValues(NGridSurfaceSeries surface)
        {
            int sizeX = surface.Data.GridSizeX;

            double x = 0;
            double[] xValues = new double[sizeX];
            Random random = new Random();

            for (int i = 0; i < sizeX; i++)
            {
                xValues[i] = x;
                x += random.NextDouble() * 10.0;
            }

            surface.XValues = new NDomArray(xValues);
        }

        private void GenerateCustomZValues(NGridSurfaceSeries surface)
        {
            int sizeZ = surface.Data.GridSizeZ;

            double[] zValues = new double[sizeZ];
            double z = 0;
            Random random = new Random();

            for (int i = 0; i < sizeZ; i++)
            {
                zValues[i] = z;
                z += random.NextDouble() * 10;
            }

            surface.ZValues = new NDomArray(zValues);
        }

        private void FillData(NGridSurfaceSeries surface)
        {
            int nCountX = surface.Data.GridSizeX;
            int nCountZ = surface.Data.GridSizeZ;

            double sizeXOrigin = -2.3;
            double sizeXScale = 4.6 / nCountX;


            for (int z = 0; z < nCountZ; z++)
            {
                for (int x = 0; x < nCountX; x++)
                {
                    double xVal = (x * sizeXScale) + sizeXOrigin;
                    double yVal = (z * sizeXScale) + sizeXOrigin;

                    double zVal = xVal * Math.Exp(-(xVal * xVal + yVal * yVal));

                    surface.Data.SetValue(x, z, zVal);
                }
            }
        }

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

            NComboBox spacingComboBox = new NComboBox();
            spacingComboBox.Items.FillFromEnum();
            stack.Add(NPairBox.Create("Spacing Mode:", spacingComboBox));

            m_XGridOriginNumericUpDown = new NNumericUpDown();
            stack.Add(NPairBox.Create("X Origin:", m_XGridOriginNumericUpDown));
            m_XGridOriginNumericUpDown.ValueChanged += OnXOriginNumericUpDownValueChanged;

            m_XGridStepNumericUpDown = new NNumericUpDown();
            stack.Add(NPairBox.Create("X Grid Step:", m_XGridStepNumericUpDown));
            m_XGridStepNumericUpDown.ValueChanged += OnXGridStepNumericUpDownValueChanged;

            m_ZGridOriginNumericUpDown = new NNumericUpDown();
            stack.Add(NPairBox.Create("Z Origin:", m_ZGridOriginNumericUpDown));
            m_ZGridOriginNumericUpDown.ValueChanged += OnZOriginNumericUpDownValueChanged;

            m_ZGridStepNumericUpDown = new NNumericUpDown();
            stack.Add(NPairBox.Create("Z Grid Step:", m_ZGridStepNumericUpDown));
            m_ZGridStepNumericUpDown.ValueChanged += OnZGridStepNumericUpDownValueChanged;

            spacingComboBox.SelectedIndexChanged += OnSpacingModeComboBoxSelectedIndexChanged;
            spacingComboBox.SelectedIndex = 1;

            m_XGridOriginNumericUpDown.Value = 0;
            m_ZGridOriginNumericUpDown.Value = 0;
            m_XGridStepNumericUpDown.Value = 1;
            m_ZGridStepNumericUpDown.Value = 1;

            return group;
        }

        private void OnXGridStepNumericUpDownValueChanged(NValueChangeEventArgs arg)
        {
            m_Surface.StepX = (double)arg.NewValue;
        }

        private void OnXOriginNumericUpDownValueChanged(NValueChangeEventArgs arg)
        {
            m_Surface.OriginX = (double)arg.NewValue;
        }

        private void OnZOriginNumericUpDownValueChanged(NValueChangeEventArgs arg)
        {
            m_Surface.OriginZ = (double)arg.NewValue;
        }

        private void OnZGridStepNumericUpDownValueChanged(NValueChangeEventArgs arg)
        {
            m_Surface.StepZ = (double)arg.NewValue;
        }

        public string GetExampleDescription()
        {
            return @"

This example demonstrates how to control the spacing between the grid cells in a grid surface series.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Grid Surface Series", "https://www.nevron.com/docs/openvision/grid-surface-chart-series.html"), ("Surface Series Overview", "https://www.nevron.com/docs/openvision/surface-chart-series-overview.html"), ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields NGridSurfaceSeries m_Surface; NNumericUpDown m_XGridOriginNumericUpDown; NNumericUpDown m_XGridStepNumericUpDown; NNumericUpDown m_ZGridOriginNumericUpDown; NNumericUpDown m_ZGridStepNumericUpDown; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Grid Surface Spacing Example for WPF Solution

VB.NET Grid Surface Spacing Example Code for Nevron Chart for WPF
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.Wpf
Imports System

Class MainWindow

#Region "Constructors"

	Public Sub New()
		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NGridSurfaceSpacingExample"

		' 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)
		Content = 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 = "Grid Surface Grid Spacing"

            ' setup chart
            Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)
            chart.Enable3D = True
            chart.ModelWidth = 55.0F
            chart.ModelDepth = 55.0F
            chart.ModelHeight = 45.0F
            chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)
            chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.SoftCameraLight)
            chart.Interactor = New NInteractor(New NTrackballTool())

            ' add a surface series
            m_Surface = New NGridSurfaceSeries()
            chart.Series.Add(m_Surface)
            m_Surface.Name = "Surface"
            m_Surface.LegendView.Mode = ENSeriesLegendMode.None
            m_Surface.Fill = New NColorFill(NColor.FromRGB(160, 170, 212))
            m_Surface.FillColorMode = ENColorMode.Uniform
            m_Surface.ShowFrame = True
            m_Surface.FrameMode = ENSurfaceFrameMode.Mesh
            m_Surface.CellTriangulationMode = ENSurfaceCellTriangulationMode.Diagonal1
            m_Surface.Data.SetGridSize(500, 500)

            ' setup axes
            Dim scaleX As NLinearScale = New NLinearScale()
            chart.Axes(ENCartesianAxis.PrimaryX).Scale = scaleX
            scaleX.MajorGridLines.ShowAtWalls = ENChartWall.Bottom Or ENChartWall.Back
            scaleX.InflateViewRangeBegin = False
            scaleX.InflateViewRangeEnd = False

            Dim scaleZ As NLinearScale = New NLinearScale()
            chart.Axes(ENCartesianAxis.Depth).Scale = scaleZ
            scaleZ.MajorGridLines.ShowAtWalls = ENChartWall.Bottom Or ENChartWall.Left
            scaleZ.InflateViewRangeBegin = False
            scaleZ.InflateViewRangeEnd = False

            ' add interlace stripe to the Y axis
            Dim linearScale As NLinearScale = TryCast(chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale)
            Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            stripStyle.Interlaced = True
            stripStyle.SetShowAtWall(ENChartWall.Back, True)
            stripStyle.SetShowAtWall(ENChartWall.Left, True)
            linearScale.Strips.Add(stripStyle)

            ' specify that the surface should use custom X and Z values
            m_Surface.XValuesMode = ENGridSurfaceValuesMode.CustomValues
            m_Surface.ZValuesMode = ENGridSurfaceValuesMode.CustomValues

            m_Surface.Data.SetGridSize(40, 40)

            GenerateCustomXValues(m_Surface)
            GenerateCustomZValues(m_Surface)
            FillData(m_Surface)

            Return chartViewWithCommandBars
        End Function

        Private Sub GenerateCustomXValues(surface As NGridSurfaceSeries)
            Dim sizeX = surface.Data.GridSizeX

            Dim x As Double = 0
            Dim xValues = New Double(sizeX - 1) {}
            Dim random As Random = New Random()

            For i = 0 To sizeX - 1
                xValues(i) = x
                x += random.NextDouble() * 10.0
            Next

            surface.XValues = New NDomArray(Of Double)(xValues)
        End Sub

        Private Sub GenerateCustomZValues(surface As NGridSurfaceSeries)
            Dim sizeZ = surface.Data.GridSizeZ

            Dim zValues = New Double(sizeZ - 1) {}
            Dim z As Double = 0
            Dim random As Random = New Random()

            For i = 0 To sizeZ - 1
                zValues(i) = z
                z += random.NextDouble() * 10
            Next

            surface.ZValues = New NDomArray(Of Double)(zValues)
        End Sub

        Private Sub FillData(surface As NGridSurfaceSeries)
            Dim nCountX = surface.Data.GridSizeX
            Dim nCountZ = surface.Data.GridSizeZ

            Dim sizeXOrigin = -2.3
            Dim sizeXScale = 4.6 / nCountX


            For z = 0 To nCountZ - 1
                For x = 0 To nCountX - 1
                    Dim xVal = x * sizeXScale + sizeXOrigin
                    Dim yVal = z * sizeXScale + sizeXOrigin

                    Dim zVal = xVal * Math.Exp(-(xVal * xVal + yVal * yVal))

                    surface.Data.SetValue(x, z, zVal)
                Next
            Next
        End Sub

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

            Dim spacingComboBox As NComboBox = New NComboBox()
            spacingComboBox.Items.FillFromEnum(Of ENGridSurfaceValuesMode)()
            stack.Add(NPairBox.Create("Spacing Mode:", spacingComboBox))

            m_XGridOriginNumericUpDown = New NNumericUpDown()
            stack.Add(NPairBox.Create("X Origin:", m_XGridOriginNumericUpDown))
            Me.m_XGridOriginNumericUpDown.ValueChanged += AddressOf OnXOriginNumericUpDownValueChanged

            m_XGridStepNumericUpDown = New NNumericUpDown()
            stack.Add(NPairBox.Create("X Grid Step:", m_XGridStepNumericUpDown))
            Me.m_XGridStepNumericUpDown.ValueChanged += AddressOf OnXGridStepNumericUpDownValueChanged

            m_ZGridOriginNumericUpDown = New NNumericUpDown()
            stack.Add(NPairBox.Create("Z Origin:", m_ZGridOriginNumericUpDown))
            Me.m_ZGridOriginNumericUpDown.ValueChanged += AddressOf OnZOriginNumericUpDownValueChanged

            m_ZGridStepNumericUpDown = New NNumericUpDown()
            stack.Add(NPairBox.Create("Z Grid Step:", m_ZGridStepNumericUpDown))
            Me.m_ZGridStepNumericUpDown.ValueChanged += AddressOf OnZGridStepNumericUpDownValueChanged

            spacingComboBox.SelectedIndexChanged += AddressOf OnSpacingModeComboBoxSelectedIndexChanged
            spacingComboBox.SelectedIndex = 1

            m_XGridOriginNumericUpDown.Value = 0
            m_ZGridOriginNumericUpDown.Value = 0
            m_XGridStepNumericUpDown.Value = 1
            m_ZGridStepNumericUpDown.Value = 1

            Return group
        End Function

        Private Sub OnXGridStepNumericUpDownValueChanged(arg As NValueChangeEventArgs)
            m_Surface.StepX = CDbl(arg.NewValue)
        End Sub

        Private Sub OnXOriginNumericUpDownValueChanged(arg As NValueChangeEventArgs)
            m_Surface.OriginX = CDbl(arg.NewValue)
        End Sub

        Private Sub OnZOriginNumericUpDownValueChanged(arg As NValueChangeEventArgs)
            m_Surface.OriginZ = CDbl(arg.NewValue)
        End Sub

        Private Sub OnZGridStepNumericUpDownValueChanged(arg As NValueChangeEventArgs)
            m_Surface.StepZ = CDbl(arg.NewValue)
        End Sub

        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to control the spacing between the grid cells in a grid surface series.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Grid Surface Series", "https://www.nevron.com/docs/openvision/grid-surface-chart-series.html"), ("Surface Series Overview", "https://www.nevron.com/docs/openvision/surface-chart-series-overview.html"), ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_Surface As NGridSurfaceSeries Private m_XGridOriginNumericUpDown As NNumericUpDown Private m_XGridStepNumericUpDown As NNumericUpDown Private m_ZGridOriginNumericUpDown As NNumericUpDown Private m_ZGridStepNumericUpDown As NNumericUpDown #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) Grid Surface Spacing Example for WPF Solution