Vertex Surface Fill Custom Colors Example for Blazor

Vertex Surface Fill Custom Colors Example for Blazor

Nevron NOV Chart for Blazor ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All Blazor Chart examples are also available as a stand-alone Visual Studio solution in C#, which you can download from the links below.

Vertex Surface Fill Custom Colors Example for Blazor 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 Blazor
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 Blazor Solution