Value Timeline Scale Example for WPF

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

Value Timeline Scale Example for WPF Description

This example demonstrates how to create a value timeline scale.


Value Timeline Scale Example

C# Value Timeline Scale Example Code for Nevron Chart for WPF
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 - NValueTimelineScaleExample";

			// 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 = "Value 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_TimeLineScale = new NValueTimelineScale();
			axis.Scale = m_TimeLineScale;

			// 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 value 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_TimeLineScale.FirstRow.Visible = ((NCheckBox)arg.TargetNode).Checked; } void OnSecondRowVisibleCheckBoxClick(NEventArgs arg) { m_TimeLineScale.SecondRow.Visible = ((NCheckBox)arg.TargetNode).Checked; } void OnFirstRowVisibleCheckBoxClick(NEventArgs arg) { m_TimeLineScale.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; NValueTimelineScale m_TimeLineScale; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Value Timeline Scale Example for WPF Solution

VB.NET Value Timeline Scale Example Code for Nevron Chart for WPF
Language: VB.NET

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

		' 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 = "Value Timeline Scale"

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

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

            ' setup X axis
            Dim axis = m_Chart.Axes(ENCartesianAxis.PrimaryX)

            m_TimeLineScale = New NValueTimelineScale()
            axis.Scale = m_TimeLineScale

            ' setup primary Y axis
            axis = m_Chart.Axes(ENCartesianAxis.PrimaryY)
            Dim linearScale = CType(axis.Scale, NLinearScale)

            ' configure ticks and grid lines
            linearScale.MajorGridLines.Stroke = New NStroke(NColor.LightGray)
            linearScale.InnerMajorTicks.Visible = False

            ' add interlaced stripe 
            Dim strip As NScaleStrip = 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(Nothing)

            Return chartViewWithCommandBars
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)

            Dim firstRowVisibleCheckBox As NCheckBox = New NCheckBox("First Row Visible")
            firstRowVisibleCheckBox.Click += AddressOf OnFirstRowVisibleCheckBoxClick
            stack.Add(firstRowVisibleCheckBox)

            Dim secondRowVisibleCheckBox As NCheckBox = New NCheckBox("Second Row Visible")
            secondRowVisibleCheckBox.Click += AddressOf OnSecondRowVisibleCheckBoxClick
            stack.Add(secondRowVisibleCheckBox)

            Dim thirdRowVisibleCheckBox As NCheckBox = New NCheckBox("Third Row Visible")
            thirdRowVisibleCheckBox.Click += AddressOf OnThirdRowVisibleCheckBoxClick
            stack.Add(thirdRowVisibleCheckBox)

            Dim dailyDataButton As NButton = New NButton("Daily Data")
            dailyDataButton.Click += AddressOf OnDailyDataButtonClick
            stack.Add(dailyDataButton)

            Dim weeklyDataButton As NButton = New NButton("Weekly Data")
            weeklyDataButton.Click += AddressOf OnWeeklyDataButtonClick
            stack.Add(weeklyDataButton)

            Dim monthlyDataButton As NButton = New NButton("Monthly Data")
            monthlyDataButton.Click += AddressOf OnMonthlyDataButtonClick
            stack.Add(monthlyDataButton)

            Dim yearlyDataButton As NButton = New NButton("Yearly Data")
            yearlyDataButton.Click += AddressOf OnYearlyDataButtonClick
            stack.Add(yearlyDataButton)

            firstRowVisibleCheckBox.Checked = True
            secondRowVisibleCheckBox.Checked = True
            thirdRowVisibleCheckBox.Checked = True

            Return boxGroup
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create a value timeline scale.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Timeline scale", "https://www.nevron.com/docs/openvision/timeline-scale.html"), ("DateTime Scale", "https://www.nevron.com/docs/openvision/datetime-scale.html")} End Function #End Region #Region "Implementation" Private Sub GenerateData(dtStart As Date, dtEnd As Date, span As NDateTimeSpan) Dim count As Long = span.GetSpanCountInRange(New NDateTimeRange(dtStart, dtEnd)) Dim open, high, low, close As Double m_Stock.DataPoints.Clear() Dim random As Random = New Random() Dim dtNow = dtStart Dim prevClose As Double = 100 For nIndex As Integer = 0 To count - 1 open = prevClose If prevClose < 25 OrElse random.NextDouble() > 0.5 Then ' 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) End If If low < 1 Then low = 1 End If prevClose = close m_Stock.DataPoints.Add(New NStockDataPoint(NDateTimeHelpers.ToOADate(dtNow), open, close, high, low)) dtNow = span.Add(dtNow) Next End Sub #End Region #Region "Event Handlers" Private Sub OnThirdRowVisibleCheckBoxClick(arg As NEventArgs) m_TimeLineScale.FirstRow.Visible = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnSecondRowVisibleCheckBoxClick(arg As NEventArgs) m_TimeLineScale.SecondRow.Visible = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnFirstRowVisibleCheckBoxClick(arg As NEventArgs) m_TimeLineScale.ThirdRow.Visible = CType(arg.TargetNode, NCheckBox).Checked End Sub Private Sub OnYearlyDataButtonClick(arg As NEventArgs) ' generate data for 30 years Dim dtNow = Date.Now Dim dtEnd As Date = New DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0) Dim dtStart As Date = NDateTimeUnit.Year.Add(dtEnd, -30) GenerateData(dtStart, dtEnd, New NDateTimeSpan(1, NDateTimeUnit.Month)) End Sub Private Sub OnMonthlyDataButtonClick(arg As NEventArgs) ' generate data for 30 months Dim dtNow = Date.Now Dim dtEnd As Date = New DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0) Dim dtStart As Date = NDateTimeUnit.Month.Add(dtEnd, -30) GenerateData(dtStart, dtEnd, New NDateTimeSpan(1, NDateTimeUnit.Week)) End Sub Private Sub OnWeeklyDataButtonClick(arg As NEventArgs) ' generate data for 30 weeks Dim dtNow = Date.Now Dim dtEnd As Date = New DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0) Dim dtStart As Date = NDateTimeUnit.Week.Add(dtEnd, -30) GenerateData(dtStart, dtEnd, New NDateTimeSpan(1, NDateTimeUnit.Day)) End Sub Private Sub OnDailyDataButtonClick(arg As NEventArgs) ' generate data for 30 days Dim dtNow = Date.Now Dim dtEnd As Date = New DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 17, 0, 0, 0) Dim dtStart As Date = New DateTime(dtNow.Year, dtNow.Month, dtNow.Day, 7, 0, 0, 0) GenerateData(dtStart, dtEnd, New NDateTimeSpan(5, NDateTimeUnit.Minute)) End Sub #End Region #Region "Fields" Private m_Chart As NCartesianChart Private m_Stock As NStockSeries Private m_TimeLineScale As NValueTimelineScale #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) Value Timeline Scale Example for WPF Solution

Related Documentation Links