In this example, the logarithm base is limited to a few predefined values, but it is possible to set the logarithm base to any integer value.

| 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 - NScalesLogarithmicExample";
// 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()
{
NStackPanel stack = new NStackPanel();
stack.HorizontalPlacement = ENHorizontalPlacement.Left;
NStackPanel controlStack = new NStackPanel();
stack.Add(controlStack);
// create the radial gauge
m_RadialGauge = new NRadialGauge();
m_RadialGauge.PreferredSize = defaultRadialGaugeSize;
m_RadialGauge.Dial = new NDial(ENDialShape.CutCircle, new NEdgeDialRim());
m_RadialGauge.SweepAngle = new NAngle(-180, NUnit.Degree);
m_RadialGauge.BeginAngle = new NAngle(-1, NUnit.Degree);
NAdvancedGradientFill advancedGradient = new NAdvancedGradientFill();
advancedGradient.BackgroundColor = NColor.DarkCyan;
advancedGradient.Points.Add(new NAdvancedGradientPoint(NColor.LightSteelBlue, new NAngle(10, NUnit.Degree), 0.1f, 0, 1.0f, ENAdvancedGradientPointShape.Circle));
m_RadialGauge.Dial.BackgroundFill = advancedGradient;
// configure scale
NGaugeAxis axis = new NGaugeAxis();
m_RadialGauge.Axes.Clear();
m_RadialGauge.Axes.Add(axis);
axis.Range = new NRange(1, 100);
axis.Scale = new NLogarithmicScale();
m_Scale = (NLogarithmicScale)axis.Scale;
m_Scale.SetPredefinedScale(ENPredefinedScaleStyle.Standard);
m_Scale.MajorTickMode = ENMajorTickMode.CustomStep;
m_Scale.CustomStep = 1;
m_Scale.MinTickDistance = 30;
m_Scale.Ruler.Stroke.Width = 0;
m_Scale.Labels.Style.TextStyle.Fill = new NColorFill(NColor.Black);
m_Scale.Labels.Style.TextStyle.Font = new NFont("Microsoft Sans Serif", 8, ENFontStyle.Bold);
m_Scale.OuterMajorTicks.Fill = new NColorFill(NColor.White);
// needle value indicator
m_ValueIndicator = new NNeedleValueIndicator();
m_ValueIndicator.Value = 59;
m_ValueIndicator.Fill = new NStockGradientFill(ENGradientStyle.Horizontal, ENGradientVariant.Variant1, NColor.White, NColor.Red);
m_ValueIndicator.Stroke.Color = NColor.Red;
m_ValueIndicator.EnableDampening = true;
m_ValueIndicator.OffsetFromCenter = -10;
m_RadialGauge.Indicators.Add(m_ValueIndicator);
// add radial gauge
controlStack.Add(m_RadialGauge);
// Timer
m_Timer = new NTimer();
m_Timer.Interval = 200;
m_Timer.Tick += OnTimerTick;
m_Timer.Start();
return stack;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NStackPanel propertyStack = new NStackPanel();
stack.Add(new NUniSizeBoxGroup(propertyStack));
// reversed scale check box
m_ReverseScaleCheckBox = new NCheckBox("Reversed");
m_ReverseScaleCheckBox.CheckedChanged += OnReverseCheckBoxCheckedChange;
m_ReverseScaleCheckBox.Checked = true;
propertyStack.Add(m_ReverseScaleCheckBox);
// logarithmic base
m_LogarithmicBaseComboBox = new NComboBox();
m_LogarithmicBaseComboBox.Items.Add(new NComboBoxItem("10"));
m_LogarithmicBaseComboBox.Items.Add(new NComboBoxItem("5"));
m_LogarithmicBaseComboBox.Items.Add(new NComboBoxItem("2"));
m_LogarithmicBaseComboBox.SelectedIndexChanged += OnLogarithmicBaseComboBoxIndexChanged;
m_LogarithmicBaseComboBox.SelectedIndex = 2;
propertyStack.Add(new NPairBox("Logarithmic Base:", m_LogarithmicBaseComboBox, true));
return stack;
}
public string GetExampleDescription()
{
return @"In this example, the logarithm base is limited to a few predefined values,
but it is possible to set the logarithm base to any integer value.
";
}
///
/// 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"),
("Gauges Axes", "https://www.nevron.com/docs/openvision/gauges-axes.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
private void OnTimerTick()
{
m_FirstIndicatorAngle += 0.02;
double needleValue = 50.0 - Math.Cos(m_FirstIndicatorAngle) * 50.0;
m_ValueIndicator.Value = needleValue;
}
private void OnReverseCheckBoxCheckedChange(NValueChangeEventArgs arg)
{
bool enableInvert = (bool)arg.NewValue;
m_RadialGauge.Axes[0].Scale.Invert = enableInvert;
}
private void OnLogarithmicBaseComboBoxIndexChanged(NValueChangeEventArgs arg)
{
int logBase = (int)arg.NewValue;
switch (logBase)
{
case 0:
m_Scale.LogarithmBase = 10;
break;
case 1:
m_Scale.LogarithmBase = 5;
break;
case 2:
m_Scale.LogarithmBase = 2;
break;
}
}
#endregion
#region Fields
NRadialGauge m_RadialGauge;
NNeedleValueIndicator m_ValueIndicator;
NLogarithmicScale m_Scale;
NTimer m_Timer;
NCheckBox m_ReverseScaleCheckBox;
NComboBox m_LogarithmicBaseComboBox;
double m_FirstIndicatorAngle;
#endregion
#region Static Methods
#endregion
#region Constants
private static readonly NSize defaultRadialGaugeSize = new NSize(300, 300);
#endregion
#region Nested Types
#endregion
}
}