Weekly Schedule Calendar Example for WinForms

Weekly Schedule Calendar Example for WinForms

Nevron NOV Chart for WinForms ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WinForms 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.

Weekly Schedule Calendar Example for WinForms Description

This example demonstrates the ability of the timeline and date/time scales to skip date time ranges, when it is expected that there is no data for them. Common applications of this feature are financial charts that usually display only working week days as stock markets are closed on weekends.


Weekly Schedule Work Calendar Example

C# Weekly Schedule Calendar Example Code for Nevron Chart for WinForms
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 - NWeeklyScheduleWorkCalendarExample";

			// 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 = "Weekly 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;
			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 = "Weekly Workload in %";

			NWorkCalendar workCalendar = rangeTimeline.Calendar;

			// show only the working days on the scale
			NWeekDayRule weekDayRule = new NWeekDayRule(ENWeekDayBit.Monday | ENWeekDayBit.Tuesday | ENWeekDayBit.Wednesday | ENWeekDayBit.Thursday | ENWeekDayBit.Friday);
			workCalendar.Rules.Add(weekDayRule);

			// generate data for week working days
			for (int i = 0; i < 21; i++)
			{
				if (dt.DayOfWeek != DayOfWeek.Saturday && dt.DayOfWeek != DayOfWeek.Sunday)
				{
					ranges.DataPoints.Add(new NRangeDataPoint(NDateTimeHelpers.ToOADate(dt), 0, NDateTimeHelpers.ToOADate(dt + new TimeSpan(1, 0, 0, 0)), rand.NextDouble() * 70 + 30.0d));
				}

				dt += new TimeSpan(1, 0, 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 the ability of the timeline and date/time scales to skip date time ranges, when it is expected that there is no data for them. Common applications of this feature are financial charts that usually display only working week days as stock markets are closed on weekends.

"; } /// /// 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) Weekly Schedule Calendar Example for WinForms Solution

VB.NET Weekly Schedule Calendar Example Code for Nevron Chart for WinForms
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.Forms
Imports System

Public Class Form1

#Region "Constructors"

    Public Sub New()
        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.

        ' Set form title
        Text = "NOV WinForms - NWeeklyScheduleWorkCalendarExample"

        ' 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)
        host.Dock = DockStyle.Fill
        Controls.Add(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 = "Weekly 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
            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 = "Weekly Workload in %"

            Dim workCalendar = rangeTimeline.Calendar

            ' show only the working days on the scale
            Dim weekDayRule As NWeekDayRule = New NWeekDayRule(ENWeekDayBit.Monday Or ENWeekDayBit.Tuesday Or ENWeekDayBit.Wednesday Or ENWeekDayBit.Thursday Or ENWeekDayBit.Friday)
            workCalendar.Rules.Add(weekDayRule)

            ' generate data for week working days
            For i = 0 To 20
                If dt.DayOfWeek <> DayOfWeek.Saturday AndAlso dt.DayOfWeek <> DayOfWeek.Sunday Then
                    ranges.DataPoints.Add(New NRangeDataPoint(NDateTimeHelpers.ToOADate(dt), 0, NDateTimeHelpers.ToOADate(dt + New TimeSpan(1, 0, 0, 0)), rand.NextDouble() * 70 + 30.0R))
                End If

                dt += New TimeSpan(1, 0, 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 the ability of the timeline and date/time scales to skip date time ranges, when it is expected that there is no data for them. Common applications of this feature are financial charts that usually display only working week days as stock markets are closed on weekends.

" 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) Weekly Schedule Calendar Example for WinForms Solution