This example demonstrates how to create a XYZ scatter point chart rendering millions of data points in real-time using the NFastPointSeries.

| 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 - NFastPoint3D";
// 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;
m_Title = chartView.Surface.Titles[0];
m_Title.Text = "Fast Point 3D";
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
chart.Enable3D = true;
chart.ModelWidth = 50;
chart.ModelHeight = 50;
chart.ModelDepth = 50;
chart.Projection.SetPredefinedProjection(ENPredefinedProjection.Perspective1);
chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft);
ConfigureLinearScale(chart.Axes[ENCartesianAxis.PrimaryX]);
ConfigureLinearScale(chart.Axes[ENCartesianAxis.PrimaryY]);
ConfigureLinearScale(chart.Axes[ENCartesianAxis.Depth]);
// setup the fast point series
m_FastPointSeries = new NFastPointSeries();
chart.Series.Add(m_FastPointSeries);
m_FastPointSeries.Name = "FastPoint Series";
m_FastPointSeries.FillColorMode = ENColorMode.Custom;
chart.Interactor = new NInteractor(new NTrackballTool());
// init the random colors array
m_RandomColors = new uint[10000];
Random random = new Random();
for (int i = 0; i < m_RandomColors.Length; i++)
{
uint red = (uint)(255 * random.NextDouble());
uint green = (uint)(255 * random.NextDouble());
uint blue = (uint)(255 * random.NextDouble());
m_RandomColors[i] = (uint)(0xFF000000 | (red << 16) | (green << 8) | blue);
}
return chartViewWithCommandBars;
}
///
///
///
///
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
m_PointCountComboBox = new NComboBox();
m_PointCountComboBox.Items.Fill(new string[] { "100K", "500K", "1M", "2M", "10M"});
m_PointCountComboBox.SelectedIndexChanged += OnPointCountComboBoxSelectedIndexChanged;
m_PointCountComboBox.SelectedIndex = 2;
stack.Add(NPairBox.Create("Point Count:", m_PointCountComboBox));
m_PointSizeNumericUpDown = new NNumericUpDown();
m_PointSizeNumericUpDown.Value = 2;
m_PointSizeNumericUpDown.Minimum = 1;
m_PointSizeNumericUpDown.Maximum = 20;
m_PointSizeNumericUpDown.ValueChanged += OnPointSizeNumericUpDownValueChanged;
stack.Add(NPairBox.Create("Point Size:", m_PointSizeNumericUpDown));
m_EnableShaderRenderingCheckBox = new NCheckBox();
m_EnableShaderRenderingCheckBox.CheckedChanged += OnEnableShaderRenderingCheckBoxChanged;
m_EnableShaderRenderingCheckBox.Checked = m_FastPointSeries.EnableShaderRendering;
stack.Add(NPairBox.Create("Enable Shader Rendering:", m_EnableShaderRenderingCheckBox));
m_StartStopTimerButton = new NButton("Stop Timer");
m_StartStopTimerButton.Click += OnStartStopTimerButtonClick;
stack.Add(m_StartStopTimerButton);
AddData();
return group;
}
///
///
///
///
public string GetExampleDescription()
{
return @"This example demonstrates how to create a XYZ scatter point chart rendering millions of data points in real-time using the NFastPointSeries.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Fast Point Series", "https://www.nevron.com/docs/openvision/fast-point-chart-series.html"),
("Fast Series Overview", "https://www.nevron.com/docs/openvision/fast-chart-series-overview.html"),
("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"),
("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"),
("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html"),
};
}
#endregion
#region Implementation
///
/// Applies a linear scale and an interlaced stripe at the specified axis
///
///
private void ConfigureLinearScale(NCartesianAxis axis)
{
// add interlaced stripe to the Y axis
NLinearScale scale = new NLinearScale();
NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
stripStyle.SetShowAtWall(ENChartWall.Left, true);
stripStyle.SetShowAtWall(ENChartWall.Back, true);
stripStyle.SetShowAtWall(ENChartWall.Right, true);
stripStyle.SetShowAtWall(ENChartWall.Front, true);
stripStyle.SetShowAtWall(ENChartWall.Bottom, true);
stripStyle.SetShowAtWall(ENChartWall.Top, true);
stripStyle.Interlaced = true;
scale.Strips.Add(stripStyle);
axis.Scale = scale;
axis.Visible = true;
}
#endregion
#region Event Handlers
///
///
///
///
private void OnChartViewRegistered(NEventArgs arg)
{
m_Timer = new NTimer();
m_Timer.Tick += OnTimerTick;
m_Timer.Start();
}
///
///
///
///
private void OnChartViewUnregistered(NEventArgs arg)
{
m_Timer.Stop();
m_Timer.Tick -= OnTimerTick;
m_Timer = null;
}
///
///
///
///
void OnStartStopTimerButtonClick(NEventArgs arg)
{
AddData();
if (m_Timer.IsStarted)
{
m_Timer.Stop();
m_StartStopTimerButton.Content = new NLabel("Start Timer");
}
else
{
m_Timer.Start();
m_StartStopTimerButton.Content = new NLabel("Stop Timer");
}
}
///
///
///
private void OnTimerTick()
{
// spin the points
unsafe
{
fixed (byte* pData = &m_FastPointSeries.Data.Data[0])
{
int count = m_FastPointSeries.Data.Count;
int dataItemSize = m_FastPointSeries.Data.DataItemSize;
float* pXValues = (float*)m_FastPointSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.XValueF, pData);
float* pYValues = (float*)m_FastPointSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.YValueF, pData);
float* pZValues = (float*)m_FastPointSeries.Data.GetDataChannelPointer(ENSeriesDataChannelName.ZValueF, pData);
NVector4DF[] spinSpeeds = m_SpinSpeeds;
// modify the data
for (int i = 0; i < count; i++)
{
NVector3DF v;
v.X = *pXValues;
v.Y = *pYValues;
v.Z = *pZValues;
NVector4DF q = spinSpeeds[i];
float ix = q.W * v.X + q.Y * v.Z - q.Z * v.Y;
float iy = q.W * v.Y + q.Z * v.X - q.X * v.Z;
float iz = q.W * v.Z + q.X * v.Y - q.Y * v.X;
float iw = -q.X * v.X - q.Y * v.Y - q.Z * v.Z;
*pXValues = ix * q.W + iw * -q.X + iy * -q.Z - iz * -q.Y;
*pYValues = iy * q.W + iw * -q.Y + iz * -q.X - ix * -q.Z;
*pZValues = iz * q.W + iw * -q.Z + ix * -q.Y - iy * -q.X;
pXValues += dataItemSize;
pYValues += dataItemSize;
pZValues += dataItemSize;
}
m_FastPointSeries.Data.OnDataChanged();
}
}
}
///
///
///
///
private void OnPointSizeNumericUpDownValueChanged(NValueChangeEventArgs arg)
{
m_FastPointSeries.Size = (float)m_PointSizeNumericUpDown.Value;
}
///
///
///
///
private void OnPointCountComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
AddData();
}
///
///
///
///
private void OnEnableShaderRenderingCheckBoxChanged(NValueChangeEventArgs arg)
{
m_FastPointSeries.EnableShaderRendering = m_EnableShaderRenderingCheckBox.Checked;
}
#endregion
#region Fields
NFastPointSeries m_FastPointSeries;
NLabel m_Title;
NTimer m_Timer;
NComboBox m_PointCountComboBox;
NNumericUpDown m_PointSizeNumericUpDown;
NCheckBox m_EnableShaderRenderingCheckBox;
NButton m_StartStopTimerButton;
Random m_Random = new Random();
NVector4DF[] m_SpinSpeeds;
uint[] m_RandomColors;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}