This example demonstrates how to create a chart with several XYZ scatter fast line series. The fast line series can render millions of data points in real-time.

| 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 - NFastLine3D";
// 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
///
///
///
class NLineInfo
{
///
/// Initiailizer constructor
///
///
///
public NLineInfo(NVector3DD[] controlPoints, NVector3DD[] controlPointDirections)
{
ControlPoints = controlPoints;
ControlPointDirections = controlPointDirections;
}
public NVector3DD[] ControlPoints;
public NVector3DD[] ControlPointDirections;
}
///
///
///
///
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 Line 3D";
// configure the chart
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.SoftCameraLight);
ConfigureLinearScale(chart.Axes[ENCartesianAxis.PrimaryX]);
ConfigureLinearScale(chart.Axes[ENCartesianAxis.PrimaryY]);
ConfigureLinearScale(chart.Axes[ENCartesianAxis.Depth]);
return chartViewWithCommandBars;
}
///
///
///
///
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
m_PointCountPerChannelComboBox = new NComboBox();
m_PointCountPerChannelComboBox.Items.Add(new NComboBoxItem("10000"));
m_PointCountPerChannelComboBox.Items.Add(new NComboBoxItem("20000"));
m_PointCountPerChannelComboBox.Items.Add(new NComboBoxItem("50000"));
m_PointCountPerChannelComboBox.Items.Add(new NComboBoxItem("100000"));
m_PointCountPerChannelComboBox.SelectedIndex = 0;
stack.Add(NPairBox.Create("Point Count Per Channel:", m_PointCountPerChannelComboBox));
m_SeriesCountComboBox = new NComboBox();
m_SeriesCountComboBox.Items.Add(new NComboBoxItem("10"));
m_SeriesCountComboBox.Items.Add(new NComboBoxItem("100"));
m_SeriesCountComboBox.Items.Add(new NComboBoxItem("500"));
m_SeriesCountComboBox.SelectedIndex = 0;
stack.Add(NPairBox.Create("Series Count:", m_SeriesCountComboBox));
m_EnableShaderRenderingCheckBox = new NCheckBox("Enable Shader Rendering");
m_EnableShaderRenderingCheckBox.CheckedChanged += OnEnableShaderRenderingCheckBoxCheckedChanged;
stack.Add(m_EnableShaderRenderingCheckBox);
m_StartStopTimerButton = new NButton("Stop Timer");
m_StartStopTimerButton.Click += OnStartStopTimerButtonClick;
stack.Add(m_StartStopTimerButton);
// make sure max point count is updated
m_PointCountPerChannelComboBox.SelectedIndexChanged += OnPointCountPerChannelComboBoxSelectedIndexChanged;
OnPointCountPerChannelComboBoxSelectedIndexChanged(null);
AddSeries();
return group;
}
///
///
///
///
public string GetExampleDescription()
{
return @"This example demonstrates how to create a chart with several XYZ scatter fast line series. The fast line series can render millions of data points in real-time.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Fast Line Series", "https://www.nevron.com/docs/openvision/fast-line-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
///
/// Adds series to the chart
///
private void AddSeries()
{
int seriesCount = GetSeriesCount();
NChartViewWithCommandBars chartView = (NChartViewWithCommandBars)ExampleContent;
NCartesianChart chart = (NCartesianChart)chartView.View.Surface.Charts[0];
chart.Series.Clear();
chart.Interactor = new NInteractor(new NTrackballTool());
NColor[] palette = NChartPalette.GetColors(ENChartPalette.Bright);
m_LineInfos = new NLineInfo[seriesCount];
// setup the fast line series
for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++)
{
NFastLineSeries fastLineSeries = new NFastLineSeries();
chart.Series.Add(fastLineSeries);
fastLineSeries.LegendView.Mode = ENSeriesLegendMode.None;
fastLineSeries.Name = "Fast Line Series";
fastLineSeries.Data.HasXValues = true;
fastLineSeries.Data.HasZValues = true;
fastLineSeries.Stroke = new NStroke(1, palette[seriesIndex % palette.Length]);
int controlPointCount = GetPointCount();
NVector3DD[] controlPointDirections = new NVector3DD[controlPointCount];
NVector3DD[] controlPoints = new NVector3DD[controlPointCount];
for (int i = 0, j = controlPointCount; i < j; i++)
{
controlPoints[i] = new NVector3DD(
m_Random.NextDouble() * 400 - 200,
m_Random.NextDouble() * 400 - 200,
m_Random.NextDouble() * 400 - 200
);
controlPointDirections[i] = new NVector3DD(
m_Random.NextDouble() * 1,
m_Random.NextDouble() * 1,
m_Random.NextDouble() * 1
);
}
m_LineInfos[seriesIndex] = new NLineInfo(controlPoints, controlPointDirections);
}
}
///
/// 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();
axis.ViewRangeMode = ENAxisViewRangeMode.FixedRange;
axis.MinViewRangeValue = -220;
axis.MaxViewRangeValue = 220;
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;
}
///
/// Gets the number of series in the chart
///
///
private int GetSeriesCount()
{
switch (m_SeriesCountComboBox.SelectedIndex)
{
case 0:
return 10;
case 1:
return 100;
case 2:
return 500;
}
return 0;
}
///
/// Gets the number of points in a series
///
///
private int GetPointCount()
{
switch (m_PointCountPerChannelComboBox.SelectedIndex)
{
case 0:
return 1000;
case 1:
return 5000;
case 2:
return 10000;
case 3:
return 20000;
}
return 0;
}
///
/// Adds random data to the chart
///
private void AddData()
{
int pointCount = GetPointCount();
AddSeries();
unsafe
{
NChartViewWithCommandBars chartView = (NChartViewWithCommandBars)ExampleContent;
NCartesianChart chart = (NCartesianChart)chartView.View.Surface.Charts[0];
for (int i = 0; i < chart.Series.Count; i++)
{
NFastLineSeries fastLine = chart.Series[i] as NFastLineSeries;
if (fastLine == null)
continue;
int dataItemSize = fastLine.Data.DataItemSize;
fastLine.Data.SetCount(pointCount);
fastLine.EnableShaderRendering = true;
NLineInfo lineInfo = m_LineInfos[i];
NVector3DD[] controlPointDirections = lineInfo.ControlPointDirections;
NVector3DD[] controlPoints = lineInfo.ControlPoints;
int controlPointsCount = controlPoints.Length;
for (int j = 0; j < controlPointsCount; j++)
{
controlPoints[j].X += controlPointDirections[j].X;
controlPoints[j].Y += controlPointDirections[j].Y;
controlPoints[j].Z += controlPointDirections[j].Z;
// invert x, y or z direction if points start to go out of bounds
if (controlPoints[j].X > 200)
{
controlPointDirections[j].X = -Math.Abs(controlPointDirections[j].X);
}
if (controlPoints[j].X < -200)
{
controlPointDirections[j].X = Math.Abs(controlPointDirections[j].X);
}
if (controlPoints[j].Y > 200)
{
controlPointDirections[j].Y = -Math.Abs(controlPointDirections[j].Y);
}
if (controlPoints[j].Y < -200)
{
controlPointDirections[j].Y = Math.Abs(controlPointDirections[j].Y);
}
if (controlPoints[j].Z > 200)
{
controlPointDirections[j].Z = -Math.Abs(controlPointDirections[j].Z);
}
if (controlPoints[j].Z < -200)
{
controlPointDirections[j].Z = Math.Abs(controlPointDirections[j].Z);
}
}
fixed (byte* pData = &fastLine.Data.Data[0])
{
float* pXValues = (float*)fastLine.Data.GetDataChannelPointer(ENSeriesDataChannelName.XValueF, pData);
float* pYValues = (float*)fastLine.Data.GetDataChannelPointer(ENSeriesDataChannelName.YValueF, pData);
float* pZValues = (float*)fastLine.Data.GetDataChannelPointer(ENSeriesDataChannelName.ZValueF, pData);
for (int j = 0; j < pointCount; j++)
{
NVector3DD vec = lineInfo.ControlPoints[j % controlPointsCount];
*pXValues = (float)vec.X;
*pYValues = (float)vec.Y;
*pZValues = (float)vec.Z;
pXValues += dataItemSize;
pYValues += dataItemSize;
pZValues += dataItemSize;
}
}
fastLine.Data.OnDataChanged();
}
}
}
#endregion
#region Event Handlers
///
/// Timer tick
///
private void OnTimerTick()
{
AddData();
}
///
/// Start / stop timer button
///
///
void OnStartStopTimerButtonClick(NEventArgs args)
{
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 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;
}
///
///
///
///
///
private void OnEnableShaderRenderingCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
NChartViewWithCommandBars chartView = (NChartViewWithCommandBars)ExampleContent;
NChart[] charts = chartView.View.Surface.Charts;
for (int i = 0; i < charts.Length; i++)
{
NCartesianChart chart = (NCartesianChart)charts[i];
for (int j = 0; j < chart.Series.Count; j++)
{
NFastLineSeries fastLine = chart.Series[j] as NFastLineSeries;
if (fastLine != null)
{
fastLine.EnableShaderRendering = m_EnableShaderRenderingCheckBox.Checked;
}
}
}
}
///
///
///
///
///
private void OnPointCountPerChannelComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
AddData();
}
#endregion
#region Fields
NComboBox m_PointCountPerChannelComboBox;
NComboBox m_SeriesCountComboBox;
NTimer m_Timer;
NLabel m_Title;
Random m_Random;
NLineInfo[] m_LineInfos;
NCheckBox m_EnableShaderRenderingCheckBox;
NButton m_StartStopTimerButton;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}