Range Timeline Scale Example for Blazor

Range Timeline Scale 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.

Range Timeline Scale Example for Blazor Description

This example demonstrates how to create a range timeline scale.


Range Timeline Scale Example

C# Range Timeline Scale Example Code for Nevron Chart for Blazor
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
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 - NRangeTimelineScaleExample";

			// 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 = "Range Timeline Scale";

			// configure chart
			m_Chart = (NCartesianChart)chartView.Surface.Charts[0];

			// configure axes
			m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
            m_Chart.SetPredefinedInteractor(ENPredefinedInteractor.DataZoomingAndScrolling);

            // setup X axis
            NCartesianAxis axis = m_Chart.Axes[ENCartesianAxis.PrimaryX];

			m_RangeTimelineScale = new NRangeTimelineScale();
			axis.Scale = m_RangeTimelineScale;

			// setup primary Y axis
			axis = m_Chart.Axes[ENCartesianAxis.PrimaryY];
			NLinearScale linearScale = (NLinearScale)axis.Scale;

			// configure ticks and grid lines
			linearScale.MajorGridLines.Stroke = new NStroke(NColor.LightGray);
			linearScale.InnerMajorTicks.Visible = false;

			// add interlaced stripe 
			NScaleStrip strip = new NScaleStrip();
			strip.Fill = new NColorFill(NColor.Beige);
			strip.Interlaced = true;
			linearScale.Strips.Add(strip);

			// Setup the stock series
			m_Stock = new NStockSeries();
			m_Chart.Series.Add(m_Stock);

			m_Stock.DataLabelStyle = new NDataLabelStyle(false);
			m_Stock.CandleShape = ENCandleShape.Stick;
			m_Stock.CandleWidth = 4;
			m_Stock.UseXValues = true;

			chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));

			OnWeeklyDataButtonClick(null);

			return chartViewWithCommandBars;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);

			NCheckBox firstRowVisibleCheckBox = new NCheckBox("First Row Visible");
			firstRowVisibleCheckBox.Click += OnFirstRowVisibleCheckBoxClick;
			stack.Add(firstRowVisibleCheckBox);

			NCheckBox secondRowVisibleCheckBox = new NCheckBox("Second Row Visible");
			secondRowVisibleCheckBox.Click += OnSecondRowVisibleCheckBoxClick;
			stack.Add(secondRowVisibleCheckBox);

			NCheckBox thirdRowVisibleCheckBox = new NCheckBox("Third Row Visible");
			thirdRowVisibleCheckBox.Click += OnThirdRowVisibleCheckBoxClick;
			stack.Add(thirdRowVisibleCheckBox);

			NButton dailyDataButton = new NButton("Daily Data");
			dailyDataButton.Click += OnDailyDataButtonClick;
			stack.Add(dailyDataButton);

			NButton weeklyDataButton = new NButton("Weekly Data");
			weeklyDataButton.Click += OnWeeklyDataButtonClick;
			stack.Add(weeklyDataButton);

			NButton monthlyDataButton = new NButton("Monthly Data");
			monthlyDataButton.Click += OnMonthlyDataButtonClick;
			stack.Add(monthlyDataButton);

			NButton yearlyDataButton = new NButton("Yearly Data");
			yearlyDataButton.Click += OnYearlyDataButtonClick;
			stack.Add(yearlyDataButton);

			firstRowVisibleCheckBox.Checked = true;
			secondRowVisibleCheckBox.Checked = true;
			thirdRowVisibleCheckBox.Checked = true;

			return boxGroup;
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create a range timeline scale.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Timeline scale", "https://www.nevron.com/docs/openvision/timeline-scale.html"), ("DateTime Scale", "https://www.nevron.com/docs/openvision/datetime-scale.html"), }; } #endregion #region Implementation private void GenerateData(DateTime dtStart, DateTime dtEnd, NDateTimeSpan span) { long count = span.GetSpanCountInRange(new NDateTimeRange(dtStart, dtEnd)); double open, high, low, close; m_Stock.DataPoints.Clear(); Random random = new Random(); DateTime dtNow = dtStart; double prevClose = 100; for (int nIndex = 0; nIndex < count; nIndex++) { open = prevClose; if (prevClose < 25 || random.NextDouble() > 0.5) { // upward price change close = open + (2 + (random.NextDouble() * 20)); high = close + (random.NextDouble() * 10); low = open - (random.NextDouble() * 10); } else { // downward price change close = open - (2 + (random.NextDouble() * 20)); high = open + (random.NextDouble() * 10); low = close - (random.NextDouble() * 10); } if (low < 1) { low = 1; } prevClose = close; m_Stock.DataPoints.Add(new NStockDataPoint(NDateTimeHelpers.ToOADate(dtNow), open, close, high, low)); dtNow = span.Add(dtNow); } } #endregion #region Event Handlers void OnThirdRowVisibleCheckBoxClick(NEventArgs arg) { m_RangeTimelineScale.FirstRow.Visible = ((NCheckBox)arg.TargetNode).Checked; } void OnSecondRowVisibleCheckBoxClick(NEventArgs arg) { m_RangeTimelineScale.SecondRow.Visible = ((NCheckBox)arg.TargetNode).Checked; } void OnFirstRowVisibleCheckBoxClick(NEventArgs arg) { m_RangeTimelineScale.ThirdRow.Visible = ((NCheckBox)arg.TargetNode).Checked; } void OnYearlyDataButtonClick(NEventArgs arg) { // generate data for 30 years DateTime dtNow = DateTime.Now; DateTime dtEnd = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0); DateTime dtStart = NDateTimeUnit.Year.Add(dtEnd, -30); GenerateData(dtStart, dtEnd, new NDateTimeSpan(1, NDateTimeUnit.Month)); } void OnMonthlyDataButtonClick(NEventArgs arg) { // generate data for 30 months DateTime dtNow = DateTime.Now; DateTime dtEnd = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0); DateTime dtStart = NDateTimeUnit.Month.Add(dtEnd, -30); GenerateData(dtStart, dtEnd, new NDateTimeSpan(1, NDateTimeUnit.Week)); } void OnWeeklyDataButtonClick(NEventArgs arg) { // generate data for 30 weeks DateTime dtNow = DateTime.Now; DateTime dtEnd = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0); DateTime dtStart = NDateTimeUnit.Week.Add(dtEnd, -30); GenerateData(dtStart, dtEnd, new NDateTimeSpan(1, NDateTimeUnit.Day)); } void OnDailyDataButtonClick(NEventArgs arg) { // generate data for 30 days DateTime dtNow = DateTime.Now; DateTime dtEnd = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 17, 0, 0, 0); DateTime dtStart = new DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0); GenerateData(dtStart, dtEnd, new NDateTimeSpan(5, NDateTimeUnit.Minute)); } #endregion #region Fields NCartesianChart m_Chart; NStockSeries m_Stock; NRangeTimelineScale m_RangeTimelineScale; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Range Timeline Scale Example for Blazor Solution

Related Documentation Links