Logarithmic Scale 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.

Logarithmic Scale Example for Blazor Description

This example demonstrates how to create a logarithmic scale.


Logarithmic Scale Example

C# Logarithmic Scale 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 - NLogarithmicScaleExample";

			// 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 = "Logarithmic Scale";

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

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

			NLogarithmicScale logarithmicScale = new NLogarithmicScale();

			logarithmicScale.MinorGridLines.Stroke.DashStyle = ENDashStyle.Dot;
			logarithmicScale.MinorTickCount = 3;
			logarithmicScale.MajorTickMode = ENMajorTickMode.CustomStep;

			// add interlaced stripe 
			NScaleStrip strip = new NScaleStrip();
			strip.Fill = new NColorFill(NColor.Beige);
			strip.Interlaced = true;
			logarithmicScale.Strips.Add(strip);

			logarithmicScale.CustomStep = 1;

            m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale = logarithmicScale;

			NLineSeries line = new NLineSeries();
			m_Chart.Series.Add(line);

			line.LegendView.Mode = ENSeriesLegendMode.None;
			line.InflateMargins = false;

			NMarkerStyle markerStyle = new NMarkerStyle();
			line.MarkerStyle = markerStyle;

			markerStyle.Shape = ENPointShape3D.Ellipse;
			markerStyle.Size = new NSize(15, 15);

			NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
			dataLabelStyle.Visible = true;
			dataLabelStyle.Format = "";
			line.DataLabelStyle = dataLabelStyle;

			line.DataPoints.Add(new NLineDataPoint(12));
			line.DataPoints.Add(new NLineDataPoint(100));
			line.DataPoints.Add(new NLineDataPoint(250));
			line.DataPoints.Add(new NLineDataPoint(500));
			line.DataPoints.Add(new NLineDataPoint(1500));
			line.DataPoints.Add(new NLineDataPoint(5500));
			line.DataPoints.Add(new NLineDataPoint(9090));

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

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

			NNumericUpDown logarithmBaseUpDown = new NNumericUpDown();
 			logarithmBaseUpDown.Minimum = 1;
			logarithmBaseUpDown.ValueChanged += OnLogarithmBaseUpDownValueChanged;
			stack.Add(NPairBox.Create("Logarithm Base:", logarithmBaseUpDown));

			NCheckBox invertedCheckBox = new NCheckBox("Inverted");
			invertedCheckBox.CheckedChanged += OnInvertedCheckBoxCheckedChanged;
			invertedCheckBox.Checked = false;
			stack.Add(invertedCheckBox);

			logarithmBaseUpDown.Value = 10;

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

This example demonstrates how to create a logarithmic scale.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Logarithmic Scale", "https://www.nevron.com/docs/openvision/logarithmic-scale.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers void OnLogarithmBaseUpDownValueChanged(NValueChangeEventArgs arg) { NLogarithmicScale logScale = m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLogarithmicScale; logScale.LogarithmBase = ((NNumericUpDown)arg.TargetNode).Value; } void OnInvertedCheckBoxCheckedChanged(NValueChangeEventArgs arg) { ((NLogarithmicScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale).Invert = ((NCheckBox)arg.TargetNode).Checked; } #endregion #region Fields NCartesianChart m_Chart; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Logarithmic Scale Example for Blazor Solution

Related Documentation Links