Mesh Surface 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.

Mesh Surface Example for Blazor Description

This example demonstrates how to create a scatter funnel chart.


Mesh Surface Example

C# Mesh Surface Example Code for Nevron Chart for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Chart.Tools;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Presentation;
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 - NMeshSurfaceExample";

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

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

            NLinearScale scale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;
            scale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;

            // setup axes
            NLinearScale scaleX = new NLinearScale();
            chart.Axes[ENCartesianAxis.PrimaryX].Scale = scaleX;
            scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
            scaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);

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

            // 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);

            // add the surface series
            m_Surface = new NMeshSurfaceSeries();
            chart.Series.Add(m_Surface);

            m_Surface.Name = "Surface";
            m_Surface.LegendView.Mode = ENSeriesLegendMode.SeriesLogic;
            m_Surface.FillColorMode = ENColorMode.Zone;
            m_Surface.FlatPositionValue = 0.5;
            m_Surface.Data.SetGridSize(20, 20);
            m_Surface.Fill = new NColorFill(NColor.YellowGreen);

            FillData(m_Surface);

            return chartViewWithCommandBars;
        }

        private void FillData(NMeshSurfaceSeries surface)
        {
            double x, y, z;
            int nCountX = surface.Data.GridSizeX;
            int nCountZ = surface.Data.GridSizeZ;

            for (int j = 0; j < nCountZ; j++)
            {
                for (int i = 0; i < nCountX; i++)
                {
                    x = 2 + i + Math.Sin(j / 4.0) * 2;
                    z = 1 + j + Math.Cos(i / 4.0);

                    y = Math.Sin(i / 3.0) * Math.Sin(j / 3.0);

                    if (y < 0)
                    {
                        y = Math.Abs(y / 2.0);
                    }

                    surface.Data.SetValue(i, j, y, x, z);
                }
            }
        }

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

            m_ShowFillCheckBox = new NCheckBox("Show Fill");
            m_ShowFillCheckBox.CheckedChanged += OnShowFillCheckBoxCheckedChanged;
            stack.Add(m_ShowFillCheckBox);

            m_FillModeCombo = new NComboBox();
			m_FillModeCombo.Items.FillFromEnum();
            m_FillModeCombo.SelectedIndexChanged += OnFillModeComboSelectedIndexChanged;
            m_FillModeCombo.SelectedIndex = (int)m_Surface.FillColorMode;
            stack.Add(NPairBox.Create("Fill Mode:", m_FillModeCombo));

            m_ShowFrameCheckBox = new NCheckBox("Show Frame");
            m_ShowFrameCheckBox.CheckedChanged += OnShowFrameCheckBoxCheckedChanged;
            stack.Add(m_ShowFrameCheckBox);

            m_FrameModeCombo = new NComboBox();
			m_FrameModeCombo.Items.FillFromEnum();
            m_FrameModeCombo.SelectedIndexChanged += OnFrameModeComboSelectedIndexChanged;
            m_FrameModeCombo.SelectedIndex = (int)m_Surface.FrameMode;
            stack.Add(NPairBox.Create("Frame Mode:", m_FrameModeCombo));

            m_FrameColorModeCombo = new NComboBox();
            m_FrameColorModeCombo.Items.FillFromEnum();
            m_FrameColorModeCombo.SelectedIndexChanged += OnFrameColorModeComboSelectedIndexChanged;
            m_FrameColorModeCombo.SelectedIndex = (int)m_Surface.FrameColorMode;
            stack.Add(NPairBox.Create("Frame Color Mode:", m_FrameColorModeCombo));

            m_SmoothShadingCheckBox = new NCheckBox("Smooth Shading");
            m_SmoothShadingCheckBox.CheckedChanged += OnSmoothShadingCheckBoxCheckedChanged;
            m_SmoothShadingCheckBox.Checked = false;
            m_SmoothShadingCheckBox.HorizontalPlacement = Layout.ENHorizontalPlacement.Left;
            stack.Add(m_SmoothShadingCheckBox);

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

            m_EnableShaderRenderingCheckBox = new NCheckBox("Enable Shader Rendering");
            m_EnableShaderRenderingCheckBox.CheckedChanged += OnEnableShaderRenderingCheckBoxCheckedChanged;
            m_EnableShaderRenderingCheckBox.Checked = false;
            m_EnableShaderRenderingCheckBox.HorizontalPlacement = Layout.ENHorizontalPlacement.Left;
            stack.Add(m_EnableShaderRenderingCheckBox);

            m_DrawFlatCheckBox = new NCheckBox("Draw Flat");
            m_DrawFlatCheckBox.CheckedChanged += OnDrawFlatCheckBoxCheckedChanged;
            m_DrawFlatCheckBox.Checked = false;
            m_DrawFlatCheckBox.HorizontalPlacement = Layout.ENHorizontalPlacement.Left;
            stack.Add(m_DrawFlatCheckBox);

            m_ShowFillCheckBox.Checked = true;
            m_ShowFrameCheckBox.Checked = true;

            return group;
		}

        private void OnSmoothPaletteCheckBoxCheckedChanged(NValueChangeEventArgs arg)
        {
            m_Surface.Palette.InterpolateColors = (bool)arg.NewValue;
        }

        private void OnShowFrameCheckBoxCheckedChanged(NValueChangeEventArgs arg)
        {
            m_Surface.ShowFrame = (bool)arg.NewValue;
            m_FrameModeCombo.Enabled = m_Surface.ShowFrame;
            m_FrameColorModeCombo.Enabled = m_Surface.ShowFrame;
        }

        private void OnEnableShaderRenderingCheckBoxCheckedChanged(NValueChangeEventArgs arg)
        {
            m_Surface.EnableShaderRendering = (bool)arg.NewValue;
        }

        private void OnShowFillCheckBoxCheckedChanged(NValueChangeEventArgs arg)
        {
            m_Surface.ShowFill = (bool)arg.NewValue;
            m_FillModeCombo.Enabled = m_Surface.ShowFill;
        }

        private void OnDrawFlatCheckBoxCheckedChanged(NValueChangeEventArgs arg)
        {
            m_Surface.DrawFlat = (bool)arg.NewValue;
        }

        private void OnFrameColorModeComboSelectedIndexChanged(NValueChangeEventArgs arg)
        {
            m_Surface.FrameColorMode = (ENColorMode)arg.NewValue;
        }

        private void OnSmoothShadingCheckBoxCheckedChanged(NValueChangeEventArgs arg)
        {
            m_Surface.ShadingMode = (bool)arg.NewValue ? ENShadingMode.Smooth : ENShadingMode.Flat;
        }

        private void OnFrameModeComboSelectedIndexChanged(NValueChangeEventArgs arg)
        {
            m_Surface.FrameMode = (ENSurfaceFrameMode)arg.NewValue;
        }

        private void OnFillModeComboSelectedIndexChanged(NValueChangeEventArgs arg)
        {
            m_Surface.FillColorMode = (ENColorMode)arg.NewValue;
        }

        public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create a scatter funnel chart.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Mesh Surface Series", "https://www.nevron.com/docs/openvision/mesh-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"), ("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields NMeshSurfaceSeries m_Surface; NCheckBox m_ShowFillCheckBox; NComboBox m_FillModeCombo; NCheckBox m_ShowFrameCheckBox; NComboBox m_FrameModeCombo; NComboBox m_FrameColorModeCombo; NCheckBox m_SmoothShadingCheckBox; NCheckBox m_SmoothPaletteCheckBox; NCheckBox m_EnableShaderRenderingCheckBox; NCheckBox m_DrawFlatCheckBox; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Mesh Surface Example for Blazor Solution