Standard Vector 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.

Standard Vector Example for Blazor Description

This example demonstrates how to create a standard 2D vector chart.


Standard Vector Example

C# Standard Vector 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 - NStandardVectorExample";

			// 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 = "Standard Vector";

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

			m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);

			// setup X axis
			NLinearScale scaleX = new NLinearScale();
			m_Chart.Axes[ENCartesianAxis.PrimaryX].Scale = scaleX;

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

            // add interlace stripe to the Y axis
            NScaleStrip stripStyleY = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
            stripStyleY.Interlaced = true;
            stripStyleY.SetShowAtWall(ENChartWall.Back, true);
            stripStyleY.SetShowAtWall(ENChartWall.Left, true);
            scaleY.Strips.Add(stripStyleY);

            // setup shape series
            NVectorSeries vectorSeries = new NVectorSeries();
			m_Chart.Series.Add(vectorSeries);
			vectorSeries.DataLabelStyle = new NDataLabelStyle(false);
			vectorSeries.InflateMargins = false;
			vectorSeries.UseXValues = true;
			vectorSeries.MinArrowheadSize = new NSize(2, 3);
			vectorSeries.MaxArrowheadSize = new NSize(4, 6);

			// fill data
			FillData(vectorSeries);
		
			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 standard 2D vector chart.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Vector Series", "https://www.nevron.com/docs/openvision/vector-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), }; } #endregion #region Implementation private void FillData(NVectorSeries vectorSeries) { double x, y = 0; for (int i = 0; i < 15; i++) { x = 1; y += 1; for (int j = 0; j < 15; j++) { double dx = Math.Sin(x / 3.0) * Math.Cos((x - y) / 4.0); double dy = Math.Cos(y / 8.0) * Math.Cos(y / 4.0); NColor color = ColorFromVector(dx, dy); vectorSeries.DataPoints.Add(new NVectorDataPoint(x, y, x + dx, y + dy, new NColorFill(color), new NStroke(1, color))); x++; } } } private NColor ColorFromVector(double dx, double dy) { double length = Math.Sqrt(dx * dx + dy * dy); double sq2 = Math.Sqrt(2); int r = (int)((255 / sq2) * length); int g = 20; int b = (int)((255 / sq2) * (sq2 - length)); return NColor.FromRGB((byte)r, (byte)g, (byte)b); } #endregion #region Event Handlers #endregion #region Fields NCartesianChart m_Chart; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Standard Vector Example for Blazor Solution

Related Documentation Links