This example demonstrates how to create a chart containing multiple fast lines series that represent data channels with random data. The fast line series can handle millions of data points in real-time without sampling.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.DataStructures;
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 - NFastLine2D";
// 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.Registered += OnChartViewRegistered;
chartView.Unregistered += OnChartViewUnregistered;
NDockPanel dockPanel = new NDockPanel();
chartView.Surface.Content = dockPanel;
m_Title = new NLabel();
m_Title.Text = "Fast Line 2D";
m_Title.Margins = new NMargins(NChartViewSurface.DefaultPanelMargin);
m_Title.Font = new NFont(NFontDescriptor.DefaultSansFamilyName, NChartViewSurface.DefaultLabelFontSize);
m_Title.TextFill = new NColorFill(NColor.Black);
m_Title.TextAlignment = ENContentAlignment.MiddleCenter;
NDockLayout.SetDockArea(m_Title, ENDockArea.Top);
dockPanel.AddChild(m_Title);
m_ChannelInfos = new NList();
// setup the fast line series
NChart[] charts = new NChart[] { CreateChart(new NChannelInfo[] { new NChannelInfo(NColor.Red, true, 50, 200, 14), new NChannelInfo(NColor.Blue, false, 100, 400, 10)}, 1),
CreateChart(new NChannelInfo[] { new NChannelInfo(NColor.Red, true, 100, 300, 13), new NChannelInfo(NColor.Blue, false, 50, 140, 15)}, 2 ),
CreateChart(new NChannelInfo[] { new NChannelInfo(NColor.Red, true, 100, 200, 17), new NChannelInfo(NColor.Blue, false, 0, 100, 8)}, 3) };
float chartPercentage = 100 / charts.Length;
float chartBegin = 0;
NStackPanel chartsPanel = new NStackPanel();
chartsPanel.Direction = ENHVDirection.TopToBottom;
chartsPanel.FillMode = ENStackFillMode.Equal;
chartsPanel.FitMode = ENStackFitMode.Equal;
NDockLayout.SetDockArea(chartsPanel, ENDockArea.Center);
chartsPanel.Margins = new NMargins(NChartViewSurface.DefaultPanelMargin);
dockPanel.AddChild(chartsPanel);
for (int i = 0; i < charts.Length; i++)
{
NChart chart = charts[i];
chartsPanel.AddChild(chart);
chart.Margins = new NMargins(NChartViewSurface.DefaultPanelMargin);
chartBegin += chartPercentage;
}
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_EnableShaderRenderingCheckBox = new NCheckBox("Enable Shader Rendering");
m_EnableShaderRenderingCheckBox.Checked = true;
m_EnableShaderRenderingCheckBox.CheckedChanged += OnEnableShaderRenderingCheckBoxCheckedChanged;
stack.Add(m_EnableShaderRenderingCheckBox);
m_UseCustomColorsCheckBox = new NCheckBox("Use Custom Colors");
m_UseCustomColorsCheckBox.CheckedChanged += OnUseCustomColorsCheckBoxCheckedChanged;
stack.Add(m_UseCustomColorsCheckBox);
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);
return group;
}
///
///
///
///
public string GetExampleDescription()
{
return @"This example demonstrates how to create a chart containing multiple fast lines series that represent data channels with random data. The fast line series can handle millions of data points in real-time without sampling.
";
}
///
/// 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"),
("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html"),
};
}
#endregion
#region Implementation
///
/// Creates a chart
///
///
///
private NCartesianChart CreateChart(NChannelInfo[] channelInfos, int signalNumber)
{
NCartesianChart chart = new NCartesianChart();
chart.FitMode = ENCartesianChartFitMode.Stretch;
// don't regard axis labels width during fitting
chart.AxisContentFitMode = ENAxisContentFitMode.LabelsHeight;
// hide the x/y axes, we're going to use custom axes
NCartesianAxis axisX = (NCartesianAxis)chart.Axes[ENCartesianAxis.PrimaryX];
ConfigureLinearScale(axisX, false);
((NNumericScale)axisX.Scale).MinTickDistance = 30;
NLinearScale scaleX = (NLinearScale)axisX.Scale;
scaleX.ViewRangeInflateMode = ENScaleViewRangeInflateMode.None;
scaleX.Title.Text = "Signal " + signalNumber.ToString();
NCartesianAxis axisY = (NCartesianAxis)chart.Axes[ENCartesianAxis.PrimaryY];
ConfigureLinearScale(axisY, true);
axisY.Scale.Title.Text = "mV";
int channelInfoInfo = m_ChannelInfos.Count;
m_ChannelInfos.AddRange(channelInfos);
for (int i = 0; i < channelInfos.Length; i++)
{
NFastLineSeries fastLine = new NFastLineSeries();
fastLine.EnableShaderRendering = true;
fastLine.DataPointOriginIndex = 0;
fastLine.Data.HasXValues = true;
// store the channel info index in the tag property
fastLine.Tag = channelInfoInfo++;
chart.Series.Add(fastLine);
}
return chart;
}
///
/// Applies a linear scale and an interlaced stripe at the specified axis
///
///
///
private void ConfigureLinearScale(NCartesianAxis axis, bool vertical)
{
// add interlaced stripe to the Y axis
NLinearScale scale = new NLinearScale();
if (vertical)
{
scale.MinTickDistance = 25;
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);
}
else
{
// increase the distance between ticks for horizontal axes
scale.MinTickDistance = 40;
}
// remove label staggering
scale.Labels.OverlapResolveLayouts = new NDomArray(new ENLevelLabelsLayout[] { ENLevelLabelsLayout.RemoveOverlap });
axis.Scale = scale;
}
#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;
}
///
///
///
///
///
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 OnUseCustomColorsCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
ResetData();
}
///
///
///
private void OnTimerTick()
{
AddData();
}
///
///
///
///
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 EnableShaderRenderingCheck_CheckedChanged(object sender, EventArgs e)
{
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)
{
switch (m_PointCountPerChannelComboBox.SelectedIndex)
{
case 0:
m_MaxPointCount = 10000;
break;
case 1:
m_MaxPointCount = 20000;
break;
case 2:
m_MaxPointCount = 50000;
break;
case 3:
m_MaxPointCount = 100000;
break;
default:
m_MaxPointCount = 0;
break;
}
ResetData();
// m_Title.Text = "Fast Line 2D\r\n Showing Realtime Rendering of " + (m_MaxPointCount * 6).ToString("#,##0", CultureInfo.InvariantCulture) + " Data Points in 6 Channels";
}
#endregion
#region Fields
public readonly bool AddRandom;
public readonly float MinValue;
public readonly float MaxValue;
public float Phase;
public readonly NColor MinColor;
public readonly NColor MaxColor;
public int CurrentPointIndex;
public int CurrentXValue;
public readonly int CycleCount;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}