This example demonstrates how to create an ordinal scale.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.DataStructures;
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 - NOrdinalScaleExample";
// 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 = "Ordinal Scale";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
// configure axes
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
m_Chart.SetPredefinedInteractor(ENPredefinedInteractor.DataZoomingAndScrolling);
// add interlaced stripe to the Y axis
NLinearScale linearScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
NScaleStrip stripStyle = new NScaleStrip();
stripStyle.Fill = new NColorFill(NColor.Beige);
stripStyle.Interlaced = true;
linearScale.Strips.Add(stripStyle);
// add some series
int dataItemsCount = 6;
NBarSeries bar = new NBarSeries();
bar.InflateMargins = true;
bar.DataLabelStyle = new NDataLabelStyle(false);
Random random = new Random();
for (int i = 0; i < dataItemsCount; i++)
{
bar.DataPoints.Add(new NBarDataPoint(random.Next(10, 30)));
}
m_Chart.Series.Add(bar);
NOrdinalScale ordinalScale = (NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale;
ordinalScale.Labels.OverlapResolveLayouts = new NDomArray(new ENLevelLabelsLayout[] { ENLevelLabelsLayout.AutoScale });
NList labels = new NList();
for (int j = 0; j < dataItemsCount; j++)
{
labels.Add("Category " + j.ToString());
}
ordinalScale.Labels.TextProvider = new NOrdinalScaleLabelTextProvider(labels);
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
NCheckBox displayDataPointsBetweenTicksCheckBox = new NCheckBox("Display Data Points Between Ticks");
displayDataPointsBetweenTicksCheckBox.CheckedChanged += OnDisplayDataPointsBetweenTicksCheckBoxCheckedChanged;
displayDataPointsBetweenTicksCheckBox.Checked = true;
stack.Add(displayDataPointsBetweenTicksCheckBox);
NCheckBox autoLabelsCheckBox = new NCheckBox("Auto Labels");
autoLabelsCheckBox.CheckedChanged += OnAutoLabelsCheckBoxCheckedChanged;
autoLabelsCheckBox.Checked = true;
stack.Add(autoLabelsCheckBox);
NCheckBox invertedCheckBox = new NCheckBox("Inverted");
invertedCheckBox.CheckedChanged += OnInvertedCheckBoxCheckedChanged;
invertedCheckBox.Checked = false;
stack.Add(invertedCheckBox);
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to create an ordinal scale.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"),
("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
void OnAutoLabelsCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
if (((NCheckBox)arg.TargetNode).Checked)
{
((NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).Labels.TextProvider = new NFormattedScaleLabelTextProvider(new NNumericValueFormatter());
}
else
{
NList labels = new NList();
int dataPointCount = ((NBarSeries)m_Chart.Series[0]).DataPoints.Count;
for (int j = 0; j < dataPointCount; j++)
{
labels.Add("Category " + j.ToString());
}
((NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).Labels.TextProvider = new NOrdinalScaleLabelTextProvider(labels);
}
}
void OnDisplayDataPointsBetweenTicksCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
((NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).DisplayDataPointsBetweenTicks = ((NCheckBox)arg.TargetNode).Checked;
}
void OnInvertedCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
((NOrdinalScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).Invert = ((NCheckBox)arg.TargetNode).Checked;
}
#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.DataStructures
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 - NOrdinalScaleExample"
' 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 = "Ordinal Scale"
' configure chart
m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
' configure axes
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
m_Chart.SetPredefinedInteractor(ENPredefinedInteractor.DataZoomingAndScrolling)
' add interlaced stripe to the Y axis
Dim linearScale As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale
Dim stripStyle As NScaleStrip = New NScaleStrip()
stripStyle.Fill = New NColorFill(NColor.Beige)
stripStyle.Interlaced = True
linearScale.Strips.Add(stripStyle)
' add some series
Dim dataItemsCount = 6
Dim bar As NBarSeries = New NBarSeries()
bar.InflateMargins = True
bar.DataLabelStyle = New NDataLabelStyle(False)
Dim random As Random = New Random()
For i = 0 To dataItemsCount - 1
bar.DataPoints.Add(New NBarDataPoint(random.Next(10, 30)))
Next
m_Chart.Series.Add(bar)
Dim ordinalScale As NOrdinalScale = m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale
ordinalScale.Labels.OverlapResolveLayouts = New NDomArray(Of ENLevelLabelsLayout)(New ENLevelLabelsLayout() {ENLevelLabelsLayout.AutoScale})
Dim labels As NList(Of String) = New NList(Of String)()
For j = 0 To dataItemsCount - 1
labels.Add("Category " & j.ToString())
Next
ordinalScale.Labels.TextProvider = New NOrdinalScaleLabelTextProvider(labels)
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 displayDataPointsBetweenTicksCheckBox As NCheckBox = New NCheckBox("Display Data Points Between Ticks")
displayDataPointsBetweenTicksCheckBox.CheckedChanged += AddressOf OnDisplayDataPointsBetweenTicksCheckBoxCheckedChanged
displayDataPointsBetweenTicksCheckBox.Checked = True
stack.Add(displayDataPointsBetweenTicksCheckBox)
Dim autoLabelsCheckBox As NCheckBox = New NCheckBox("Auto Labels")
autoLabelsCheckBox.CheckedChanged += AddressOf OnAutoLabelsCheckBoxCheckedChanged
autoLabelsCheckBox.Checked = True
stack.Add(autoLabelsCheckBox)
Dim invertedCheckBox As NCheckBox = New NCheckBox("Inverted")
invertedCheckBox.CheckedChanged += AddressOf OnInvertedCheckBoxCheckedChanged
invertedCheckBox.Checked = False
stack.Add(invertedCheckBox)
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how to create an ordinal scale.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnAutoLabelsCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
If CType(arg.TargetNode, NCheckBox).Checked Then
CType(m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale, NOrdinalScale).Labels.TextProvider = New NFormattedScaleLabelTextProvider(New NNumericValueFormatter())
Else
Dim labels As NList(Of String) = New NList(Of String)()
Dim dataPointCount = CType(m_Chart.Series(0), NBarSeries).DataPoints.Count
For j = 0 To dataPointCount - 1
labels.Add("Category " & j.ToString())
Next
CType(m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale, NOrdinalScale).Labels.TextProvider = New NOrdinalScaleLabelTextProvider(labels)
End If
End Sub
Private Sub OnDisplayDataPointsBetweenTicksCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale, NOrdinalScale).DisplayDataPointsBetweenTicks = CType(arg.TargetNode, NCheckBox).Checked
End Sub
Private Sub OnInvertedCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
CType(m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale, NOrdinalScale).Invert = CType(arg.TargetNode, NCheckBox).Checked
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