Weekly Schedule Calendar Example for Blazor

Weekly Schedule Calendar Example for Blazor

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

Weekly Schedule Calendar Example for Blazor 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 Blazor
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 Blazor Solution