This example demonstrates how to configure axis ticks.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Chart;
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 - NAxisTicksExample";
// 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);
chartView.Surface.Titles[0].Text = "Axis Ticks";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
// configure axes
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
NLinearScale scaleY = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
scaleY.MinorTickCount = 1;
scaleY.InnerMinorTicks.Visible = true;
scaleY.InnerMinorTicks.Stroke = new NStroke(1, NColor.Black);
scaleY.InnerMinorTicks.Length = 5;
scaleY.OuterMinorTicks.Visible = true;
scaleY.OuterMinorTicks.Stroke = new NStroke(1, NColor.Black);
scaleY.OuterMinorTicks.Length = 5;
scaleY.InnerMajorTicks.Visible = true;
scaleY.InnerMajorTicks.Stroke = new NStroke(1, NColor.Black);
// add interlaced stripe
NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
strip.Interlaced = true;
scaleY.Strips.Add(strip);
NOrdinalScale scaleX = (NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale;
// create dummy data
NBarSeries bar = new NBarSeries();
bar.Name = "Bars";
Random random = new Random();
for (int i = 0; i < 10; i++)
{
bar.DataPoints.Add(new NBarDataPoint(random.Next(100)));
}
m_Chart.Series.Add(bar);
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
stack.Add(new NLabel("Major Outer Ticks"));
NColorBox majorOuterTickColor = new NColorBox();
majorOuterTickColor.SelectedColorChanged += OnMajorOuterTickColorSelectedColorChanged;
stack.Add(NPairBox.Create("Color", majorOuterTickColor));
majorOuterTickColor.SelectedColor = NColor.Black;
NNumericUpDown majorOuterTicksLengthNumericUpDown = new NNumericUpDown();
majorOuterTicksLengthNumericUpDown.ValueChanged += OnMajorOuterTicksLengthNumericUpDownValueChanged;
stack.Add(NPairBox.Create("Length", majorOuterTicksLengthNumericUpDown));
majorOuterTicksLengthNumericUpDown.Value = 10;
stack.Add(new NLabel("Major Inner Ticks"));
NColorBox majorInnerTickColor = new NColorBox();
majorInnerTickColor.SelectedColorChanged += OnMajorInnerTickColorSelectedColorChanged;
stack.Add(NPairBox.Create("Color", majorInnerTickColor));
majorInnerTickColor.SelectedColor = NColor.Black;
NNumericUpDown majorInnerTicksLengthNumericUpDown = new NNumericUpDown();
majorInnerTicksLengthNumericUpDown.ValueChanged += OnMajorInnerTicksLengthNumericUpDownValueChanged;
stack.Add(NPairBox.Create("Length", majorInnerTicksLengthNumericUpDown));
majorInnerTicksLengthNumericUpDown.Value = 10;
stack.Add(new NLabel("Minor Inner Ticks"));
NColorBox minorInnerTickColor = new NColorBox();
minorInnerTickColor.SelectedColorChanged += OnMinorInnerTickColorSelectedColorChanged;
stack.Add(NPairBox.Create("Color", minorInnerTickColor));
minorInnerTickColor.SelectedColor = NColor.Black;
NNumericUpDown minorInnerTicksLengthNumericUpDown = new NNumericUpDown();
minorInnerTicksLengthNumericUpDown.ValueChanged += OnMinorInnerTicksLengthNumericUpDownValueChanged;
stack.Add(NPairBox.Create("Length", minorInnerTicksLengthNumericUpDown));
minorInnerTicksLengthNumericUpDown.Value = 10;
stack.Add(new NLabel("Minor Outer Ticks"));
NColorBox minorOuterTickColor = new NColorBox();
minorOuterTickColor.SelectedColorChanged += OnMinorOuterTickColorSelectedColorChanged;
stack.Add(NPairBox.Create("Color", minorOuterTickColor));
minorOuterTickColor.SelectedColor = NColor.Black;
NNumericUpDown minorOuterTicksLengthNumericUpDown = new NNumericUpDown();
minorOuterTicksLengthNumericUpDown.ValueChanged += OnMinorOuterTicksLengthNumericUpDownValueChanged;
stack.Add(NPairBox.Create("Length", minorOuterTicksLengthNumericUpDown));
minorOuterTicksLengthNumericUpDown.Value = 10;
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to configure axis ticks.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Scale Ticks", "https://www.nevron.com/docs/openvision/scale-ticks.html"),
("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"),
("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
void OnMinorOuterTicksLengthNumericUpDownValueChanged(NValueChangeEventArgs arg)
{
((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).OuterMinorTicks.Length = ((NNumericUpDown)arg.TargetNode).Value;
}
void OnMinorInnerTicksLengthNumericUpDownValueChanged(NValueChangeEventArgs arg)
{
((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).InnerMinorTicks.Length = ((NNumericUpDown)arg.TargetNode).Value;
}
void OnMajorOuterTicksLengthNumericUpDownValueChanged(NValueChangeEventArgs arg)
{
((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).OuterMajorTicks.Length = ((NNumericUpDown)arg.TargetNode).Value;
}
void OnMajorInnerTicksLengthNumericUpDownValueChanged(NValueChangeEventArgs arg)
{
((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).InnerMajorTicks.Length = ((NNumericUpDown)arg.TargetNode).Value;
}
void OnMajorInnerTickColorSelectedColorChanged(NValueChangeEventArgs arg)
{
((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).InnerMajorTicks.Stroke = new NStroke(1, ((NColorBox)arg.TargetNode).SelectedColor);
}
void OnMinorInnerTickColorSelectedColorChanged(NValueChangeEventArgs arg)
{
((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).InnerMinorTicks.Stroke = new NStroke(1, ((NColorBox)arg.TargetNode).SelectedColor);
}
void OnMajorOuterTickColorSelectedColorChanged(NValueChangeEventArgs arg)
{
((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).OuterMajorTicks.Stroke = new NStroke(1, ((NColorBox)arg.TargetNode).SelectedColor);
}
void OnMinorOuterTickColorSelectedColorChanged(NValueChangeEventArgs arg)
{
((NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).OuterMinorTicks.Stroke = new NStroke(1, ((NColorBox)arg.TargetNode).SelectedColor);
}
#endregion
#region Fields
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.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 - NAxisTicksExample"
' 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)
chartView.Surface.Titles(0).Text = "Axis Ticks"
' configure chart
m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
' configure axes
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
Dim scaleY As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale
scaleY.MinorTickCount = 1
scaleY.InnerMinorTicks.Visible = True
scaleY.InnerMinorTicks.Stroke = New NStroke(1, NColor.Black)
scaleY.InnerMinorTicks.Length = 5
scaleY.OuterMinorTicks.Visible = True
scaleY.OuterMinorTicks.Stroke = New NStroke(1, NColor.Black)
scaleY.OuterMinorTicks.Length = 5
scaleY.InnerMajorTicks.Visible = True
scaleY.InnerMajorTicks.Stroke = New NStroke(1, NColor.Black)
' add interlaced stripe
Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
strip.Interlaced = True
scaleY.Strips.Add(strip)
Dim scaleX As NOrdinalScale = m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale
' create dummy data
Dim bar As NBarSeries = New NBarSeries()
bar.Name = "Bars"
Dim random As Random = New Random()
For i = 0 To 9
bar.DataPoints.Add(New NBarDataPoint(random.Next(100)))
Next
m_Chart.Series.Add(bar)
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 boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
stack.Add(New NLabel("Major Outer Ticks"))
Dim majorOuterTickColor As NColorBox = New NColorBox()
majorOuterTickColor.SelectedColorChanged += AddressOf OnMajorOuterTickColorSelectedColorChanged
stack.Add(NPairBox.Create("Color", majorOuterTickColor))
majorOuterTickColor.SelectedColor = NColor.Black
Dim majorOuterTicksLengthNumericUpDown As NNumericUpDown = New NNumericUpDown()
majorOuterTicksLengthNumericUpDown.ValueChanged += AddressOf OnMajorOuterTicksLengthNumericUpDownValueChanged
stack.Add(NPairBox.Create("Length", majorOuterTicksLengthNumericUpDown))
majorOuterTicksLengthNumericUpDown.Value = 10
stack.Add(New NLabel("Major Inner Ticks"))
Dim majorInnerTickColor As NColorBox = New NColorBox()
majorInnerTickColor.SelectedColorChanged += AddressOf OnMajorInnerTickColorSelectedColorChanged
stack.Add(NPairBox.Create("Color", majorInnerTickColor))
majorInnerTickColor.SelectedColor = NColor.Black
Dim majorInnerTicksLengthNumericUpDown As NNumericUpDown = New NNumericUpDown()
majorInnerTicksLengthNumericUpDown.ValueChanged += AddressOf OnMajorInnerTicksLengthNumericUpDownValueChanged
stack.Add(NPairBox.Create("Length", majorInnerTicksLengthNumericUpDown))
majorInnerTicksLengthNumericUpDown.Value = 10
stack.Add(New NLabel("Minor Inner Ticks"))
Dim minorInnerTickColor As NColorBox = New NColorBox()
minorInnerTickColor.SelectedColorChanged += AddressOf OnMinorInnerTickColorSelectedColorChanged
stack.Add(NPairBox.Create("Color", minorInnerTickColor))
minorInnerTickColor.SelectedColor = NColor.Black
Dim minorInnerTicksLengthNumericUpDown As NNumericUpDown = New NNumericUpDown()
minorInnerTicksLengthNumericUpDown.ValueChanged += AddressOf OnMinorInnerTicksLengthNumericUpDownValueChanged
stack.Add(NPairBox.Create("Length", minorInnerTicksLengthNumericUpDown))
minorInnerTicksLengthNumericUpDown.Value = 10
stack.Add(New NLabel("Minor Outer Ticks"))
Dim minorOuterTickColor As NColorBox = New NColorBox()
minorOuterTickColor.SelectedColorChanged += AddressOf OnMinorOuterTickColorSelectedColorChanged
stack.Add(NPairBox.Create("Color", minorOuterTickColor))
minorOuterTickColor.SelectedColor = NColor.Black
Dim minorOuterTicksLengthNumericUpDown As NNumericUpDown = New NNumericUpDown()
minorOuterTicksLengthNumericUpDown.ValueChanged += AddressOf OnMinorOuterTicksLengthNumericUpDownValueChanged
stack.Add(NPairBox.Create("Length", minorOuterTicksLengthNumericUpDown))
minorOuterTicksLengthNumericUpDown.Value = 10
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how to configure axis ticks.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Scale Ticks", "https://www.nevron.com/docs/openvision/scale-ticks.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnMinorOuterTicksLengthNumericUpDownValueChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale).OuterMinorTicks.Length = CType(arg.TargetNode, NNumericUpDown).Value
End Sub
Private Sub OnMinorInnerTicksLengthNumericUpDownValueChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale).InnerMinorTicks.Length = CType(arg.TargetNode, NNumericUpDown).Value
End Sub
Private Sub OnMajorOuterTicksLengthNumericUpDownValueChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale).OuterMajorTicks.Length = CType(arg.TargetNode, NNumericUpDown).Value
End Sub
Private Sub OnMajorInnerTicksLengthNumericUpDownValueChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale).InnerMajorTicks.Length = CType(arg.TargetNode, NNumericUpDown).Value
End Sub
Private Sub OnMajorInnerTickColorSelectedColorChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale).InnerMajorTicks.Stroke = New NStroke(1, CType(arg.TargetNode, NColorBox).SelectedColor)
End Sub
Private Sub OnMinorInnerTickColorSelectedColorChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale).InnerMinorTicks.Stroke = New NStroke(1, CType(arg.TargetNode, NColorBox).SelectedColor)
End Sub
Private Sub OnMajorOuterTickColorSelectedColorChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale).OuterMajorTicks.Stroke = New NStroke(1, CType(arg.TargetNode, NColorBox).SelectedColor)
End Sub
Private Sub OnMinorOuterTickColorSelectedColorChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale).OuterMinorTicks.Stroke = New NStroke(1, CType(arg.TargetNode, NColorBox).SelectedColor)
End Sub
#End Region
#Region "Fields"
Private m_Chart As NCartesianChart
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class