This example demonstrates how to create a XY scatter point 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 - NXYZScatterPointExample";
// 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 Point";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
m_Chart.Enable3D = true;
m_Chart.FitMode = ENCartesianChartFitMode.Aspect;
m_Chart.ModelWidth = m_Chart.ModelHeight = m_Chart.ModelHeight = 50;
m_Chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted);
m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.NorthernLights);
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYZLinear);
m_Chart.Interactor = new NInteractor(new NTrackballTool());
// setup X axis
{
NLinearScale linearScaleX = new NLinearScale();
m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = linearScaleX;
linearScaleX.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
linearScaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);
linearScaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
}
// setup Y axis
{
NLinearScale linearScaleY = new NLinearScale();
m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale = linearScaleY;
linearScaleY.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
linearScaleY.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);
linearScaleY.MajorGridLines.SetShowAtWall(ENChartWall.Left, true);
NScaleStrip m_Strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
m_Strip.Interlaced = true;
linearScaleY.Strips.Add(m_Strip);
}
// setup Z axis
{
NLinearScale linearScaleZ = new NLinearScale();
m_Chart.Axes[ENCartesianAxis.Depth].Scale = linearScaleZ;
linearScaleZ.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
linearScaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
linearScaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Left, true);
}
// add a point series
m_Point = new NPointSeries();
m_Point.Name = "Point Series";
m_Point.DataLabelStyle = new NDataLabelStyle(false);
m_Point.Fill = new NColorFill(new NColor(NColor.DarkOrange, 160));
m_Point.Size = 20;
m_Point.Shape = ENPointShape3D.Sphere;
m_Point.UseXValues = true;
m_Point.UseZValues = true;
m_Point.ValueFormatter = new NNumericValueFormatter(ENNumericValueFormat.LimitedPrecision2);
m_Chart.Series.Add(m_Point);
OnNewDataButtonClick(null);
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.DataPoints));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
NCheckBox inflateMarginsCheckBox = new NCheckBox();
inflateMarginsCheckBox.CheckedChanged += OnInflateMarginsCheckBoxCheckedChanged;
stack.Add(NPairBox.Create("Inflate Margins: ", inflateMarginsCheckBox));
NCheckBox verticalAxisRoundToTick = new NCheckBox();
verticalAxisRoundToTick.CheckedChanged += OnAxesRoundToTickCheckedChanged;
stack.Add(NPairBox.Create("Axes Round To Tick: ", verticalAxisRoundToTick));
verticalAxisRoundToTick.Checked = true;
NCheckBox showDataLabels = new NCheckBox("Show Data Labels");
showDataLabels.CheckedChanged += OnShowDataLabelsCheckedChanged;
showDataLabels.Checked = false;
stack.Add(showDataLabels);
NButton newDataButton = new NButton("New Data");
newDataButton.Click += OnNewDataButtonClick;
stack.Add(newDataButton);
return group;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to create a XY scatter point chart.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Point Series", "https://www.nevron.com/docs/openvision/point-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 OnShowDataLabelsCheckedChanged(NValueChangeEventArgs arg)
{
if ((arg.TargetNode as NCheckBox).Checked)
{
m_Point.DataLabelStyle = new NDataLabelStyle(true);
m_Point.DataLabelStyle.Format = "";
}
else
{
m_Point.DataLabelStyle = new NDataLabelStyle(false);
}
}
void OnNewDataButtonClick(NEventArgs arg)
{
m_Point.DataPoints.Clear();
NDataPointCollection dataPoints = m_Point.DataPoints;
Random random = new Random();
for (int i = 0; i < 10; i++)
{
double u1 = random.NextDouble();
double u2 = random.NextDouble();
double u3 = random.NextDouble();
if (u1 == 0)
u1 += 0.0001;
if(u2 == 0)
u2 += 0.0001;
double z0 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2);
double z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2);
double z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u3);
dataPoints.Add(new NPointDataPoint(z0, z1, z2));
}
}
void OnAxesRoundToTickCheckedChanged(NValueChangeEventArgs arg)
{
for (int i = 0; i < m_Chart.Axes.Count; i++)
{
NLinearScale linearScale = m_Chart.Axes[i].Scale as NLinearScale;
if (linearScale != null)
{
if ((arg.TargetNode as NCheckBox).Checked)
{
linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.MajorTick;
linearScale.InflateViewRangeBegin = true;
linearScale.InflateViewRangeEnd = true;
}
else
{
linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.Logical;
}
}
}
}
void OnInflateMarginsCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
m_Point.InflateMargins = (arg.TargetNode as NCheckBox).Checked;
}
#endregion
#region Fields
NPointSeries m_Point;
NCartesianChart m_Chart;
#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.Forms
Imports System
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NXYZScatterPointExample"
' 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)
host.Dock = DockStyle.Fill
Controls.Add(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 Point"
' configure chart
m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
m_Chart.Enable3D = True
m_Chart.FitMode = ENCartesianChartFitMode.Aspect
m_Chart.ModelWidth = CSharpImpl.__Assign(m_Chart.ModelHeight, CSharpImpl.__Assign(m_Chart.ModelHeight, 50))
m_Chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)
m_Chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.NorthernLights)
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYZLinear)
m_Chart.Interactor = New NInteractor(New NTrackballTool())
' setup X axis
If True Then
Dim linearScaleX As NLinearScale = New NLinearScale()
m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale = linearScaleX
linearScaleX.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot
linearScaleX.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)
linearScaleX.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
End If
' setup Y axis
If True Then
Dim linearScaleY As NLinearScale = New NLinearScale()
m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale = linearScaleY
linearScaleY.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot
linearScaleY.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)
linearScaleY.MajorGridLines.SetShowAtWall(ENChartWall.Left, True)
Dim m_Strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
m_Strip.Interlaced = True
linearScaleY.Strips.Add(m_Strip)
End If
' setup Z axis
If True Then
Dim linearScaleZ As NLinearScale = New NLinearScale()
m_Chart.Axes(ENCartesianAxis.Depth).Scale = linearScaleZ
linearScaleZ.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot
linearScaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
linearScaleZ.MajorGridLines.SetShowAtWall(ENChartWall.Left, True)
End If
' add a point series
m_Point = New NPointSeries()
m_Point.Name = "Point Series"
m_Point.DataLabelStyle = New NDataLabelStyle(False)
m_Point.Fill = New NColorFill(New NColor(NColor.DarkOrange, 160))
m_Point.Size = 20
m_Point.Shape = ENPointShape3D.Sphere
m_Point.UseXValues = True
m_Point.UseZValues = True
m_Point.ValueFormatter = New NNumericValueFormatter(ENNumericValueFormat.LimitedPrecision2)
m_Chart.Series.Add(m_Point)
OnNewDataButtonClick(Nothing)
chartView.Document.StyleSheets.ApplyTheme(New NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.DataPoints))
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim inflateMarginsCheckBox As NCheckBox = New NCheckBox()
inflateMarginsCheckBox.CheckedChanged += AddressOf OnInflateMarginsCheckBoxCheckedChanged
stack.Add(NPairBox.Create("Inflate Margins: ", inflateMarginsCheckBox))
Dim verticalAxisRoundToTick As NCheckBox = New NCheckBox()
verticalAxisRoundToTick.CheckedChanged += AddressOf OnAxesRoundToTickCheckedChanged
stack.Add(NPairBox.Create("Axes Round To Tick: ", verticalAxisRoundToTick))
verticalAxisRoundToTick.Checked = True
Dim showDataLabels As NCheckBox = New NCheckBox("Show Data Labels")
showDataLabels.CheckedChanged += AddressOf OnShowDataLabelsCheckedChanged
showDataLabels.Checked = False
stack.Add(showDataLabels)
Dim newDataButton As NButton = New NButton("New Data")
newDataButton.Click += AddressOf OnNewDataButtonClick
stack.Add(newDataButton)
Return group
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how to create a XY scatter point chart.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Point Series", "https://www.nevron.com/docs/openvision/point-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 OnShowDataLabelsCheckedChanged(arg As NValueChangeEventArgs)
If TryCast(arg.TargetNode, NCheckBox).Checked Then
m_Point.DataLabelStyle = New NDataLabelStyle(True)
m_Point.DataLabelStyle.Format = ""
Else
m_Point.DataLabelStyle = New NDataLabelStyle(False)
End If
End Sub
Private Sub OnNewDataButtonClick(arg As NEventArgs)
m_Point.DataPoints.Clear()
Dim dataPoints = m_Point.DataPoints
Dim random As Random = New Random()
For i = 0 To 9
Dim u1 As Double = random.NextDouble()
Dim u2 As Double = random.NextDouble()
Dim u3 As Double = random.NextDouble()
If u1 = 0 Then u1 += 0.0001
If u2 = 0 Then u2 += 0.0001
Dim z0 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Cos(2 * Math.PI * u2)
Dim z1 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u2)
Dim z2 = Math.Sqrt(-2 * Math.Log(u1)) * Math.Sin(2 * Math.PI * u3)
dataPoints.Add(New NPointDataPoint(z0, z1, z2))
Next
End Sub
Private Sub OnAxesRoundToTickCheckedChanged(arg As NValueChangeEventArgs)
For i = 0 To m_Chart.Axes.Count - 1
Dim linearScale As NLinearScale = TryCast(m_Chart.Axes(i).Scale, NLinearScale)
If linearScale IsNot Nothing Then
If TryCast(arg.TargetNode, NCheckBox).Checked Then
linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.MajorTick
linearScale.InflateViewRangeBegin = True
linearScale.InflateViewRangeEnd = True
Else
linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.Logical
End If
End If
Next
End Sub
Private Sub OnInflateMarginsCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
m_Point.InflateMargins = TryCast(arg.TargetNode, NCheckBox).Checked
End Sub
#End Region
#Region "Fields"
Private m_Point As NPointSeries
Private m_Chart As NCartesianChart
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class