Vertex Surface Fill Custom Colors Example for WPF

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

Vertex Surface Fill Custom Colors Example for WPF Description

The example demonstrates how to use the Vertex surface series to plot objects with a large amount of vertices, and with a custom color per vertex.


Vertex Surface Fill Custom Colors Example

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

			// 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 Fill With Custom Colors";

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

            // setup axes
            NLinearScale scaleY = (NLinearScale)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;
            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;
            chart.Axes[ENCartesianAxis.Depth].Scale = scaleZ;

            // add the surface series
            m_Surface = new NVertexSurfaceSeries();
            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.FillColorMode = 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);

            NComboBox cubeSizeComboBox = new NComboBox();
            for (int i = 1; i < 10; i++)
            {
                cubeSizeComboBox.Items.Add(new NComboBoxItem(i.ToString() + "x" + i.ToString()));
            }

            cubeSizeComboBox.SelectedIndexChanged += OnCubeSizeComboBoxSelectedIndexChanged;
            cubeSizeComboBox.SelectedIndex = 4;
            stack.Add(NPairBox.Create("Cube Dimensions:", cubeSizeComboBox));

            return group;
        }

        private void OnCubeSizeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
        {
            int cubeSide = ((int)arg.NewValue + 1);
            int dataPointCount = 8 * (int)Math.Pow(cubeSide, 3);

            m_Surface.Data.Clear();
            m_Surface.Indices.Clear();
            m_Surface.Data.SetCapacity(dataPointCount);

            uint currentIndex = 0;

            uint[] cubeIndices = new uint[] {   // bottom
                                            0, 1, 3,
                                            0, 3, 2,

                                            // left
                                            2, 0, 4,
                                            2, 4, 6,

                                            // right
                                            1, 3, 5,
                                            3, 7, 5,

                                            // front
                                            0, 1, 4,
                                            1, 5, 4,

                                            // back
                                            2, 6, 3,
                                            3,6, 7,

                                            // top
                                            4, 5, 6,
                                            5, 7, 6 };

            // generate all vertexes and colors
            for (int x = 0; x < cubeSide; x++)
            {
                double x1 = x + 0.1;
                double x2 = x + 1 - 0.1;

                byte r1 = (byte)(x1 * 255.0 / cubeSide);
                byte r2 = (byte)(x1 * 255.0 / cubeSide);

                for (int y = 0; y < cubeSide; y++)
                {
                    double y1 = y + 0.1;
                    double y2 = y + 1 - 0.1;

                    byte g1 = (byte)(y1 * 255.0 / cubeSide);
                    byte g2 = (byte)(y1 * 255.0 / cubeSide);

                    for (int z = 0; z < cubeSide; z++)
                    {
                        double z1 = z + 0.1;
                        double z2 = z + 1 - 0.1;

                        byte b1 = (byte)(z1 * 255.0 / cubeSide);
                        byte b2 = (byte)(z1 * 255.0 / cubeSide);

                        m_Surface.Data.AddValueColor(new NVector3DD(x1, y1, z1), NColor.FromRGB(r1, g1, b1));
                        m_Surface.Data.AddValueColor(new NVector3DD(x2, y1, z1), NColor.FromRGB(r2, g1, b1));
                        m_Surface.Data.AddValueColor(new NVector3DD(x1, y2, z1), NColor.FromRGB(r1, g2, b1));
                        m_Surface.Data.AddValueColor(new NVector3DD(x2, y2, z1), NColor.FromRGB(r2, g2, b1));
                        m_Surface.Data.AddValueColor(new NVector3DD(x1, y1, z2), NColor.FromRGB(r1, g1, b2));
                        m_Surface.Data.AddValueColor(new NVector3DD(x2, y1, z2), NColor.FromRGB(r2, g1, b2));
                        m_Surface.Data.AddValueColor(new NVector3DD(x1, y2, z2), NColor.FromRGB(r1, g2, b2));
                        m_Surface.Data.AddValueColor(new NVector3DD(x2, y2, z2), NColor.FromRGB(r2, g2, b2));

                        // add indicess
                        for (int i = 0; i < cubeIndices.Length; i++)
                        {
                            m_Surface.Indices.Add(currentIndex + cubeIndices[i]);
                        }

                        currentIndex += 8;
                    }
                }
            }
        }
        /// 
        /// 
        /// 
        /// 
        public string GetExampleDescription()
        {
            return @"

The example demonstrates how to use the Vertex surface series to plot objects with a large amount of vertices, and with a 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 NVertexSurfaceSeries m_Surface; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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

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

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

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

            ' setup axes
            Dim scaleY As NLinearScale = 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
            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
            chart.Axes(ENCartesianAxis.Depth).Scale = scaleZ

            ' add the surface series
            m_Surface = New NVertexSurfaceSeries()
            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.FillColorMode = 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)

            Dim cubeSizeComboBox As NComboBox = New NComboBox()
            For i = 1 To 9
                cubeSizeComboBox.Items.Add(New NComboBoxItem(i.ToString() & "x" & i.ToString()))
            Next

            cubeSizeComboBox.SelectedIndexChanged += AddressOf OnCubeSizeComboBoxSelectedIndexChanged
            cubeSizeComboBox.SelectedIndex = 4
            stack.Add(NPairBox.Create("Cube Dimensions:", cubeSizeComboBox))

            Return group
        End Function

        Private Sub OnCubeSizeComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
            Dim cubeSide = CInt(arg.NewValue) + 1
            Dim dataPointCount = 8 * CInt(Math.Pow(cubeSide, 3))

            m_Surface.Data.Clear()
            m_Surface.Indices.Clear()
            m_Surface.Data.SetCapacity(dataPointCount)

            Dim currentIndex As UInteger = 0


            ' left

            ' right

            ' front

            ' back

            ' top
            Dim cubeIndices = New UInteger() {0, 1, 3, 0, 3, 2, 2, 0, 4, 2, 4, 6, 1, 3, 5, 3, 7, 5, 0, 1, 4, 1, 5, 4, 2, 6, 3, 3, 6, 7, 4, 5, 6, 5, 7, 6}   ' bottom

            ' generate all vertexes and colors
            For x = 0 To cubeSide - 1
                Dim x1 = x + 0.1
                Dim x2 = x + 1 - 0.1

                Dim r1 As Byte = x1 * 255.0 / cubeSide
                Dim r2 As Byte = x1 * 255.0 / cubeSide

                For y = 0 To cubeSide - 1
                    Dim y1 = y + 0.1
                    Dim y2 = y + 1 - 0.1

                    Dim g1 As Byte = y1 * 255.0 / cubeSide
                    Dim g2 As Byte = y1 * 255.0 / cubeSide

                    For z = 0 To cubeSide - 1
                        Dim z1 = z + 0.1
                        Dim z2 = z + 1 - 0.1

                        Dim b1 As Byte = z1 * 255.0 / cubeSide
                        Dim b2 As Byte = z1 * 255.0 / cubeSide

                        m_Surface.Data.AddValueColor(New NVector3DD(x1, y1, z1), NColor.FromRGB(r1, g1, b1))
                        m_Surface.Data.AddValueColor(New NVector3DD(x2, y1, z1), NColor.FromRGB(r2, g1, b1))
                        m_Surface.Data.AddValueColor(New NVector3DD(x1, y2, z1), NColor.FromRGB(r1, g2, b1))
                        m_Surface.Data.AddValueColor(New NVector3DD(x2, y2, z1), NColor.FromRGB(r2, g2, b1))
                        m_Surface.Data.AddValueColor(New NVector3DD(x1, y1, z2), NColor.FromRGB(r1, g1, b2))
                        m_Surface.Data.AddValueColor(New NVector3DD(x2, y1, z2), NColor.FromRGB(r2, g1, b2))
                        m_Surface.Data.AddValueColor(New NVector3DD(x1, y2, z2), NColor.FromRGB(r1, g2, b2))
                        m_Surface.Data.AddValueColor(New NVector3DD(x2, y2, z2), NColor.FromRGB(r2, g2, b2))

                        ' add indicess
                        For i = 0 To cubeIndices.Length - 1
                            m_Surface.Indices.Add(currentIndex + cubeIndices(i))
                        Next

                        currentIndex += 8
                    Next
                Next
            Next
        End Sub
        ''' 
        ''' 
        ''' 
        ''' 
        Public Function GetExampleDescription() As String
            Return "

The example demonstrates how to use the Vertex surface series to plot objects with a large amount of vertices, and with a 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_Surface As NVertexSurfaceSeries #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 Fill Custom Colors Example for WPF Solution