This example demonstrates how to create a period (duration) scale. The duration scale is similar to a linear scale except it uses time units for decoration.
Time units are different than date/time units because they are regular (always result in the same number of ticks).

| 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 - NTimeSpanScaleExampe";
// 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 = "Time Span Scale";
// configure chart
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
chart.SetPredefinedInteractor(ENPredefinedInteractor.DataZoomingAndScrolling);
// configure axes
chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XTimeSpanYLinear);
m_TimeSpanScale = new NTimeSpanScale();
chart.Axes[ENCartesianAxis.PrimaryX].Scale = m_TimeSpanScale;
// configure the y axis
NLinearScale linearScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;
NScaleGridLines majorGrid = new NScaleGridLines();
majorGrid.Stroke = new NStroke(1, NColor.DarkGray, ENDashStyle.Dot);
linearScale.MajorGridLines = majorGrid;
// add a strip line style
NScaleStrip strip = new NScaleStrip();
strip.Fill = new NColorFill(NColor.Beige);
strip.Interlaced = true;
linearScale.Strips.Add(strip);
m_Line = new NLineSeries();
m_Line.UseXValues = true;
m_Line.DataLabelStyle = new NDataLabelStyle(false);
chart.Series.Add(m_Line);
Random random = new Random();
for (int i = 0; i < 7; i++)
{
m_Line.DataPoints.Add(new NLineDataPoint(random.Next(-100, 100)));
}
m_Line.LegendView.Mode = ENSeriesLegendMode.None;
m_Line.InflateMargins = true;
// assign marker
NMarkerStyle markerStyle = new NMarkerStyle();
markerStyle.Visible = true;
markerStyle.Fill = new NColorFill(NColor.DarkOrange);
markerStyle.Shape = ENPointShape3D.Ellipse;
markerStyle.Size = new NSize(6, 6);
m_Line.MarkerStyle = markerStyle;
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
OnGenerateMinuteDataButtonClick(null);
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
NStackPanel groupBoxContent = new NStackPanel();
NGroupBox groupBox = new NGroupBox("Allowed Time Units", groupBoxContent);
stack.Add(groupBox);
m_EnableUnitSensitiveFormattingCheckBox = new NCheckBox("Enable Unit Sensitive Formatting");
m_EnableUnitSensitiveFormattingCheckBox.Checked = true;
m_EnableUnitSensitiveFormattingCheckBox.CheckedChanged += OnEnableUnitSensitiveFormattingCheckBoxCheckedChanged;
groupBoxContent.AddChild(m_EnableUnitSensitiveFormattingCheckBox);
m_MillisecondCheckBox = new NCheckBox("Millisecond");
m_MillisecondCheckBox.Checked = true;
m_MillisecondCheckBox.CheckedChanged += OnAllowedTimeUnitChanged;
groupBoxContent.AddChild(m_MillisecondCheckBox);
m_SecondCheckBox = new NCheckBox("Second");
m_SecondCheckBox.Checked = true;
m_SecondCheckBox.CheckedChanged += OnAllowedTimeUnitChanged;
groupBoxContent.AddChild(m_SecondCheckBox);
m_MinuteCheckBox = new NCheckBox("Minute");
m_MinuteCheckBox.Checked = true;
m_MinuteCheckBox.CheckedChanged += OnAllowedTimeUnitChanged;
groupBoxContent.AddChild(m_MinuteCheckBox);
m_HourCheckBox = new NCheckBox("Hour");
m_HourCheckBox.Checked = true;
m_HourCheckBox.CheckedChanged += OnAllowedTimeUnitChanged;
groupBoxContent.AddChild(m_HourCheckBox);
m_DayCheckBox = new NCheckBox("Day");
m_DayCheckBox.Checked = true;
m_DayCheckBox.CheckedChanged += OnAllowedTimeUnitChanged;
groupBoxContent.AddChild(m_DayCheckBox);
m_HalfDayDayCheckBox = new NCheckBox("Half Day");
m_HalfDayDayCheckBox.Checked = true;
m_HalfDayDayCheckBox.CheckedChanged += OnAllowedTimeUnitChanged;
groupBoxContent.AddChild(m_HalfDayDayCheckBox);
m_WeekCheckBox = new NCheckBox("Week");
m_WeekCheckBox.Checked = true;
m_WeekCheckBox.CheckedChanged += OnAllowedTimeUnitChanged;
groupBoxContent.AddChild(m_WeekCheckBox);
NButton generateMinuteDataButton = new NButton("Generate Minute Data");
generateMinuteDataButton.Click += OnGenerateMinuteDataButtonClick;
stack.Add(generateMinuteDataButton);
NButton generateHourlyDataButton = new NButton("Generate Hourly Data");
generateHourlyDataButton.Click += OnGenerateHourlyDataButtonClick;
stack.Add(generateHourlyDataButton);
NButton generateDailyDataButton = new NButton("Generate Daily Data");
generateDailyDataButton.Click += OnGenerateDailyDataButtonClick;
stack.Add(generateDailyDataButton);
return boxGroup;
}
///
///
///
///
public string GetExampleDescription()
{
return @"This example demonstrates how to create a period (duration) scale. The duration scale is similar to a linear scale except it uses time units for decoration.
Time units are different than date/time units because they are regular (always result in the same number of ticks).
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Timespan scale", "https://www.nevron.com/docs/openvision/timespan-scale.html"),
("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnEnableUnitSensitiveFormattingCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
if (m_TimeSpanScale == null)
return;
if (((NCheckBox)arg.TargetNode).Checked)
{
m_TimeSpanScale.Labels.TextProvider = new NTimeUnitSensitiveLabelTextProvider();
}
else
{
m_TimeSpanScale.Labels.TextProvider = new NFormattedScaleLabelTextProvider(new NTimeSpanValueFormatter(ENTimeSpanValueFormat.HourMinute));
}
}
private void OnAllowedTimeUnitChanged(NValueChangeEventArgs arg)
{
if (m_TimeSpanScale == null)
return;
NList autoTimeUnits = new NList();
if (m_MillisecondCheckBox.Checked)
{
autoTimeUnits.Add(NTimeUnit.Millisecond);
}
if (m_SecondCheckBox.Checked)
{
autoTimeUnits.Add(NTimeUnit.Second);
}
if (m_MinuteCheckBox.Checked)
{
autoTimeUnits.Add(NTimeUnit.Minute);
}
if (m_HourCheckBox.Checked)
{
autoTimeUnits.Add(NTimeUnit.Hour);
}
if (m_DayCheckBox.Checked)
{
autoTimeUnits.Add(NTimeUnit.Day);
}
if (m_HalfDayDayCheckBox.Checked)
{
autoTimeUnits.Add(NTimeUnit.HalfDay);
}
if (m_WeekCheckBox.Checked)
{
autoTimeUnits.Add(NTimeUnit.Week);
}
m_TimeSpanScale.AutoTimeUnits = new NDomArray(autoTimeUnits.ToArray());
}
private void OnGenerateMinuteDataButtonClick(NEventArgs arg)
{
GenerateData(new TimeSpan(0, 10, 0), new TimeSpan(0, 0, 10));
}
private void OnGenerateHourlyDataButtonClick(NEventArgs arg)
{
GenerateData(new TimeSpan(15, 0, 0), new TimeSpan(0, 10, 0));
}
private void OnGenerateDailyDataButtonClick(NEventArgs arg)
{
GenerateData(new TimeSpan(240, 0, 0), new TimeSpan(12, 0, 0));
}
private void GenerateData(TimeSpan limit, TimeSpan step)
{
m_Line.DataPoints.Clear();
TimeSpan origin = new TimeSpan(0);
Random rand = new Random();
long count = limit.Ticks / step.Ticks;
long counter = 0;
Random random = new Random();
for (; origin < limit; origin += step)
{
double y = 10 * Math.Sin(Math.PI * counter / count) + random.NextDouble() * 2 - 1;
m_Line.DataPoints.Add(new NLineDataPoint((double)origin.Ticks, y));
}
}
#endregion
#region Fields
NLineSeries m_Line;
NTimeSpanScale m_TimeSpanScale;
NCheckBox m_EnableUnitSensitiveFormattingCheckBox;
NCheckBox m_MillisecondCheckBox;
NCheckBox m_SecondCheckBox;
NCheckBox m_MinuteCheckBox;
NCheckBox m_HourCheckBox;
NCheckBox m_DayCheckBox;
NCheckBox m_HalfDayDayCheckBox;
NCheckBox m_WeekCheckBox;
#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 - NTimeSpanScaleExampe"
' 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 = "Time Span Scale"
' configure chart
Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)
chart.SetPredefinedInteractor(ENPredefinedInteractor.DataZoomingAndScrolling)
' configure axes
chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XTimeSpanYLinear)
m_TimeSpanScale = New NTimeSpanScale()
chart.Axes(ENCartesianAxis.PrimaryX).Scale = m_TimeSpanScale
' configure the y axis
Dim linearScale As NLinearScale = chart.Axes(ENCartesianAxis.PrimaryY).Scale
Dim majorGrid As NScaleGridLines = New NScaleGridLines()
majorGrid.Stroke = New NStroke(1, NColor.DarkGray, ENDashStyle.Dot)
linearScale.MajorGridLines = majorGrid
' add a strip line style
Dim strip As NScaleStrip = New NScaleStrip()
strip.Fill = New NColorFill(NColor.Beige)
strip.Interlaced = True
linearScale.Strips.Add(strip)
m_Line = New NLineSeries()
m_Line.UseXValues = True
m_Line.DataLabelStyle = New NDataLabelStyle(False)
chart.Series.Add(m_Line)
Dim random As Random = New Random()
For i = 0 To 6
m_Line.DataPoints.Add(New NLineDataPoint(random.Next(-100, 100)))
Next
m_Line.LegendView.Mode = ENSeriesLegendMode.None
m_Line.InflateMargins = True
' assign marker
Dim markerStyle As NMarkerStyle = New NMarkerStyle()
markerStyle.Visible = True
markerStyle.Fill = New NColorFill(NColor.DarkOrange)
markerStyle.Shape = ENPointShape3D.Ellipse
markerStyle.Size = New NSize(6, 6)
m_Line.MarkerStyle = markerStyle
chartView.Document.StyleSheets.ApplyTheme(New NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series))
OnGenerateMinuteDataButtonClick(Nothing)
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim groupBoxContent As NStackPanel = New NStackPanel()
Dim groupBox As NGroupBox = New NGroupBox("Allowed Time Units", groupBoxContent)
stack.Add(groupBox)
m_EnableUnitSensitiveFormattingCheckBox = New NCheckBox("Enable Unit Sensitive Formatting")
m_EnableUnitSensitiveFormattingCheckBox.Checked = True
Me.m_EnableUnitSensitiveFormattingCheckBox.CheckedChanged += AddressOf OnEnableUnitSensitiveFormattingCheckBoxCheckedChanged
groupBoxContent.AddChild(m_EnableUnitSensitiveFormattingCheckBox)
m_MillisecondCheckBox = New NCheckBox("Millisecond")
m_MillisecondCheckBox.Checked = True
Me.m_MillisecondCheckBox.CheckedChanged += AddressOf OnAllowedTimeUnitChanged
groupBoxContent.AddChild(m_MillisecondCheckBox)
m_SecondCheckBox = New NCheckBox("Second")
m_SecondCheckBox.Checked = True
Me.m_SecondCheckBox.CheckedChanged += AddressOf OnAllowedTimeUnitChanged
groupBoxContent.AddChild(m_SecondCheckBox)
m_MinuteCheckBox = New NCheckBox("Minute")
m_MinuteCheckBox.Checked = True
Me.m_MinuteCheckBox.CheckedChanged += AddressOf OnAllowedTimeUnitChanged
groupBoxContent.AddChild(m_MinuteCheckBox)
m_HourCheckBox = New NCheckBox("Hour")
m_HourCheckBox.Checked = True
Me.m_HourCheckBox.CheckedChanged += AddressOf OnAllowedTimeUnitChanged
groupBoxContent.AddChild(m_HourCheckBox)
m_DayCheckBox = New NCheckBox("Day")
m_DayCheckBox.Checked = True
Me.m_DayCheckBox.CheckedChanged += AddressOf OnAllowedTimeUnitChanged
groupBoxContent.AddChild(m_DayCheckBox)
m_HalfDayDayCheckBox = New NCheckBox("Half Day")
m_HalfDayDayCheckBox.Checked = True
Me.m_HalfDayDayCheckBox.CheckedChanged += AddressOf OnAllowedTimeUnitChanged
groupBoxContent.AddChild(m_HalfDayDayCheckBox)
m_WeekCheckBox = New NCheckBox("Week")
m_WeekCheckBox.Checked = True
Me.m_WeekCheckBox.CheckedChanged += AddressOf OnAllowedTimeUnitChanged
groupBoxContent.AddChild(m_WeekCheckBox)
Dim generateMinuteDataButton As NButton = New NButton("Generate Minute Data")
generateMinuteDataButton.Click += AddressOf OnGenerateMinuteDataButtonClick
stack.Add(generateMinuteDataButton)
Dim generateHourlyDataButton As NButton = New NButton("Generate Hourly Data")
generateHourlyDataButton.Click += AddressOf OnGenerateHourlyDataButtonClick
stack.Add(generateHourlyDataButton)
Dim generateDailyDataButton As NButton = New NButton("Generate Daily Data")
generateDailyDataButton.Click += AddressOf OnGenerateDailyDataButtonClick
stack.Add(generateDailyDataButton)
Return boxGroup
End Function
'''
'''
'''
'''
Public Function GetExampleDescription() As String
Return "This example demonstrates how to create a period (duration) scale. The duration scale is similar to a linear scale except it uses time units for decoration.
Time units are different than date/time units because they are regular (always result in the same number of ticks).
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Timespan scale", "https://www.nevron.com/docs/openvision/timespan-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 OnEnableUnitSensitiveFormattingCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
If m_TimeSpanScale Is Nothing Then Return
If CType(arg.TargetNode, NCheckBox).Checked Then
m_TimeSpanScale.Labels.TextProvider = New NTimeUnitSensitiveLabelTextProvider()
Else
m_TimeSpanScale.Labels.TextProvider = New NFormattedScaleLabelTextProvider(New NTimeSpanValueFormatter(ENTimeSpanValueFormat.HourMinute))
End If
End Sub
Private Sub OnAllowedTimeUnitChanged(arg As NValueChangeEventArgs)
If m_TimeSpanScale Is Nothing Then Return
Dim autoTimeUnits As NList(Of NTimeUnit) = New NList(Of NTimeUnit)()
If m_MillisecondCheckBox.Checked Then
autoTimeUnits.Add(NDateTimeUnit.Millisecond)
End If
If m_SecondCheckBox.Checked Then
autoTimeUnits.Add(NDateTimeUnit.Second)
End If
If m_MinuteCheckBox.Checked Then
autoTimeUnits.Add(NDateTimeUnit.Minute)
End If
If m_HourCheckBox.Checked Then
autoTimeUnits.Add(NDateTimeUnit.Hour)
End If
If m_DayCheckBox.Checked Then
autoTimeUnits.Add(NDateTimeUnit.Day)
End If
If m_HalfDayDayCheckBox.Checked Then
autoTimeUnits.Add(NDateTimeUnit.HalfDay)
End If
If m_WeekCheckBox.Checked Then
autoTimeUnits.Add(NDateTimeUnit.Week)
End If
m_TimeSpanScale.AutoTimeUnits = New NDomArray(Of NTimeUnit)(autoTimeUnits.ToArray())
End Sub
Private Sub OnGenerateMinuteDataButtonClick(arg As NEventArgs)
GenerateData(New TimeSpan(0, 10, 0), New TimeSpan(0, 0, 10))
End Sub
Private Sub OnGenerateHourlyDataButtonClick(arg As NEventArgs)
GenerateData(New TimeSpan(15, 0, 0), New TimeSpan(0, 10, 0))
End Sub
Private Sub OnGenerateDailyDataButtonClick(arg As NEventArgs)
GenerateData(New TimeSpan(240, 0, 0), New TimeSpan(12, 0, 0))
End Sub
Private Sub GenerateData(limit As TimeSpan, [step] As TimeSpan)
m_Line.DataPoints.Clear()
Dim origin As TimeSpan = New TimeSpan(0)
Dim rand As Random = New Random()
Dim count As Long = limit.Ticks / [step].Ticks
Dim counter As Long = 0
Dim random As Random = New Random()
While origin < limit
Dim y As Double = 10 * Math.Sin(Math.PI * counter / count) + random.NextDouble() * 2 - 1
m_Line.DataPoints.Add(New NLineDataPoint(origin.Ticks, y))
origin += [step]
End While
End Sub
#End Region
#Region "Fields"
Private m_Line As NLineSeries
Private m_TimeSpanScale As NTimeSpanScale
Private m_EnableUnitSensitiveFormattingCheckBox As NCheckBox
Private m_MillisecondCheckBox As NCheckBox
Private m_SecondCheckBox As NCheckBox
Private m_MinuteCheckBox As NCheckBox
Private m_HourCheckBox As NCheckBox
Private m_DayCheckBox As NCheckBox
Private m_HalfDayDayCheckBox As NCheckBox
Private m_WeekCheckBox As NCheckBox
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class