This example demonstrates how to use the daily schedule of the work calendar in order to skip hourly ranges for which there is no data.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Chart.Tools;
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 - NDailyScheduleWorkCalendarExample";
// 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 = "Daily Schedule Work Calendar";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
NRangeSeries ranges = new NRangeSeries();
m_Chart.Series.Add(ranges);
ranges.DataLabelStyle = new NDataLabelStyle(false);
ranges.UseXValues = true;
DateTime dt = new DateTime(2014, 4, 14);
Random rand = new Random();
NRangeTimelineScale rangeTimeline = new NRangeTimelineScale();
rangeTimeline.EnableCalendar = true;
rangeTimeline.InflateViewRangeEnd = false;
rangeTimeline.InflateViewRangeBegin = false;
m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = rangeTimeline;
NLinearScale yScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
yScale.MajorGridLines.Visible = true;
// add interlaced strip
NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
strip.Interlaced = true;
yScale.Strips.Add(strip);
yScale.Title.Text = "Daily Workload in %";
NWorkCalendar workCalendar = rangeTimeline.Calendar;
NDateTimeRangeRule dateTimeRangeRule = null;
for (int i = 0; i < 120; i++)
{
int hourOfTheDay = i % 24;
if (hourOfTheDay < 8 || hourOfTheDay > 18)
{
DateTime curDate = new DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0);
if (dateTimeRangeRule != null)
{
if (dateTimeRangeRule.Range.Begin != curDate)
{
dateTimeRangeRule = null;
}
}
if (dateTimeRangeRule == null)
{
dateTimeRangeRule = new NDateTimeRangeRule(new NDateTimeRange(curDate, curDate + new TimeSpan(24, 0, 0)), true);
workCalendar.Rules.Add(dateTimeRangeRule);
}
dateTimeRangeRule.Schedule.SetHourRange(dt.Hour, dt.Hour + 1, true);
}
else
{
ranges.DataPoints.Add(new NRangeDataPoint(NDateTimeHelpers.ToOADate(dt), 0, NDateTimeHelpers.ToOADate(dt + new TimeSpan(1, 0, 0)), rand.NextDouble() * 70 + 30.0d));
}
dt += new TimeSpan(1, 0, 0);
}
ConfigureInteractivity(m_Chart);
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 enableWorkCalendarCheckBox = new NCheckBox("Enable Work Calendar");
enableWorkCalendarCheckBox.CheckedChanged += OnEnableWorkCalendarCheckBoxCheckedChanged;
enableWorkCalendarCheckBox.Checked = true;
stack.Add(enableWorkCalendarCheckBox);
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to use the daily schedule of the work calendar in order to skip hourly ranges for which there is no data.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("DateTime Scale", "https://www.nevron.com/docs/openvision/datetime-scale.html"),
("Timeline scale", "https://www.nevron.com/docs/openvision/timeline-scale.html"),
("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html"),
};
}
#endregion
#region Implementation
private void ConfigureInteractivity(NChart chart)
{
NInteractor interactor = new NInteractor();
NRectangleZoomTool rectangleZoomTool = new NRectangleZoomTool();
rectangleZoomTool.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
interactor.Add(rectangleZoomTool);
NDataPanTool dataPanTool = new NDataPanTool();
dataPanTool.StartMouseButtonEvent = ENMouseButtonEvent.RightButtonDown;
dataPanTool.EndMouseButtonEvent = ENMouseButtonEvent.RightButtonUp;
interactor.Add(dataPanTool);
chart.Interactor = interactor;
}
#endregion
#region Event Handlers
void OnEnableWorkCalendarCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
((NRangeTimelineScale)m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale).EnableCalendar = (arg.TargetNode as NCheckBox).Checked;
}
#endregion
#region Fields
NCartesianChart m_Chart;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}