Daily Schedule Calendar Example for WPF

Daily Schedule Calendar Example for WPF

Nevron NOV Chart for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF Chart examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Daily Schedule Calendar Example for WPF Description

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.


Daily Schedule Work Calendar Example

C# Daily Schedule Calendar Example Code for Nevron Chart for WPF
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 } }

Download a fully functional C# (.cs) Daily Schedule Calendar Example for WPF Solution

VB.NET Daily Schedule Calendar Example Code for Nevron Chart for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Chart.Tools
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 - NDailyScheduleWorkCalendarExample"

		' 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 = "Daily Schedule Work Calendar"

            ' configure chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)

            Dim ranges As NRangeSeries = New NRangeSeries()
            m_Chart.Series.Add(ranges)

            ranges.DataLabelStyle = New NDataLabelStyle(False)
            ranges.UseXValues = True

            Dim dt As Date = New DateTime(2014, 4, 14)
            Dim rand As Random = New Random()

            Dim rangeTimeline As NRangeTimelineScale = New NRangeTimelineScale()
            rangeTimeline.EnableCalendar = True
            rangeTimeline.InflateViewRangeEnd = False
            rangeTimeline.InflateViewRangeBegin = False
            m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale = rangeTimeline

            Dim yScale As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale
            yScale.MajorGridLines.Visible = True

            ' add interlaced strip
            Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
            strip.Interlaced = True
            yScale.Strips.Add(strip)

            yScale.Title.Text = "Daily Workload in %"

            Dim workCalendar = rangeTimeline.Calendar
            Dim dateTimeRangeRule As NDateTimeRangeRule = Nothing

            For i = 0 To 119
                Dim hourOfTheDay = i Mod 24

                If hourOfTheDay < 8 OrElse hourOfTheDay > 18 Then
                    Dim curDate As Date = New DateTime(dt.Year, dt.Month, dt.Day, 0, 0, 0)

                    If dateTimeRangeRule IsNot Nothing Then
                        If dateTimeRangeRule.Range.Begin <> curDate Then
                            dateTimeRangeRule = Nothing
                        End If
                    End If

                    If dateTimeRangeRule Is Nothing Then
                        dateTimeRangeRule = New NDateTimeRangeRule(New NDateTimeRange(curDate, curDate + New TimeSpan(24, 0, 0)), True)
                        workCalendar.Rules.Add(dateTimeRangeRule)
                    End If

                    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.0R))
                End If

                dt += New TimeSpan(1, 0, 0)
            Next

            ConfigureInteractivity(m_Chart)

            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 enableWorkCalendarCheckBox As NCheckBox = New NCheckBox("Enable Work Calendar")
            enableWorkCalendarCheckBox.CheckedChanged += AddressOf OnEnableWorkCalendarCheckBoxCheckedChanged
            enableWorkCalendarCheckBox.Checked = True
            stack.Add(enableWorkCalendarCheckBox)

            Return boxGroup
        End Function
        Public Function GetExampleDescription() As String
            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.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("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")} End Function #End Region #Region "Implementation" Private Sub ConfigureInteractivity(chart As NChart) Dim interactor As NInteractor = New NInteractor() Dim rectangleZoomTool As NRectangleZoomTool = New NRectangleZoomTool() rectangleZoomTool.VerticalValueSnapper = New NAxisRulerMinMaxSnapper() interactor.Add(rectangleZoomTool) Dim dataPanTool As NDataPanTool = New NDataPanTool() dataPanTool.StartMouseButtonEvent = ENMouseButtonEvent.RightButtonDown dataPanTool.EndMouseButtonEvent = ENMouseButtonEvent.RightButtonUp interactor.Add(dataPanTool) chart.Interactor = interactor End Sub #End Region #Region "Event Handlers" Private Sub OnEnableWorkCalendarCheckBoxCheckedChanged(arg As NValueChangeEventArgs) CType(m_Chart.Axes(ENCartesianAxis.PrimaryX).Scale, NRangeTimelineScale).EnableCalendar = TryCast(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

Download a fully functional VB.NET (.vb) Daily Schedule Calendar Example for WPF Solution