Vertex Surface Frame Custom Colors Example for WinForms

Vertex Surface Frame Custom Colors 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.

Vertex Surface Frame Custom Colors Example for WinForms Description

The example demonstrates how to use the Vertex Surface series to plot lines with large amounts of vertices, and with custom color per vertex.


Vertex Surface Frame Custom Colors Example

C# Vertex Surface Frame Custom Colors 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 - NVertexSurfaceFrameCustomColorsExample";

			// 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 = "Vertex Surface Series Line With Custom Colors";

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

            // setup axes
            NLinearScale scaleY = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
            scaleY.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;

            // add interlace stripe to the Y axis
            NScaleStrip stripStyleY = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
            stripStyleY.Interlaced = true;
            stripStyleY.SetShowAtWall(ENChartWall.Back, true);
            stripStyleY.SetShowAtWall(ENChartWall.Left, true);
            scaleY.Strips.Add(stripStyleY);

            NLinearScale scaleX = new NLinearScale();
            scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
            scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);
            scaleX.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;
            m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = scaleX;

            NLinearScale scaleZ = new NLinearScale();
            scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
            scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Left, true);
            scaleZ.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;
            m_Chart.Axes[ENCartesianAxis.Depth].Scale = scaleZ;

            // add the surface series
            m_Surface = new NVertexSurfaceSeries();
            m_Chart.Series.Add(m_Surface);

            m_Surface.Name = "Surface";
            m_Surface.LegendView.Mode = ENSeriesLegendMode.SeriesLogic;
            m_Surface.FlatPositionValue = 10.0;
            m_Surface.Palette.InterpolateColors = false;
            m_Surface.ValueFormatter = new NNumericValueFormatter("0.00");
            m_Surface.ShowFrame = true;
            m_Surface.FrameColorMode = ENColorMode.Custom;
            m_Surface.VertexPrimitive = ENVertexPrimitive.Triangles;
            m_Surface.Data.HasColors = true;
            m_Surface.UseIndices = true;

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

            m_NumberOfLinesUpDown = new NNumericUpDown();
            m_NumberOfLinesUpDown.Minimum = 1;
            m_NumberOfLinesUpDown.Maximum = 10;
            m_NumberOfLinesUpDown.ValueChanged += OnNumberOfLinesUpDownValueChanged;
            stack.Add(NPairBox.Create("Number of Lines:", m_NumberOfLinesUpDown));

            m_DataCountPerLineComboBox = new NComboBox();

            m_DataCountPerLineComboBox.Items.Add(new NComboBoxItem("10K"));
            m_DataCountPerLineComboBox.Items.Add(new NComboBoxItem("100K"));
            m_DataCountPerLineComboBox.Items.Add(new NComboBoxItem("500K"));

            m_DataCountPerLineComboBox.SelectedIndexChanged += OnDataCountPerLineComboBoxSelectedIndexChanged;
            
            stack.Add(NPairBox.Create("Data Count Per Line:", m_DataCountPerLineComboBox));

            m_DataCountPerLineComboBox.SelectedIndex = 1;
            m_NumberOfLinesUpDown.Value = 7;

            return group;
        }

        private void UpdateData()
        {
            int dataPointCount = 0;

            switch (m_DataCountPerLineComboBox.SelectedIndex)
            {
                case 0:
                    dataPointCount = 10000;
                    break;
                case 1:
                    dataPointCount = 100000;
                    break;
                case 2:
                    dataPointCount = 500000;
                    break;
            }

            int lineCount = (int)m_NumberOfLinesUpDown.Value;
            m_Chart.Series.Clear();
            Random random = new Random();

            NColor[] palette = NChartPalette.GetColors(ENChartPalette.Fresh);

            for (int lineIndex = 0; lineIndex < lineCount; lineIndex++)
            {
                // setup surface series
                NVertexSurfaceSeries surface = new NVertexSurfaceSeries();
                m_Chart.Series.Add(surface);

                surface.Name = "Surface";

                surface.ShowFill = false;
                surface.FillColorMode = ENColorMode.Custom;

                surface.ShowFrame = true;
                surface.FrameMode = ENSurfaceFrameMode.Dots;
                surface.FrameColorMode = ENColorMode.Custom;

                surface.VertexPrimitive = ENVertexPrimitive.LineStrip;
                
                surface.Data.HasColors = true;
                surface.Data.SetCapacity(dataPointCount);

                double x = 0.1;
                double y = 0;
                double z = 0;
                double a = 10.0;
                double b = 18 + lineIndex; // 28.0 - ;
                double c = (lineIndex + 3) / 3.0; //8.0
                double t = lineIndex * (0.01 / lineCount) + 0.01;

                NColor color1 = palette[lineIndex % palette.Length];
                NColor color2 = palette[(lineIndex + 1) % palette.Length];

                unsafe
                {
                    fixed (byte* pData = &surface.Data.Data[0])
                    {
                        float* pVertex = (float*)pData;
                        uint* pColor = (uint*)(pData + surface.Data.ColorOffset * 4);

                        for (int dataPointIndex = 0; dataPointIndex < dataPointCount; dataPointIndex++)
                        {
                            float xt = (float)(x + t * a * (y - x));
                            float yt = (float)(y + t * (x * (b - z) - y));
                            float zt = (float)(z + t * (x * y - c * z));

                            pVertex[0] = xt;
                            pVertex[1] = yt;
                            pVertex[2] = zt;

                            NColor color = NColor.InterpolateColors(color1, color2, (float)((yt + 40.0) / 80.0));
                            *pColor = color.PackedARGB;

                            pVertex += 4;
                            pColor += 4;

                            x = xt;
                            y = yt;
                            z = zt;
                        }
                    }
                }

                // notify series that data has changed as we've modified it directly using pointers
                surface.Data.SetCount(dataPointCount);
            }
        }
        /// 
        /// 
        /// 
        /// 
        private void OnNumberOfLinesUpDownValueChanged(NValueChangeEventArgs arg)
        {
            UpdateData();
        }
        /// 
        /// 
        /// 
        /// 
        private void OnDataCountPerLineComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
        {
            UpdateData();
        }
        /// 
        /// 
        /// 
        /// 
        public string GetExampleDescription()
        {
            return @"

The example demonstrates how to use the Vertex Surface series to plot lines with large amounts of vertices, and with custom color per vertex.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Vertex Surface Series", "https://www.nevron.com/docs/openvision/vertex-surface-chart-series.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 #endregion #region Event Handlers #endregion #region Fields NNumericUpDown m_NumberOfLinesUpDown; NComboBox m_DataCountPerLineComboBox; NVertexSurfaceSeries m_Surface; NCartesianChart m_Chart; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Vertex Surface Frame Custom Colors Example for WinForms Solution

VB.NET Vertex Surface Frame Custom Colors 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 - NVertexSurfaceFrameCustomColorsExample"

        ' 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 = "Vertex Surface Series Line With Custom Colors"

            ' setup chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
            m_Chart.Enable3D = True
            m_Chart.ModelWidth = 60.0F
            m_Chart.ModelDepth = 60.0F
            m_Chart.ModelHeight = 50.0F
            m_Chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)
            m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.SoftTopLeft)
            m_Chart.Interactor = New NInteractor(New NTrackballTool())

            ' setup axes
            Dim scaleY As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale
            scaleY.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None

            ' add interlace stripe to the Y axis
            Dim stripStyleY As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            stripStyleY.Interlaced = True
            stripStyleY.SetShowAtWall(ENChartWall.Back, True)
            stripStyleY.SetShowAtWall(ENChartWall.Left, True)
            scaleY.Strips.Add(stripStyleY)

            Dim scaleX As NLinearScale = New NLinearScale()
            scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
            scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)
            scaleX.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None
            m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale = scaleX

            Dim scaleZ As NLinearScale = New NLinearScale()
            scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
            scaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Left, True)
            scaleZ.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None
            m_Chart.Axes(ENCartesianAxis.Depth).Scale = scaleZ

            ' add the surface series
            m_Surface = New NVertexSurfaceSeries()
            m_Chart.Series.Add(m_Surface)

            m_Surface.Name = "Surface"
            m_Surface.LegendView.Mode = ENSeriesLegendMode.SeriesLogic
            m_Surface.FlatPositionValue = 10.0
            m_Surface.Palette.InterpolateColors = False
            m_Surface.ValueFormatter = New NNumericValueFormatter("0.00")
            m_Surface.ShowFrame = True
            m_Surface.FrameColorMode = ENColorMode.Custom
            m_Surface.VertexPrimitive = ENVertexPrimitive.Triangles
            m_Surface.Data.HasColors = True
            m_Surface.UseIndices = True

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

            m_NumberOfLinesUpDown = New NNumericUpDown()
            m_NumberOfLinesUpDown.Minimum = 1
            m_NumberOfLinesUpDown.Maximum = 10
            Me.m_NumberOfLinesUpDown.ValueChanged += AddressOf OnNumberOfLinesUpDownValueChanged
            stack.Add(NPairBox.Create("Number of Lines:", m_NumberOfLinesUpDown))

            m_DataCountPerLineComboBox = New NComboBox()

            m_DataCountPerLineComboBox.Items.Add(New NComboBoxItem("10K"))
            m_DataCountPerLineComboBox.Items.Add(New NComboBoxItem("100K"))
            m_DataCountPerLineComboBox.Items.Add(New NComboBoxItem("500K"))

            Me.m_DataCountPerLineComboBox.SelectedIndexChanged += AddressOf OnDataCountPerLineComboBoxSelectedIndexChanged

            stack.Add(NPairBox.Create("Data Count Per Line:", m_DataCountPerLineComboBox))

            m_DataCountPerLineComboBox.SelectedIndex = 1
            m_NumberOfLinesUpDown.Value = 7

            Return group
        End Function

        Private Sub UpdateData()
            Dim dataPointCount = 0

            Select Case m_DataCountPerLineComboBox.SelectedIndex
                Case 0
                    dataPointCount = 10000
                Case 1
                    dataPointCount = 100000
                Case 2
                    dataPointCount = 500000
            End Select

            Dim lineCount As Integer = m_NumberOfLinesUpDown.Value
            m_Chart.Series.Clear()
            Dim random As Random = New Random()

            Dim palette = NChartPalette.GetColors(ENChartPalette.Fresh)

            For lineIndex = 0 To lineCount - 1
                ' setup surface series
                Dim surface As NVertexSurfaceSeries = New NVertexSurfaceSeries()
                m_Chart.Series.Add(surface)

                surface.Name = "Surface"

                surface.ShowFill = False
                surface.FillColorMode = ENColorMode.Custom

                surface.ShowFrame = True
                surface.FrameMode = ENSurfaceFrameMode.Dots
                surface.FrameColorMode = ENColorMode.Custom

                surface.VertexPrimitive = ENVertexPrimitive.LineStrip

                surface.Data.HasColors = True
                surface.Data.SetCapacity(dataPointCount)

                Dim x = 0.1
                Dim y As Double = 0
                Dim z As Double = 0
                Dim a = 10.0
                Dim b As Double = 18 + lineIndex ' 28.0 - ;
                Dim c = (lineIndex + 3) / 3.0 '8.0
                Dim t = lineIndex * (0.01 / lineCount) + 0.01

                Dim color1 = palette(lineIndex Mod palette.Length)
                Dim color2 = palette((lineIndex + 1) Mod palette.Length)
                                ''' Cannot convert UnsafeStatementSyntax, CONVERSION ERROR: Conversion for UnsafeStatement not implemented, please report this issue in 'unsafe\r\n    {\r\n     fix...' at character 8344
''' 
''' 
''' Input:
''' 
'''                 unsafe
'''                 {
'''                     fixed (byte* pData = &surface.Data.Data[0])
'''                     {
'''                         float* pVertex = (float*)pData;
'''                         uint* pColor = (uint*)(pData + surface.Data.ColorOffset * 4);
''' 
'''                         for (int dataPointIndex = 0; dataPointIndex < dataPointCount; dataPointIndex++)
'''                         {
'''                             float xt = (float)(x + t * a * (y - x));
'''                             float yt = (float)(y + t * (x * (b - z) - y));
'''                             float zt = (float)(z + t * (x * y - c * z));
''' 
'''                             pVertex[0] = xt;
'''                             pVertex[1] = yt;
'''                             pVertex[2] = zt;
''' 
'''                             Nevron.Nov.Graphics.NColor color = Nevron.Nov.Graphics.NColor.InterpolateColors(color1, color2, (float)((yt + 40.0) / 80.0));
'''                             *pColor = color.PackedARGB;
''' 
'''                             pVertex += 4;
'''                             pColor += 4;
''' 
'''                             x = xt;
'''                             y = yt;
'''                             z = zt;
'''                         }
'''                     }
'''                 }
''' 
''' 

                ' notify series that data has changed as we've modified it directly using pointers
                surface.Data.SetCount(dataPointCount)
            Next
        End Sub
        ''' 
        ''' 
        ''' 
        ''' 
        Private Sub OnNumberOfLinesUpDownValueChanged(arg As NValueChangeEventArgs)
            UpdateData()
        End Sub
        ''' 
        ''' 
        ''' 
        ''' 
        Private Sub OnDataCountPerLineComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
            UpdateData()
        End Sub
        ''' 
        ''' 
        ''' 
        ''' 
        Public Function GetExampleDescription() As String
            Return "

The example demonstrates how to use the Vertex Surface series to plot lines with large amounts of vertices, and with custom color per vertex.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Vertex Surface Series", "https://www.nevron.com/docs/openvision/vertex-surface-chart-series.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" #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_NumberOfLinesUpDown As NNumericUpDown Private m_DataCountPerLineComboBox As NComboBox Private m_Surface As NVertexSurfaceSeries Private m_Chart As NCartesianChart #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) Vertex Surface Frame Custom Colors Example for WinForms Solution