This example demonstrates how to change the orientation of axis labels.

| 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.Windows.Forms;
namespace NovWinFormsProject
{
public partial class Form1 : Form
{
#region Constructors
public Form1()
{
InitializeComponent();
// Set form title
Text = "NOV WinForms - NAxisLabelsOrientationtExample";
// 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();
m_ChartView = chartViewWithCommandBars.View;
m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);
// configure title
m_ChartView.Surface.Titles[0].Text = "Axis Labels Orientation";
// configure chart
m_Chart = (NCartesianChart)m_ChartView.Surface.Charts[0];
NLinearScale scaleY = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
strip.Interlaced = true;
scaleY.Strips.Add(strip);
for (int i = 0; i < m_Chart.Axes.Count; i++)
{
// configure the axes
NCartesianAxis axis = m_Chart.Axes[i];
// set the visibility mode to always visible
axis.VisibilityMode = ENAxisVisibilityMode.Visible;
// set the range to [0, 100]
axis.ViewRangeMode = ENAxisViewRangeMode.FixedRange;
axis.MinViewRangeValue = 0;
axis.MaxViewRangeValue = 100;
// skip depth axes
NLinearScale linearScale = new NLinearScale();
axis.Scale = linearScale;
string title = string.Empty;
switch (i)
{
case 0:
title = "Primary X";
break;
case 1:
title = "Primary Y";
break;
case 2:
title = "Secondary X";
break;
case 3:
title = "Secondary Y";
break;
case 4:
title = "Depth";
break;
}
linearScale.Title.Text = title;
linearScale.MinTickDistance = 30;
linearScale.Labels.Style.Angle = new NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0, false);
linearScale.Labels.Style.AlwaysInsideScale = true;
linearScale.Labels.OverlapResolveLayouts = new NDomArray(new ENLevelLabelsLayout[] { ENLevelLabelsLayout.Stagger2 } );
}
m_ChartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = 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));
m_AngleModeComboBox = new NComboBox();
m_AngleModeComboBox.Items.FillFromEnum();
m_AngleModeComboBox.SelectedIndex = (int)ENScaleLabelAngleMode.Scale;
m_AngleModeComboBox.SelectedIndexChanged += OnAxisLabelChanged;
stack.Add(NPairBox.Create("Angle Mode:", m_AngleModeComboBox));
m_CustomAngleNumericUpDown = new NNumericUpDown();
m_CustomAngleNumericUpDown.Minimum = 0;
m_CustomAngleNumericUpDown.Maximum = 360;
m_CustomAngleNumericUpDown.Value = 0;
m_CustomAngleNumericUpDown.ValueChanged += OnAxisLabelChanged;
stack.Add(NPairBox.Create("Custom Angle:", m_CustomAngleNumericUpDown));
m_AllowLabelsToFlipCheckBox = new NCheckBox("Allow Label To Flip");
m_AllowLabelsToFlipCheckBox.Checked = false;
m_AllowLabelsToFlipCheckBox.CheckedChanged += OnAxisLabelChanged;
stack.Add(m_AllowLabelsToFlipCheckBox);
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to change the orientation of axis labels.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Scale Labels Layout", "https://www.nevron.com/docs/openvision/scale-labels-layout.html"),
("Scale Common Label Settings", "https://www.nevron.com/docs/openvision/scale-label-settings.html"),
("Scale Range Label Settings", "https://www.nevron.com/docs/openvision/scale-range-label-settings.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
void OnOrientationComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
m_Chart.Orientation = (ENCartesianChartOrientation)((NComboBox)arg.TargetNode).SelectedIndex;
}
void OnAxisLabelChanged(NValueChangeEventArgs arg)
{
NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0];
for (int i = 0; i < chart.Axes.Count; i++)
{
// configure the axes
NLinearScale scale = (NLinearScale)chart.Axes[i].Scale;
scale.Labels.Style.Angle = new NScaleLabelAngle((ENScaleLabelAngleMode)m_AngleModeComboBox.SelectedIndex, (float)m_CustomAngleNumericUpDown.Value, m_AllowLabelsToFlipCheckBox.Checked);
}
}
#endregion
#region Fields
private NChartView m_ChartView;
NCartesianChart m_Chart;
NComboBox m_AngleModeComboBox;
NNumericUpDown m_CustomAngleNumericUpDown;
NCheckBox m_AllowLabelsToFlipCheckBox;
#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.Wpf
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 - NAxisLabelsOrientationtExample"
' 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()
m_ChartView = chartViewWithCommandBars.View
m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)
' configure title
m_ChartView.Surface.Titles(0).Text = "Axis Labels Orientation"
' configure chart
m_Chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart)
Dim scaleY As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale
Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
strip.Interlaced = True
scaleY.Strips.Add(strip)
For i = 0 To m_Chart.Axes.Count - 1
' configure the axes
Dim axis = m_Chart.Axes(i)
' set the visibility mode to always visible
axis.VisibilityMode = ENAxisVisibilityMode.Visible
' set the range to [0, 100]
axis.ViewRangeMode = ENAxisViewRangeMode.FixedRange
axis.MinViewRangeValue = 0
axis.MaxViewRangeValue = 100
' skip depth axes
Dim linearScale As NLinearScale = New NLinearScale()
axis.Scale = linearScale
Dim title = String.Empty
Select Case i
Case 0
title = "Primary X"
Case 1
title = "Primary Y"
Case 2
title = "Secondary X"
Case 3
title = "Secondary Y"
Case 4
title = "Depth"
End Select
linearScale.Title.Text = title
linearScale.MinTickDistance = 30
linearScale.Labels.Style.Angle = New NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0, False)
linearScale.Labels.Style.AlwaysInsideScale = True
linearScale.Labels.OverlapResolveLayouts = New NDomArray(Of ENLevelLabelsLayout)(New ENLevelLabelsLayout() {ENLevelLabelsLayout.Stagger2})
Next
m_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)
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))
m_AngleModeComboBox = New NComboBox()
m_AngleModeComboBox.Items.FillFromEnum(Of ENScaleLabelAngleMode)()
m_AngleModeComboBox.SelectedIndex = CInt(ENScaleLabelAngleMode.Scale)
Me.m_AngleModeComboBox.SelectedIndexChanged += AddressOf OnAxisLabelChanged
stack.Add(NPairBox.Create("Angle Mode:", m_AngleModeComboBox))
m_CustomAngleNumericUpDown = New NNumericUpDown()
m_CustomAngleNumericUpDown.Minimum = 0
m_CustomAngleNumericUpDown.Maximum = 360
m_CustomAngleNumericUpDown.Value = 0
Me.m_CustomAngleNumericUpDown.ValueChanged += AddressOf OnAxisLabelChanged
stack.Add(NPairBox.Create("Custom Angle:", m_CustomAngleNumericUpDown))
m_AllowLabelsToFlipCheckBox = New NCheckBox("Allow Label To Flip")
m_AllowLabelsToFlipCheckBox.Checked = False
Me.m_AllowLabelsToFlipCheckBox.CheckedChanged += AddressOf OnAxisLabelChanged
stack.Add(m_AllowLabelsToFlipCheckBox)
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how to change the orientation of axis labels.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Scale Labels Layout", "https://www.nevron.com/docs/openvision/scale-labels-layout.html"), ("Scale Common Label Settings", "https://www.nevron.com/docs/openvision/scale-label-settings.html"), ("Scale Range Label Settings", "https://www.nevron.com/docs/openvision/scale-range-label-settings.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnOrientationComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
m_Chart.Orientation = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENCartesianChartOrientation)
End Sub
Private Sub OnAxisLabelChanged(arg As NValueChangeEventArgs)
Dim chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart)
For i = 0 To chart.Axes.Count - 1
' configure the axes
Dim scale = CType(chart.Axes(i).Scale, NLinearScale)
scale.Labels.Style.Angle = New NScaleLabelAngle(m_AngleModeComboBox.SelectedIndex, m_CustomAngleNumericUpDown.Value, m_AllowLabelsToFlipCheckBox.Checked)
Next
End Sub
#End Region
#Region "Fields"
Private m_ChartView As NChartView
Private m_Chart As NCartesianChart
Private m_AngleModeComboBox As NComboBox
Private m_CustomAngleNumericUpDown As NNumericUpDown
Private m_AllowLabelsToFlipCheckBox As NCheckBox
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class