This example demonstrates how to create a XY 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 - NFastPoint2D";
// 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 2D";
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
ConfigureLinearScale(chart.Axes[ENCartesianAxis.PrimaryX]);
ConfigureLinearScale(chart.Axes[ENCartesianAxis.PrimaryY]);
// setup the fast point series
m_FastPointSeries = new NFastPointSeries();
chart.Series.Add(m_FastPointSeries);
m_FastPointSeries.FillColorMode = ENColorMode.Custom;
m_FastPointSeries.Name = "FastPoint Series";
// enable zooming and scrolling
NInteractor interactor = new NInteractor();
interactor.Add(new NRectangleZoomTool());
NDataPanTool dataPanTool = new NDataPanTool();
dataPanTool.StartMouseButtonEvent = ENMouseButtonEvent.RightButtonDown;
dataPanTool.EndMouseButtonEvent = ENMouseButtonEvent.RightButtonUp;
interactor.Add(dataPanTool);
chart.Interactor = interactor;
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 XY 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"),
("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);
NVector2DF[] driftSpeeds = m_DriftSpeeds;
// modify the data
for (int i = 0; i < count; i++)
{
NVector2DF v;
v.X = *pXValues + driftSpeeds[i].X;
v.Y = *pYValues + driftSpeeds[i].Y;
if ((v.X * v.X + v.Y * v.Y) > 1)
{
// When outside the sphere, change to a random velocity,
// and multiply the point by 0.9997 to move it back
// towards the inside of the sphere. Using a value
// close to 1 allows the sphere to get a little
// fuzzy.
m_DriftSpeeds[i] = GetRandomVelocity();
v.X *= 0.9997f;
v.Y *= 0.9997f;
}
else if (m_Random.Next() < 0.001)
{
// change to a new random velocity, with a small probability
m_DriftSpeeds[i] = GetRandomVelocity();
}
*pXValues = v.X;
*pYValues = v.Y;
pXValues += dataItemSize;
pYValues += 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();
NVector2DF[] m_DriftSpeeds;
#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.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 - NFastPoint2D"
' 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)
chartView.Registered += AddressOf OnChartViewRegistered
chartView.Unregistered += AddressOf OnChartViewUnregistered
m_Title = chartView.Surface.Titles(0)
m_Title.Text = "Fast Point 2D"
Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)
Me.ConfigureLinearScale(chart.Axes(ENCartesianAxis.PrimaryX))
Me.ConfigureLinearScale(chart.Axes(ENCartesianAxis.PrimaryY))
' setup the fast point series
m_FastPointSeries = New NFastPointSeries()
chart.Series.Add(m_FastPointSeries)
m_FastPointSeries.FillColorMode = ENColorMode.Custom
m_FastPointSeries.Name = "FastPoint Series"
' enable zooming and scrolling
Dim interactor As NInteractor = New NInteractor()
interactor.Add(New NRectangleZoomTool())
Dim dataPanTool As NDataPanTool = New NDataPanTool()
dataPanTool.StartMouseButtonEvent = ENMouseButtonEvent.RightButtonDown
dataPanTool.EndMouseButtonEvent = ENMouseButtonEvent.RightButtonUp
interactor.Add(dataPanTool)
chart.Interactor = interactor
Return chartViewWithCommandBars
End Function
'''
'''
'''
'''
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
m_PointCountComboBox = New NComboBox()
m_PointCountComboBox.Items.Fill(New String() {"100K", "500K", "1M", "2M", "10M"})
Me.m_PointCountComboBox.SelectedIndexChanged += AddressOf 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
Me.m_PointSizeNumericUpDown.ValueChanged += AddressOf OnPointSizeNumericUpDownValueChanged
stack.Add(NPairBox.Create("Point Size:", m_PointSizeNumericUpDown))
m_EnableShaderRenderingCheckBox = New NCheckBox()
Me.m_EnableShaderRenderingCheckBox.CheckedChanged += AddressOf OnEnableShaderRenderingCheckBoxChanged
m_EnableShaderRenderingCheckBox.Checked = m_FastPointSeries.EnableShaderRendering
stack.Add(NPairBox.Create("Enable Shader Rendering:", m_EnableShaderRenderingCheckBox))
m_StartStopTimerButton = New NButton("Stop Timer")
Me.m_StartStopTimerButton.Click += AddressOf OnStartStopTimerButtonClick
stack.Add(m_StartStopTimerButton)
AddData()
Return group
End Function
'''
'''
'''
'''
Public Function GetExampleDescription() As String
Return "This example demonstrates how to create a XY scatter point chart rendering millions of data points in real-time using the NFastPointSeries.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("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"), ("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html")}
End Function
#End Region
#Region "Implementation"
'''
''' Applies a linear scale and an interlaced stripe at the specified axis
'''
'''
Private Sub ConfigureLinearScale(axis As NCartesianAxis)
' add interlaced stripe to the Y axis
Dim scale As NLinearScale = New NLinearScale()
Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, 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
End Sub
#End Region
#Region "Event Handlers"
'''
'''
'''
'''
Private Sub OnChartViewRegistered(arg As NEventArgs)
m_Timer = New NTimer()
Me.m_Timer.Tick += AddressOf OnTimerTick
m_Timer.Start()
End Sub
'''
'''
'''
'''
Private Sub OnChartViewUnregistered(arg As NEventArgs)
m_Timer.Stop()
Me.m_Timer.Tick -= AddressOf OnTimerTick
m_Timer = Nothing
End Sub
'''
'''
'''
'''
Private Sub OnStartStopTimerButtonClick(arg As NEventArgs)
AddData()
If m_Timer.IsStarted Then
m_Timer.Stop()
m_StartStopTimerButton.Content = New NLabel("Start Timer")
Else
m_Timer.Start()
m_StartStopTimerButton.Content = New NLabel("Stop Timer")
End If
End Sub
'''
'''
'''
' spin the points
' modify the data
' When outside the sphere, change to a random velocity,
' and multiply the point by 0.9997 to move it back
' towards the inside of the sphere. Using a value
' close to 1 allows the sphere to get a little
' fuzzy.
' change to a new random velocity, with a small probability
Private Sub OnTimerTick()
''' Cannot convert UnsafeStatementSyntax, CONVERSION ERROR: Conversion for UnsafeStatement not implemented, please report this issue in 'unsafe\r\n {\r\n fixed...' at character 8393
'''
'''
''' Input:
''' // spin the points
''' unsafe
''' {
''' fixed (byte* pData = &this.m_FastPointSeries.Data.Data[0])
''' {
''' int count = this.m_FastPointSeries.Data.Count;
''' int dataItemSize = this.m_FastPointSeries.Data.DataItemSize;
'''
''' float* pXValues = (float*)this.m_FastPointSeries.Data.GetDataChannelPointer(Nevron.Nov.Chart.ENSeriesDataChannelName.XValueF, pData);
''' float* pYValues = (float*)this.m_FastPointSeries.Data.GetDataChannelPointer(Nevron.Nov.Chart.ENSeriesDataChannelName.YValueF, pData);
''' Nevron.Nov.Graphics.NVector2DF[] driftSpeeds = this.m_DriftSpeeds;
'''
''' // modify the data
''' for (int i = 0; i < count; i++)
''' {
''' Nevron.Nov.Graphics.NVector2DF v;
'''
''' v.X = *pXValues + driftSpeeds[(System.Int32)(i)].X;
''' v.Y = *pYValues + driftSpeeds[(System.Int32)(i)].Y;
'''
''' if ((v.X * v.X + v.Y * v.Y) > 1)
''' {
''' // When outside the sphere, change to a random velocity,
''' // and multiply the point by 0.9997 to move it back
''' // towards the inside of the sphere. Using a value
''' // close to 1 allows the sphere to get a little
''' // fuzzy.
''' this.m_DriftSpeeds[i] = this.GetRandomVelocity();
''' v.X *= 0.9997f;
''' v.Y *= 0.9997f;
''' }
''' else if (this.m_Random.Next() < 0.001)
''' {
''' // change to a new random velocity, with a small probability
''' this.m_DriftSpeeds[i] = this.GetRandomVelocity();
''' }
'''
''' *pXValues = v.X;
''' *pYValues = v.Y;
'''
''' pXValues += dataItemSize;
''' pYValues += dataItemSize;
''' }
'''
''' this.m_FastPointSeries.Data.OnDataChanged();
''' }
''' }
'''
'''
End Sub
'''
'''
'''
'''
Private Sub OnPointSizeNumericUpDownValueChanged(arg As NValueChangeEventArgs)
m_FastPointSeries.Size = CSng(m_PointSizeNumericUpDown.Value)
End Sub
'''
'''
'''
'''
Private Sub OnPointCountComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
AddData()
End Sub
'''
'''
'''
'''
Private Sub OnEnableShaderRenderingCheckBoxChanged(arg As NValueChangeEventArgs)
m_FastPointSeries.EnableShaderRendering = m_EnableShaderRenderingCheckBox.Checked
End Sub
#End Region
#Region "Fields"
Private m_FastPointSeries As NFastPointSeries
Private m_Title As NLabel
Private m_Timer As NTimer
Private m_PointCountComboBox As NComboBox
Private m_PointSizeNumericUpDown As NNumericUpDown
Private m_EnableShaderRenderingCheckBox As NCheckBox
Private m_StartStopTimerButton As NButton
Private m_Random As Random = New Random()
Private m_DriftSpeeds As NVector2DF()
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class