Logarithmic Scale Example for WPF

Nevron NOV Chart for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF Chart examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Logarithmic Scale Example for WPF Description

This example demonstrates how to create a logarithmic scale.


Logarithmic Scale Example

C# Logarithmic Scale Example Code for Nevron Chart for WPF
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 WPF Solution

VB.NET Logarithmic Scale Example Code for Nevron Chart for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf

Class MainWindow

#Region "Constructors"

	Public Sub New()
		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NLogarithmicScaleExample"

		' Create the NOV example and its controls
		Dim exampleContent As NWidget = CreateExampleContent()
		Dim exampleControls As NWidget = CreateExampleControls()
		If Not exampleControls Is Nothing Then
			exampleControls.PreferredWidth = 300
		End If

		' Place the example and its controls in a pair box
		Dim pairBox As NPairBox = 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
		Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
		Content = host
	End Sub


#End Region

#Region "Example"

        Public Function CreateExampleContent() As NWidget
            Dim chartViewWithCommandBars As NChartViewWithCommandBars = New NChartViewWithCommandBars()
            Dim chartView = chartViewWithCommandBars.View
            chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)

            ' configure title
            chartView.Surface.Titles(0).Text = "Logarithmic Scale"

            ' configure chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
            m_Chart.SetPredefinedInteractor(ENPredefinedInteractor.DataZoomingAndScrolling)

            ' configure axes
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)

            Dim logarithmicScale As NLogarithmicScale = New NLogarithmicScale()

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

            ' add interlaced stripe 
            Dim strip As NScaleStrip = 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

            Dim line As NLineSeries = New NLineSeries()
            m_Chart.Series.Add(line)

            line.LegendView.Mode = ENSeriesLegendMode.None
            line.InflateMargins = False

            Dim markerStyle As NMarkerStyle = New NMarkerStyle()
            line.MarkerStyle = markerStyle

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

            Dim dataLabelStyle As NDataLabelStyle = 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
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)

            Dim logarithmBaseUpDown As NNumericUpDown = New NNumericUpDown()
            logarithmBaseUpDown.Minimum = 1
            logarithmBaseUpDown.ValueChanged += AddressOf OnLogarithmBaseUpDownValueChanged
            stack.Add(NPairBox.Create("Logarithm Base:", logarithmBaseUpDown))

            Dim invertedCheckBox As NCheckBox = New NCheckBox("Inverted")
            invertedCheckBox.CheckedChanged += AddressOf OnInvertedCheckBoxCheckedChanged
            invertedCheckBox.Checked = False
            stack.Add(invertedCheckBox)

            logarithmBaseUpDown.Value = 10

            Return boxGroup
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create a logarithmic scale.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Logarithmic Scale", "https://www.nevron.com/docs/openvision/logarithmic-scale.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnLogarithmBaseUpDownValueChanged(arg As NValueChangeEventArgs) Dim logScale As NLogarithmicScale = TryCast(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLogarithmicScale) logScale.LogarithmBase = CType(arg.TargetNode, NNumericUpDown).Value End Sub Private Sub OnInvertedCheckBoxCheckedChanged(arg As NValueChangeEventArgs) CType(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLogarithmicScale).Invert = CType(arg.TargetNode, NCheckBox).Checked End Sub #End Region #Region "Fields" Private m_Chart As NCartesianChart #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Logarithmic Scale Example for WPF Solution

Related Documentation Links