This example demonstrates how to use the axis cursors tool.

| 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 - NAxisCursorToolExample";
// 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 = "Axis Cursor Tool";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);
// setup X axis
NLinearScale scaleX = new NLinearScale();
scaleX.MajorGridLines = new NScaleGridLines();
scaleX.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = scaleX;
// setup Y axis
NLinearScale scaleY = new NLinearScale();
scaleY.MajorGridLines = new NScaleGridLines();
scaleY.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
// add interlaced stripe for Y axis
NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
strip.Interlaced = true;
scaleY.Strips.Add(strip);
m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale = scaleY;
// 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 = 5;
m_Point.Shape = ENPointShape3D.Bar;
m_Point.UseXValues = true;
m_Chart.Series.Add(m_Point);
// add some sample data
NDataPointCollection dataPoints = m_Point.DataPoints;
Random random = new Random();
for (int i = 0; i < 1000; i++)
{
double u1 = random.NextDouble();
double u2 = 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);
dataPoints.Add(new NPointDataPoint(z0, z1));
}
m_Chart.Enabled = true;
NInteractor interactor = new NInteractor();
m_AxisCursorsTool = new NAxisCursorTool();
m_AxisCursorsTool.Enabled = true;
m_AxisCursorsTool.HorizontalValueChanged += OnAxisCursorsToolHorizontalValueChanged;
m_AxisCursorsTool.VerticalValueChanged += OnAxisCursorsToolVerticalValueChanged;
interactor.Add(m_AxisCursorsTool);
m_Chart.Interactor = interactor;
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
NComboBox orientationComboBox = new NComboBox();
orientationComboBox.Items.FillFromEnum();
orientationComboBox.SelectedIndex = (int)m_Chart.Orientation;
orientationComboBox.SelectedIndexChanged += OnOrientationComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Orientation:", orientationComboBox));
NCheckBox snapToMajorTicksCheckBox = new NCheckBox("Snap To Major Ticks");
snapToMajorTicksCheckBox.CheckedChanged += OnSnapToMajorTicksCheckBoxCheckedChanged;
stack.Add(snapToMajorTicksCheckBox);
NCheckBox autoHideCheckBox = new NCheckBox("Auto Hide");
autoHideCheckBox.CheckedChanged += OnAutoHideCheckBoxCheckedChanged;
stack.Add(autoHideCheckBox);
NCheckBox invertScaleCheckBox = new NCheckBox("Invert Scale");
invertScaleCheckBox.CheckedChanged += OnInvertScaleCheckBoxCheckedChanged;
stack.Add(invertScaleCheckBox);
m_HorizontalValueLabel = new NLabel();
stack.Add(NPairBox.Create("Horizontal Value:", m_HorizontalValueLabel));
m_VerticalValueLabel = new NLabel();
stack.Add(NPairBox.Create("Vertical Value:", m_VerticalValueLabel));
return group;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to use the axis cursors tool.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Axis Cursors", "https://www.nevron.com/docs/openvision/chart-interactivity-axis-cursors.html"),
("Tooltips and Cursors", "https://www.nevron.com/docs/openvision/chart-interactvity-tooltips-and-cursors.html"),
("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
void OnAutoHideCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
}
///
///
///
///
void OnSnapToMajorTicksCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
if (((NCheckBox)arg.TargetNode).Checked)
{
m_AxisCursorsTool.HorizontalValueSnapper = new NAxisMajorTickSnapper();
m_AxisCursorsTool.VerticalValueSnapper = new NAxisMajorTickSnapper();
}
else
{
m_AxisCursorsTool.HorizontalValueSnapper = null;
m_AxisCursorsTool.VerticalValueSnapper = null;
}
}
void OnInvertScaleCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
for (int i = 0; i < m_Chart.Axes.Count; i++)
{
m_Chart.Axes[i].Scale.Invert = ((NCheckBox)arg.TargetNode).Checked;
}
}
void OnOrientationComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
m_Chart.Orientation = (ENCartesianChartOrientation)((NComboBox)arg.TargetNode).SelectedIndex;
}
void OnAxisCursorsToolVerticalValueChanged(NValueChangeEventArgs arg)
{
NAxisCursorTool tool = (NAxisCursorTool)arg.TargetNode;
if (double.IsNaN(tool.VerticalValue))
{
m_VerticalValueLabel.Text = string.Empty;
}
else
{
m_VerticalValueLabel.Text = tool.VerticalValue.ToString();
}
}
void OnAxisCursorsToolHorizontalValueChanged(NValueChangeEventArgs arg)
{
NAxisCursorTool tool = (NAxisCursorTool)arg.TargetNode;
if (double.IsNaN(tool.HorizontalValue))
{
m_HorizontalValueLabel.Text = string.Empty;
}
else
{
m_HorizontalValueLabel.Text = tool.HorizontalValue.ToString();
}
}
#endregion
#region Fields
NPointSeries m_Point;
NCartesianChart m_Chart;
NAxisCursorTool m_AxisCursorsTool;
NLabel m_HorizontalValueLabel;
NLabel m_VerticalValueLabel;
#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 - NAxisCursorToolExample"
' 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 = "Axis Cursor Tool"
' configure chart
m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear)
' setup X axis
Dim scaleX As NLinearScale = New NLinearScale()
scaleX.MajorGridLines = New NScaleGridLines()
scaleX.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot
m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale = scaleX
' setup Y axis
Dim scaleY As NLinearScale = New NLinearScale()
scaleY.MajorGridLines = New NScaleGridLines()
scaleY.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dot
' add interlaced stripe for Y axis
Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
strip.Interlaced = True
scaleY.Strips.Add(strip)
m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale = scaleY
' 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 = 5
m_Point.Shape = ENPointShape3D.Bar
m_Point.UseXValues = True
m_Chart.Series.Add(m_Point)
' add some sample data
Dim dataPoints = m_Point.DataPoints
Dim random As Random = New Random()
For i = 0 To 999
Dim u1 As Double = random.NextDouble()
Dim u2 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)
dataPoints.Add(New NPointDataPoint(z0, z1))
Next
m_Chart.Enabled = True
Dim interactor As NInteractor = New NInteractor()
m_AxisCursorsTool = New NAxisCursorTool()
m_AxisCursorsTool.Enabled = True
Me.m_AxisCursorsTool.HorizontalValueChanged += AddressOf OnAxisCursorsToolHorizontalValueChanged
Me.m_AxisCursorsTool.VerticalValueChanged += AddressOf OnAxisCursorsToolVerticalValueChanged
interactor.Add(m_AxisCursorsTool)
m_Chart.Interactor = interactor
chartView.Document.StyleSheets.ApplyTheme(New NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series))
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim orientationComboBox As NComboBox = New NComboBox()
orientationComboBox.Items.FillFromEnum(Of ENCartesianChartOrientation)()
orientationComboBox.SelectedIndex = m_Chart.Orientation
orientationComboBox.SelectedIndexChanged += AddressOf OnOrientationComboBoxSelectedIndexChanged
stack.Add(NPairBox.Create("Orientation:", orientationComboBox))
Dim snapToMajorTicksCheckBox As NCheckBox = New NCheckBox("Snap To Major Ticks")
snapToMajorTicksCheckBox.CheckedChanged += AddressOf OnSnapToMajorTicksCheckBoxCheckedChanged
stack.Add(snapToMajorTicksCheckBox)
Dim autoHideCheckBox As NCheckBox = New NCheckBox("Auto Hide")
autoHideCheckBox.CheckedChanged += AddressOf OnAutoHideCheckBoxCheckedChanged
stack.Add(autoHideCheckBox)
Dim invertScaleCheckBox As NCheckBox = New NCheckBox("Invert Scale")
invertScaleCheckBox.CheckedChanged += AddressOf OnInvertScaleCheckBoxCheckedChanged
stack.Add(invertScaleCheckBox)
m_HorizontalValueLabel = New NLabel()
stack.Add(NPairBox.Create("Horizontal Value:", m_HorizontalValueLabel))
m_VerticalValueLabel = New NLabel()
stack.Add(NPairBox.Create("Vertical Value:", m_VerticalValueLabel))
Return group
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how to use the axis cursors tool.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Axis Cursors", "https://www.nevron.com/docs/openvision/chart-interactivity-axis-cursors.html"), ("Tooltips and Cursors", "https://www.nevron.com/docs/openvision/chart-interactvity-tooltips-and-cursors.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnAutoHideCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
End Sub
'''
'''
'''
'''
Private Sub OnSnapToMajorTicksCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
If CType(arg.TargetNode, NCheckBox).Checked Then
m_AxisCursorsTool.HorizontalValueSnapper = New NAxisMajorTickSnapper()
m_AxisCursorsTool.VerticalValueSnapper = New NAxisMajorTickSnapper()
Else
m_AxisCursorsTool.HorizontalValueSnapper = Nothing
m_AxisCursorsTool.VerticalValueSnapper = Nothing
End If
End Sub
Private Sub OnInvertScaleCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
For i = 0 To m_Chart.Axes.Count - 1
m_Chart.Axes(i).Scale.Invert = CType(arg.TargetNode, NCheckBox).Checked
Next
End Sub
Private Sub OnOrientationComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
m_Chart.Orientation = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENCartesianChartOrientation)
End Sub
Private Sub OnAxisCursorsToolVerticalValueChanged(arg As NValueChangeEventArgs)
Dim tool = CType(arg.TargetNode, NAxisCursorTool)
If Double.IsNaN(tool.VerticalValue) Then
m_VerticalValueLabel.Text = String.Empty
Else
m_VerticalValueLabel.Text = tool.VerticalValue.ToString()
End If
End Sub
Private Sub OnAxisCursorsToolHorizontalValueChanged(arg As NValueChangeEventArgs)
Dim tool = CType(arg.TargetNode, NAxisCursorTool)
If Double.IsNaN(tool.HorizontalValue) Then
m_HorizontalValueLabel.Text = String.Empty
Else
m_HorizontalValueLabel.Text = tool.HorizontalValue.ToString()
End If
End Sub
#End Region
#Region "Fields"
Private m_Point As NPointSeries
Private m_Chart As NCartesianChart
Private m_AxisCursorsTool As NAxisCursorTool
Private m_HorizontalValueLabel As NLabel
Private m_VerticalValueLabel As NLabel
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class