View Range 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.

View Range Example for Blazor Description

This example demonstrates how to explicitly set the axis view range.


Axis View Range Example

C# View Range 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 - NAxisViewRangeExample";

			// 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 View Range";

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

            // configure axes
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);

            m_Chart.Axes[ENCartesianAxis.PrimaryY].ClipMode = ENAxisClipMode.Auto;

            // configure scale
            NLinearScale yScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
            yScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.MajorTick;
            yScale.MinTickDistance = 30;

            // add an interlaced strip to the Y axis
            NScaleStrip interlacedStrip = new NScaleStrip();
            interlacedStrip.Interlaced = true;
            interlacedStrip.Fill = new NColorFill(NColor.Beige);
            yScale.Strips.Add(interlacedStrip);

            OnChangeDataButtonClick(null);

            chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));

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

            m_ViewRangeMode = new NComboBox();
            m_ViewRangeMode.Items.FillFromEnum();
            m_ViewRangeMode.SelectedIndexChanged += OnViewRangeModeSelectedIndexChanged;
            stack.Add(NPairBox.Create("View Range Mode:", m_ViewRangeMode));

            m_ViewRangeMinValue = new NNumericUpDown();
            m_ViewRangeMinValue.ValueChanged += OnViewRangeMinValueChanged;
            stack.Add(NPairBox.Create("View Range Min:", m_ViewRangeMinValue));

            m_ViewRangeMaxValue = new NNumericUpDown();
            m_ViewRangeMaxValue.ValueChanged += OnViewRangMaxValueChanged;
            stack.Add(NPairBox.Create("View Range Max:", m_ViewRangeMaxValue));

            NButton changeDataButton = new NButton("Change Data");
            changeDataButton.Click += OnChangeDataButtonClick;
            stack.Add(changeDataButton);

            m_ViewRangeMode.SelectedIndex = (int)ENAxisViewRangeMode.Auto;
            m_ViewRangeMinValue.Value = 20;
            m_ViewRangeMaxValue.Value = 80;

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

This example demonstrates how to explicitly set the axis view range.

"; } /// /// 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"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnViewRangeMinValueChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryY].MinViewRangeValue = (double)m_ViewRangeMinValue.Value; } private void OnViewRangMaxValueChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryY].MaxViewRangeValue = (double)m_ViewRangeMaxValue.Value; } private void OnViewRangeModeSelectedIndexChanged(NValueChangeEventArgs arg) { ENAxisViewRangeMode viewRangeMode = (ENAxisViewRangeMode)m_ViewRangeMode.SelectedIndex; m_Chart.Axes[ENCartesianAxis.PrimaryY].ViewRangeMode = viewRangeMode; switch (viewRangeMode) { case ENAxisViewRangeMode.Auto: m_ViewRangeMinValue.Enabled = false; m_ViewRangeMaxValue.Enabled = false; break; case ENAxisViewRangeMode.FixedMin: m_ViewRangeMinValue.Enabled = true; m_ViewRangeMaxValue.Enabled = false; break; case ENAxisViewRangeMode.FixedMax: m_ViewRangeMinValue.Enabled = false; m_ViewRangeMaxValue.Enabled = true; break; case ENAxisViewRangeMode.FixedRange: m_ViewRangeMinValue.Enabled = true; m_ViewRangeMaxValue.Enabled = true; break; } } private void OnChangeDataButtonClick(NEventArgs arg) { m_Chart.Series.Clear(); // setup bar series NBarSeries bar = new NBarSeries(); m_Chart.Series.Add(bar); bar.DataLabelStyle = new NDataLabelStyle(false); bar.Stroke = new NStroke(1.5f, NColor.DarkGreen); // fill in some data so that it contains several peaks of data Random random = new Random(); for (int i = 0; i < 25; i++) { double value = random.NextDouble() * 100; NBarDataPoint dataPoint = new NBarDataPoint(value); bar.DataPoints.Add(dataPoint); } } #endregion #region Fields NCartesianChart m_Chart; NComboBox m_ViewRangeMode; NNumericUpDown m_ViewRangeMinValue; NNumericUpDown m_ViewRangeMaxValue; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) View Range Example for Blazor Solution

Related Documentation Links