Stick Stock 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.

Stick Stock Example for Blazor Description

This example demonstrates how to create a stick stock chart.


Stick Stock Example

C# Stick Stock 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 - NStickStockExample";

			// 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 = "Stick Stock";

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

			m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);

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

			axis.Scale = new NValueTimelineScale();

			// 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;

			GenerateData();

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

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

This example demonstrates how to create a stick stock chart.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Stock Series", "https://www.nevron.com/docs/openvision/stock-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), }; } #endregion #region Implementation void GenerateData() { // 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); NDateTimeSpan span = new NDateTimeSpan(1, NDateTimeUnit.Day); long count = span.GetSpanCountInRange(new NDateTimeRange(dtStart, dtEnd)); double open, high, low, close; m_Stock.DataPoints.Clear(); Random random = new Random(); 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 #endregion #region Fields NStockSeries m_Stock; NCartesianChart m_Chart; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Stick Stock Example for Blazor Solution

Related Documentation Links