Axis Reference Lines Example for Blazor

Axis Reference Lines 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.

Axis Reference Lines Example for Blazor Description

This example demonstrates how to add axis reference lines.


Axis Reference Lines Example

C# Axis Reference Lines 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.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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 = "Axis Reference Lines";

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

			chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);

			// configure the y scale
			NLinearScale yScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;

			NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
			stripStyle.Interlaced = true;
			yScale.Strips.Add(stripStyle);

			yScale.MajorGridLines.Visible = true;

			// Create a point series
			NPointSeries point = new NPointSeries();
			point.InflateMargins = true;
			point.UseXValues = true;
			point.Name = "Series 1";
			chart.Series.Add(point);

			NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
			dataLabelStyle.Visible = false;
			point.DataLabelStyle = dataLabelStyle;

			// Add some data
			double[] yValues = new double[] { 31, 67, 12, 84, 90 };
			double[] xValues = new double[] { 5, 36, 51, 76, 93 };

			for (int i = 0; i < yValues.Length; i++)
			{
				point.DataPoints.Add(new NPointDataPoint(xValues[i], yValues[i]));
			}

			// Add a constline for the left axis
			m_XReferenceLine = new NAxisReferenceLine();
			m_XReferenceLine.Stroke = new NStroke(1, NColor.Red);
			m_XReferenceLine.Value = 40;
			m_XReferenceLine.Text = "X Reference Line";
			m_XReferenceLine.TextStyle = new NTextStyle();
            m_XReferenceLine.TextStyle.Fill = new NColorFill(NColor.Red);
            chart.Axes[ENCartesianAxis.PrimaryX].ReferenceLines.Add(m_XReferenceLine);

			// Add a constline for the bottom axis
			m_YReferenceLine = new NAxisReferenceLine();
			m_YReferenceLine.Stroke = new NStroke(1, NColor.Green);
			m_YReferenceLine.Value = 60;
			m_YReferenceLine.Text = "Y Reference Line";
			m_YReferenceLine.TextStyle = new NTextStyle();
            m_YReferenceLine.TextStyle.Fill = new NColorFill(NColor.Green);
            chart.Axes[ENCartesianAxis.PrimaryY].ReferenceLines.Add(m_YReferenceLine);

			// apply style sheet
			chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));

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

			stack.Add(new NLabel("Y Axis Reference Line"));

			NNumericUpDown yReferenceLineValueUpDown = new NNumericUpDown();
			yReferenceLineValueUpDown.ValueChanged +=OnYReferenceLineValueUpDownValueChanged;
			yReferenceLineValueUpDown.Value = m_YReferenceLine.Value;
			stack.Add(NPairBox.Create("Value:", yReferenceLineValueUpDown));

			NCheckBox yReferenceLineIncludeInAxisRangeCheckBox = new NCheckBox("Include Value in Axis Range");
			yReferenceLineIncludeInAxisRangeCheckBox.Checked = m_YReferenceLine.IncludeValueInAxisRange;
			yReferenceLineIncludeInAxisRangeCheckBox.CheckedChanged += OnYReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged;
			stack.Add(yReferenceLineIncludeInAxisRangeCheckBox);

			NCheckBox yReferenceLinePaintAfterSeriesCheckBox = new NCheckBox("Paint After Series");
			yReferenceLinePaintAfterSeriesCheckBox.Checked = m_YReferenceLine.PaintAfterChartContent;
			yReferenceLinePaintAfterSeriesCheckBox.CheckedChanged += OnYReferenceLinePaintAfterSeriesCheckBoxCheckedChanged;
			stack.Add(yReferenceLinePaintAfterSeriesCheckBox);

			NComboBox yTextAlignmentComboBox = new NComboBox();
			yTextAlignmentComboBox.Items.FillFromEnum();
			yTextAlignmentComboBox.SelectedIndex = (int)m_YReferenceLine.TextAlignment;
			yTextAlignmentComboBox.SelectedIndexChanged += OnYTextAlignmentComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Text Alignment:", yTextAlignmentComboBox));

			stack.Add(new NLabel("X Axis Reference Line"));

			NNumericUpDown xReferenceLineValueUpDown = new NNumericUpDown();
			xReferenceLineValueUpDown.Value = m_XReferenceLine.Value;
			xReferenceLineValueUpDown.ValueChanged += OnXReferenceLineValueUpDownValueChanged;
			stack.Add(NPairBox.Create("Value:", xReferenceLineValueUpDown));

			NCheckBox xReferenceLinePaintAfterSeriesCheckBox = new NCheckBox("Paint After Series");
			xReferenceLinePaintAfterSeriesCheckBox.Checked = m_XReferenceLine.PaintAfterChartContent;
			xReferenceLinePaintAfterSeriesCheckBox.CheckedChanged += OnXReferenceLinePaintAfterSeriesCheckBoxCheckedChanged;
			stack.Add(xReferenceLinePaintAfterSeriesCheckBox);

			NCheckBox xReferenceLineIncludeInAxisRangeCheckBox = new NCheckBox("Include Value in Axis Range");
			xReferenceLineIncludeInAxisRangeCheckBox.Checked = m_YReferenceLine.IncludeValueInAxisRange;
			xReferenceLineIncludeInAxisRangeCheckBox.CheckedChanged += OnXReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged;
			stack.Add(xReferenceLineIncludeInAxisRangeCheckBox);

			NComboBox xTextAlignmentComboBox = new NComboBox();
			xTextAlignmentComboBox.Items.FillFromEnum();
			xTextAlignmentComboBox.SelectedIndex = (int)m_XReferenceLine.TextAlignment;
			xTextAlignmentComboBox.SelectedIndexChanged += OnXTextAlignmentComboBoxSelectedIndexChanged;
			stack.Add(NPairBox.Create("Text Alignment:", xTextAlignmentComboBox));

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

This example demonstrates how to add axis reference lines.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnXReferenceLineValueUpDownValueChanged(NValueChangeEventArgs arg) { m_XReferenceLine.Value = ((NNumericUpDown)arg.TargetNode).Value; } void OnXReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_XReferenceLine.IncludeValueInAxisRange = ((NCheckBox)arg.TargetNode).Checked; } void OnXReferenceLinePaintAfterSeriesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_XReferenceLine.PaintAfterChartContent = ((NCheckBox)arg.TargetNode).Checked; } void OnXTextAlignmentComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_XReferenceLine.TextAlignment = (ENContentAlignment)((NComboBox)arg.TargetNode).SelectedIndex; } void OnYReferenceLineValueUpDownValueChanged(NValueChangeEventArgs arg) { m_YReferenceLine.Value = ((NNumericUpDown)arg.TargetNode).Value; } void OnYReferenceLineIncludeInAxisRangeCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_YReferenceLine.IncludeValueInAxisRange = ((NCheckBox)arg.TargetNode).Checked; } void OnYReferenceLinePaintAfterSeriesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_YReferenceLine.PaintAfterChartContent = ((NCheckBox)arg.TargetNode).Checked; } void OnYTextAlignmentComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { m_YReferenceLine.TextAlignment = (ENContentAlignment)((NComboBox)arg.TargetNode).SelectedIndex; } #endregion #region Fields NAxisReferenceLine m_XReferenceLine; NAxisReferenceLine m_YReferenceLine; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Axis Reference Lines Example for Blazor Solution