XY Scatter 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.

XY Scatter Area Example for Blazor Description

This example demonstrates how to create an XY scatter area chart.


XYScatter Area Example

C# XY Scatter Area 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 - NXYScatterAreaExample";

			// 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();
			m_ChartView = chartViewWithCommandBars.View;
			m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);

			// configure title
			m_ChartView.Surface.Titles[0].Text = "XY Scatter Area";

			// configure chart
			NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0];
			chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);

            // add interlace stripe
			NLinearScale linearScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;
            NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
            stripStyle.Interlaced = true;
            linearScale.Strips.Add(stripStyle);

            // show the x axis grid lines
			linearScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale;

			NScaleGridLines majorGrid = new NScaleGridLines();
			majorGrid.Visible = true;
			linearScale.MajorGridLines = majorGrid;

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

			NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
			dataLabelStyle.Visible = true;
			dataLabelStyle.ArrowStroke.Width = 0;
			dataLabelStyle.Format = "";
			m_Area.DataLabelStyle = dataLabelStyle;

			m_Area.UseXValues = true;

			// add xy values
			m_Area.DataPoints.Add(new NAreaDataPoint(12, 10));
			m_Area.DataPoints.Add(new NAreaDataPoint(25, 23));
			m_Area.DataPoints.Add(new NAreaDataPoint(45, 12));
			m_Area.DataPoints.Add(new NAreaDataPoint(55, 24));
			m_Area.DataPoints.Add(new NAreaDataPoint(61, 16));
			m_Area.DataPoints.Add(new NAreaDataPoint(69, 19));
			m_Area.DataPoints.Add(new NAreaDataPoint(78, 17));

			chart.Series.Add(m_Area);

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

			NButton changeXValuesButton = new NButton("Change X Values");
			changeXValuesButton.Click += OnChangeXValuesButtonClick;
			stack.Add(changeXValuesButton);

			NCheckBox xAxisRoundToTickCheckBox = new NCheckBox("X Axis Round To Tick");
			xAxisRoundToTickCheckBox.CheckedChanged += OnXAxisRoundToTickCheckBoxCheckedChanged;
			stack.Add(xAxisRoundToTickCheckBox);

			NCheckBox invertXAxisCheckBox = new NCheckBox("Invert X Axis");
			invertXAxisCheckBox.CheckedChanged += OnInvertXAxisCheckBoxCheckedChanged;
			stack.Add(invertXAxisCheckBox);

			NCheckBox invertYAxisCheckBox = new NCheckBox("Invert Y Axis");
			invertYAxisCheckBox.CheckedChanged += OnInvertYAxisCheckBoxCheckedChanged;
			stack.Add(invertYAxisCheckBox);

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

This example demonstrates how to create an XY scatter 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"), ("Linear Scale", "https://www.nevron.com/docs/openvision/linear-scale.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnChangeXValuesButtonClick(NEventArgs arg) { Random random = new Random(); int dataPointCount = m_Area.DataPoints.Count; m_Area.DataPoints[0].X = (double)random.Next(10); for (int i = 1; i < dataPointCount; i++) { m_Area.DataPoints[i].X = m_Area.DataPoints[i - 1].X + random.Next(1, 10); } } void OnInvertXAxisCheckBoxCheckedChanged(NValueChangeEventArgs arg) { NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0]; chart.Axes[ENCartesianAxis.PrimaryX].Scale.Invert = ((NCheckBox)arg.TargetNode).Checked; } void OnInvertYAxisCheckBoxCheckedChanged(NValueChangeEventArgs arg) { NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0]; chart.Axes[ENCartesianAxis.PrimaryY].Scale.Invert = ((NCheckBox)arg.TargetNode).Checked; } void OnXAxisRoundToTickCheckBoxCheckedChanged(NValueChangeEventArgs arg) { NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0]; NLinearScale linearScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale; if ((arg.TargetNode as NCheckBox).Checked) { linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.MajorTick; linearScale.InflateViewRangeBegin = true; linearScale.InflateViewRangeEnd = true; } else { linearScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.Logical; } } #endregion #region Fields private NChartView m_ChartView; private NAreaSeries m_Area; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

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