Standard Area 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 Area Example for Blazor Description

This example demonstrates how to create a standard area chart.


Standard Area Example

C# Standard Area 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.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NStandardAreaExample";

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

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

            // setup X axis
            NOrdinalScale scaleX = (NOrdinalScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale;
			scaleX.InflateContentRange = false;
			scaleX.MajorTickMode = ENMajorTickMode.AutoMaxCount;
			scaleX.DisplayDataPointsBetweenTicks = false;
			scaleX.Labels.Visible = false;

			for (int i = 0; i < monthLetters.Length; i++)
			{
				scaleX.CustomLabels.Add(new NCustomValueLabel(i, monthLetters[i]));
			}

			// add interlaced stripe for Y axis
			NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
			stripStyle.Interlaced = true;

			NLinearScale scaleY = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;
			scaleY.Strips.Add(stripStyle);

			// setup area series
			m_Area = new NAreaSeries();
			m_Area.Name = "Area Series";

			NDataLabelStyle dataLabelStyle = new NDataLabelStyle();

			dataLabelStyle.Visible = true;
			dataLabelStyle.Format = "";

			m_Area.DataLabelStyle = dataLabelStyle;

			for (int i = 0; i < monthValues.Length; i++)
			{
				m_Area.DataPoints.Add(new NAreaDataPoint(monthValues[i]));
			}

			chart.Series.Add(m_Area);

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

			NComboBox originModeComboBox = new NComboBox();
			originModeComboBox.Items.FillFromEnum();
			originModeComboBox.SelectedIndexChanged += OnOriginModeComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Origin Mode: ", originModeComboBox));

			NNumericUpDown customOriginUpDown = new NNumericUpDown();
			customOriginUpDown.ValueChanged += OnCustomOriginUpDownValueChanged;
			stack.Add(NPairBox.Create("Custom Origin: ", customOriginUpDown));

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

This example demonstrates how to create a standard area chart.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Area Series", "https://www.nevron.com/docs/openvision/area-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnCustomOriginUpDownValueChanged(NValueChangeEventArgs arg) { m_Area.CustomOrigin = (double)((NNumericUpDown)arg.TargetNode).Value; } void OnOriginModeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_Area.OriginMode = (ENSeriesOriginMode)((NComboBox)arg.TargetNode).SelectedIndex; } #endregion #region Fields NAreaSeries m_Area; #endregion #region Static Methods #endregion #region Constants internal static readonly double[] monthValues = new double[] { 16, 19, 16, 15, 18, 19, 24, 21, 22, 17, 19, 15 }; internal static readonly string[] monthLetters = new string[] { "J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D" }; #endregion #region Nested Types #endregion } }

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

Related Documentation Links