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