This example demonstrates the ability of the NGridSurfaceSeries to render large dynamically changing datasets with a minimal amount of CPU load. The example also shows how to efficiently fill data to the series.

| 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 - NGridSurfaceRealTimeExample";
// 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);
chartView.Registered += OnChartViewRegistered;
chartView.Unregistered += OnChartViewUnregistered;
// configure title
chartView.Surface.Titles[0].Text = "Realtime Grid Surface";
// 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.ShinyTopLeft);
chart.Interactor = new NInteractor(new NTrackballTool());
// 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 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.CellTriangulationMode = ENSurfaceCellTriangulationMode.Diagonal1;
m_Surface.Data.SetGridSize(500, 500);
SetupCommonSurfaceProperties(m_Surface);
// setup axes
chart.Axes[ENCartesianAxis.PrimaryY].ViewRangeMode = ENAxisViewRangeMode.FixedRange;
chart.Axes[ENCartesianAxis.PrimaryY].MinViewRangeValue = -3;
chart.Axes[ENCartesianAxis.PrimaryY].MaxViewRangeValue = 3;
NOrdinalScale xScale = (NOrdinalScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale;
xScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
xScale.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);
xScale.DisplayDataPointsBetweenTicks = false;
NOrdinalScale zScale = (NOrdinalScale)chart.Axes[ENCartesianAxis.Depth].Scale;
zScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
zScale.MajorGridLines.SetShowAtWall(ENChartWall.Left, true);
zScale.DisplayDataPointsBetweenTicks = false;
return chartViewWithCommandBars;
}
double phase = 0;
Random random = new Random();
private void GenerateWaves()
{
NGridSurfaceSeries surface = m_Surface;
int nCountX = surface.Data.GridSizeX;
int nCountZ = surface.Data.GridSizeZ;
double step = Math.PI * 10 / nCountX;
unsafe
{
fixed (byte* pData = &surface.Data.Data[0])
{
float* pValue = (float*)pData + 1;
int itemSize = surface.Data.DataItemSize;
double randomAmplitude = Math.Sin(phase) * 2 + random.NextDouble();
for (int z = 0; z < nCountZ; z++)
{
for (int x = 0; x < nCountX; x++)
{
float zVal = (float)(randomAmplitude * Math.Sin(phase + x * step) * Math.Cos(phase + z * step));
*pValue = zVal;
pValue += itemSize;
}
}
surface.Data.OnDataChanged();
}
}
phase += 3 * step;
}
private void SetupCommonSurfaceProperties(NGridSurfaceSeries surface)
{
surface.Palette = new NRangeMultiColorPalette();
surface.XValuesMode = ENGridSurfaceValuesMode.OriginAndStep;
surface.OriginX = -150;
surface.StepX = 10;
surface.ZValuesMode = ENGridSurfaceValuesMode.OriginAndStep;
surface.OriginZ = -150;
surface.StepZ = 10;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
NComboBox gridSizeComboBox = new NComboBox();
gridSizeComboBox.Items.Add(new NComboBoxItem("250x250"));
gridSizeComboBox.Items.Add(new NComboBoxItem("500x500"));
gridSizeComboBox.Items.Add(new NComboBoxItem("1000x1000"));
stack.Add(NPairBox.Create("Grid Size:", gridSizeComboBox));
gridSizeComboBox.SelectedIndexChanged += OnGridSizeComboBoxSelectedIndexChanged;
gridSizeComboBox.SelectedIndex = 1;
NCheckBox enableShaderRenderingCheckBox = new NCheckBox();
stack.Add(NPairBox.Create("Enable Shader Rendering:", enableShaderRenderingCheckBox));
enableShaderRenderingCheckBox.CheckedChanged += OnEnableShaderRenderingCheckBoxCheckedChanged;
NButton toggleTimerButton = new NButton("Stop Timer");
toggleTimerButton.Click += OnToggleTimerButtonClick;
toggleTimerButton.Tag = 0;
stack.Add(toggleTimerButton);
return group;
}
public string GetExampleDescription()
{
return @"This example demonstrates the ability of the NGridSurfaceSeries to render large dynamically changing datasets with a minimal amount of CPU load. The example also shows how to efficiently fill data to the 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"),
("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html"),
("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
#endregion
#region Fields
NTimer m_Timer;
NGridSurfaceSeries m_Surface;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | 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 - NGridSurfaceRealTimeExample"
' 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)
chartView.Registered += AddressOf OnChartViewRegistered
chartView.Unregistered += AddressOf OnChartViewUnregistered
' configure title
chartView.Surface.Titles(0).Text = "Realtime Grid Surface"
' 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.ShinyTopLeft)
chart.Interactor = New NInteractor(New NTrackballTool())
' 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)
' 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.CellTriangulationMode = ENSurfaceCellTriangulationMode.Diagonal1
m_Surface.Data.SetGridSize(500, 500)
SetupCommonSurfaceProperties(m_Surface)
' setup axes
chart.Axes(ENCartesianAxis.PrimaryY).ViewRangeMode = ENAxisViewRangeMode.FixedRange
chart.Axes(ENCartesianAxis.PrimaryY).MinViewRangeValue = -3
chart.Axes(ENCartesianAxis.PrimaryY).MaxViewRangeValue = 3
Dim xScale As NOrdinalScale = chart.Axes(ENCartesianAxis.PrimaryX).Scale
xScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
xScale.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)
xScale.DisplayDataPointsBetweenTicks = False
Dim zScale As NOrdinalScale = chart.Axes(ENCartesianAxis.Depth).Scale
zScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
zScale.MajorGridLines.SetShowAtWall(ENChartWall.Left, True)
zScale.DisplayDataPointsBetweenTicks = False
Return chartViewWithCommandBars
End Function
Private phase As Double = 0
Private random As Random = New Random()
Private Sub GenerateWaves()
Dim surface = m_Surface
Dim nCountX = surface.Data.GridSizeX
Dim nCountZ = surface.Data.GridSizeZ
Dim [step] = Math.PI * 10 / nCountX
''' Cannot convert UnsafeStatementSyntax, CONVERSION ERROR: Conversion for UnsafeStatement not implemented, please report this issue in 'unsafe\r\n {\r\n fixed...' at character 5217
'''
'''
''' Input:
'''
''' unsafe
''' {
''' fixed (byte* pData = &surface.Data.Data[0])
''' {
''' float* pValue = (float*)pData + 1;
''' int itemSize = surface.Data.DataItemSize;
'''
''' double randomAmplitude = System.Math.Sin(this.phase) * 2 + this.random.NextDouble();
'''
''' for (int z = 0; z < nCountZ; z++)
''' {
''' for (int x = 0; x < nCountX; x++)
''' {
''' float zVal = (float)(randomAmplitude * System.Math.Sin(this.phase + x * step) * System.Math.Cos(this.phase + z * step));
'''
''' *pValue = zVal;
'''
''' pValue += itemSize;
''' }
''' }
'''
''' surface.Data.OnDataChanged();
''' }
''' }
'''
'''
phase += 3 * [step]
End Sub
Private Sub SetupCommonSurfaceProperties(surface As NGridSurfaceSeries)
surface.Palette = New NRangeMultiColorPalette()
surface.XValuesMode = ENGridSurfaceValuesMode.OriginAndStep
surface.OriginX = -150
surface.StepX = 10
surface.ZValuesMode = ENGridSurfaceValuesMode.OriginAndStep
surface.OriginZ = -150
surface.StepZ = 10
End Sub
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim gridSizeComboBox As NComboBox = New NComboBox()
gridSizeComboBox.Items.Add(New NComboBoxItem("250x250"))
gridSizeComboBox.Items.Add(New NComboBoxItem("500x500"))
gridSizeComboBox.Items.Add(New NComboBoxItem("1000x1000"))
stack.Add(NPairBox.Create("Grid Size:", gridSizeComboBox))
gridSizeComboBox.SelectedIndexChanged += AddressOf OnGridSizeComboBoxSelectedIndexChanged
gridSizeComboBox.SelectedIndex = 1
Dim enableShaderRenderingCheckBox As NCheckBox = New NCheckBox()
stack.Add(NPairBox.Create("Enable Shader Rendering:", enableShaderRenderingCheckBox))
enableShaderRenderingCheckBox.CheckedChanged += AddressOf OnEnableShaderRenderingCheckBoxCheckedChanged
Dim toggleTimerButton As NButton = New NButton("Stop Timer")
toggleTimerButton.Click += AddressOf OnToggleTimerButtonClick
toggleTimerButton.Tag = 0
stack.Add(toggleTimerButton)
Return group
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates the ability of the NGridSurfaceSeries to render large dynamically changing datasets with a minimal amount of CPU load. The example also shows how to efficiently fill data to the 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"), ("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html"), ("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
Private m_Timer As NTimer
Private m_Surface As NGridSurfaceSeries
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class