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
}
}