This example demonstrates how to create a XY scatter line chart.

| 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 - NXYZScatterLineExample";
// 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);
// configure title
chartView.Surface.Titles[0].Text = "XYZ Scatter Line";
// configure chart
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
chart.Enable3D = true;
chart.ModelWidth = 50;
chart.ModelHeight = 50;
chart.ModelDepth = 50;
chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYZLinear);
chart.FitMode = ENCartesianChartFitMode.Aspect;
chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted);
chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft);
chart.Interactor = new NInteractor(new NTrackballTool());
// add interlaced stripe to the Y axis
NScaleStrip stripStyle = new NScaleStrip(new NColorFill(ENNamedColor.Beige), null, true, 0, 0, 1, 1);
stripStyle.Interlaced = true;
chart.Axes[ENCartesianAxis.PrimaryY].Scale.Strips.Add(stripStyle);
m_Line = new NLineSeries();
m_Line.UseXValues = true;
m_Line.UseZValues = true;
chart.Series.Add(m_Line);
m_Line.DataLabelStyle = new NDataLabelStyle(false);
m_Line.InflateMargins = true;
m_Line.Name = "Line Series";
m_Line.UseXValues = true;
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
///
/// Called when windings / complexity changes
///
private void ChangeData()
{
// add xy values
float fSpringHeight = 20;
int nWindings = (int)m_WindingsNumericUpDown.Value;
int nComplexity = (int)m_ComplexityNumericUpDown.Value;
double dCurrentAngle = 0;
double dCurrentHeight = 0;
double dX, dY, dZ;
float fHeightStep = fSpringHeight / (nWindings * nComplexity);
float fAngleStepRad = (float)(((360 / nComplexity) * 3.1415926535f) / 180.0f);
m_Line.DataPoints.Clear();
while (nWindings > 0)
{
for (int i = 0; i < nComplexity; i++)
{
dZ = Math.Cos(dCurrentAngle) * (dCurrentHeight);
dX = Math.Sin(dCurrentAngle) * (dCurrentHeight);
dY = dCurrentHeight;
m_Line.DataPoints.Add(new NLineDataPoint(dX, dY, dZ));
dCurrentAngle += fAngleStepRad;
dCurrentHeight += fHeightStep;
}
nWindings--;
}
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
m_WindingsNumericUpDown = new NNumericUpDown();
m_WindingsNumericUpDown.ValueChanged += OnWindingsUpDownValueChanged;
stack.Add(NPairBox.Create("Windings:", m_WindingsNumericUpDown));
m_ComplexityNumericUpDown = new NNumericUpDown();
m_ComplexityNumericUpDown.ValueChanged += OnComplexityUpDownValueChanged;
stack.Add(NPairBox.Create("Complexity:", m_ComplexityNumericUpDown));
m_ComplexityNumericUpDown.Value = 20;
m_WindingsNumericUpDown.Value = 5;
return group;
}
private void OnComplexityUpDownValueChanged(NValueChangeEventArgs arg)
{
ChangeData();
}
private void OnWindingsUpDownValueChanged(NValueChangeEventArgs arg)
{
ChangeData();
}
public string GetExampleDescription()
{
return @"This example demonstrates how to create a XY scatter line chart.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Line Series", "https://www.nevron.com/docs/openvision/line-chart-series.html"),
("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"),
("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"),
("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"),
("Linear Scale", "https://www.nevron.com/docs/openvision/linear-scale.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
void OnChangeXValuesButtonClick(NEventArgs arg)
{
Random random = new Random();
m_Line.DataPoints[0].X = random.Next(10);
for (int i = 1; i < m_Line.DataPoints.Count; i++)
{
m_Line.DataPoints[i].X = m_Line.DataPoints[i - 1].X + random.Next(1, 10);
}
}
#endregion
#region Fields
NNumericUpDown m_WindingsNumericUpDown;
NNumericUpDown m_ComplexityNumericUpDown;
NLineSeries m_Line;
#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 - NXYZScatterLineExample"
' 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)
' configure title
chartView.Surface.Titles(0).Text = "XYZ Scatter Line"
' configure chart
Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)
chart.Enable3D = True
chart.ModelWidth = 50
chart.ModelHeight = 50
chart.ModelDepth = 50
chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYZLinear)
chart.FitMode = ENCartesianChartFitMode.Aspect
chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)
chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.GlitterLeft)
chart.Interactor = New NInteractor(New NTrackballTool())
' add interlaced stripe to the Y axis
Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(ENNamedColor.Beige), Nothing, True, 0, 0, 1, 1)
stripStyle.Interlaced = True
chart.Axes(ENCartesianAxis.PrimaryY).Scale.Strips.Add(stripStyle)
m_Line = New NLineSeries()
m_Line.UseXValues = True
m_Line.UseZValues = True
chart.Series.Add(m_Line)
m_Line.DataLabelStyle = New NDataLabelStyle(False)
m_Line.InflateMargins = True
m_Line.Name = "Line Series"
m_Line.UseXValues = True
chartView.Document.StyleSheets.ApplyTheme(New NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series))
Return chartViewWithCommandBars
End Function
'''
''' Called when windings / complexity changes
'''
Private Sub ChangeData()
' add xy values
Dim fSpringHeight As Single = 20
Dim nWindings As Integer = m_WindingsNumericUpDown.Value
Dim nComplexity As Integer = m_ComplexityNumericUpDown.Value
Dim dCurrentAngle As Double = 0
Dim dCurrentHeight As Double = 0
Dim dX, dY, dZ As Double
Dim fHeightStep = fSpringHeight / (nWindings * nComplexity)
Dim fAngleStepRad As Single = 360 / nComplexity * 3.1415926535F / 180.0F
m_Line.DataPoints.Clear()
While nWindings > 0
For i = 0 To nComplexity - 1
dZ = Math.Cos(dCurrentAngle) * dCurrentHeight
dX = Math.Sin(dCurrentAngle) * dCurrentHeight
dY = dCurrentHeight
m_Line.DataPoints.Add(New NLineDataPoint(dX, dY, dZ))
dCurrentAngle += fAngleStepRad
dCurrentHeight += fHeightStep
Next
nWindings -= 1
End While
End Sub
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
m_WindingsNumericUpDown = New NNumericUpDown()
Me.m_WindingsNumericUpDown.ValueChanged += AddressOf OnWindingsUpDownValueChanged
stack.Add(NPairBox.Create("Windings:", m_WindingsNumericUpDown))
m_ComplexityNumericUpDown = New NNumericUpDown()
Me.m_ComplexityNumericUpDown.ValueChanged += AddressOf OnComplexityUpDownValueChanged
stack.Add(NPairBox.Create("Complexity:", m_ComplexityNumericUpDown))
m_ComplexityNumericUpDown.Value = 20
m_WindingsNumericUpDown.Value = 5
Return group
End Function
Private Sub OnComplexityUpDownValueChanged(arg As NValueChangeEventArgs)
ChangeData()
End Sub
Private Sub OnWindingsUpDownValueChanged(arg As NValueChangeEventArgs)
ChangeData()
End Sub
Public Function GetExampleDescription() As String
Return "This example demonstrates how to create a XY scatter line chart.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Line Series", "https://www.nevron.com/docs/openvision/line-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), ("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Linear Scale", "https://www.nevron.com/docs/openvision/linear-scale.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnChangeXValuesButtonClick(arg As NEventArgs)
Dim random As Random = New Random()
m_Line.DataPoints(0).X = random.Next(10)
For i = 1 To m_Line.DataPoints.Count - 1
m_Line.DataPoints(i).X = m_Line.DataPoints(i - 1).X + random.Next(1, 10)
Next
End Sub
#End Region
#Region "Fields"
Private m_WindingsNumericUpDown As NNumericUpDown
Private m_ComplexityNumericUpDown As NNumericUpDown
Private m_Line As NLineSeries
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class