Scale Ruler Caps 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.

Scale Ruler Caps Example for WPF Description

This example demonstrates how to alter the appearance of axis ruler caps.


Scale Ruler Caps Example

C# Scale Ruler Caps Example Code for Nevron Chart for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Dom;
using Nevron.Nov.Examples.ExamplesUI;
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 - NScaleRulerCapsExample";

			// 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 Ruler Caps";

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

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

			// feed some random data 
			NPointSeries point = new NPointSeries();
			point.UseXValues = true;
			point.DataLabelStyle = new NDataLabelStyle(false);

			// fill in some random data
			Random random = new Random();

			for (int i = 0; i < 30; i++)
			{
				point.DataPoints.Add(new NPointDataPoint(5 + random.Next(90), 5 + random.Next(90)));
			}

			m_Chart.Series.Add(point);

			// X Axis
			NLinearScale xScale = new NLinearScale();
			xScale.MajorGridLines = CreateScaleGrid();

			NCustomScaleBreak xScaleBreak = new NCustomScaleBreak();

			xScaleBreak.Style = ENScaleBreakStyle.Line;
			xScaleBreak.Fill = new NColorFill(new NColor(NColor.Orange, 124));
			xScaleBreak.Length = 20;
			xScaleBreak.Range = new NRange(29, 41);

			xScale.ScaleBreaks.Add(xScaleBreak);

			// add an interlaced strip to the X axis
			NScaleStrip xInterlacedStrip = new NScaleStrip();

			xInterlacedStrip.Interlaced = true;
			xInterlacedStrip.Fill = new NColorFill(new NColor(NColor.Beige, 125));

			xScale.Strips.Add(xInterlacedStrip);

			NCartesianAxis xAxis = m_Chart.Axes[ENCartesianAxis.PrimaryX];
			xAxis.Scale = xScale;

			NDockCartesianAxisAnchor xAxisAnchor = new NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Bottom);
			xAxisAnchor.BeforeSpace = 10;
			xAxis.Anchor = xAxisAnchor;

			// Y Axis
			NLinearScale yScale = new NLinearScale();
			yScale.MajorGridLines = CreateScaleGrid();

			NCustomScaleBreak yScaleBreak = new NCustomScaleBreak();

			yScaleBreak.Style = ENScaleBreakStyle.Line;
			yScaleBreak.Fill = new NColorFill(new NColor(NColor.Orange, 124));
			yScaleBreak.Length = 20;
			yScaleBreak.Range = new NRange(29, 41);

			yScale.ScaleBreaks.Add(yScaleBreak);

			// add an interlaced strip to the Y axis
			NScaleStrip yInterlacedStrip = new NScaleStrip();
			yInterlacedStrip.Interlaced = true;
			yInterlacedStrip.Fill = new NColorFill(new NColor(NColor.Beige, 125));
			yInterlacedStrip.Interval = 1;
			yInterlacedStrip.Length = 1;
			yScale.Strips.Add(yInterlacedStrip);

			NCartesianAxis yAxis = m_Chart.Axes[ENCartesianAxis.PrimaryY];
			yAxis.Scale = yScale;

			NDockCartesianAxisAnchor yAxisAnchor = new NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Left);
			yAxisAnchor.BeforeSpace = 10;
			yAxis.Anchor = yAxisAnchor;

			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_BeginCapShapeComboBox = new NComboBox();
			m_BeginCapShapeComboBox.Items.FillFromEnum();
			stack.Add(NPairBox.Create("Begin Cap Shape:", m_BeginCapShapeComboBox));
			m_BeginCapShapeComboBox.SelectedIndex = (int)ENCapShape.Ellipse;

			m_ScaleBreakCapShapeComboBox = new NComboBox();
			m_ScaleBreakCapShapeComboBox.Items.FillFromEnum();
			stack.Add(NPairBox.Create("Scale Break Cap Shape:", m_ScaleBreakCapShapeComboBox));
			m_ScaleBreakCapShapeComboBox.SelectedIndex = (int)ENCapShape.VerticalLine;

			m_EndCapShapeComboBox = new NComboBox();
			m_EndCapShapeComboBox.Items.FillFromEnum();
			stack.Add(NPairBox.Create("End Cap Shape:", m_EndCapShapeComboBox));
			m_EndCapShapeComboBox.SelectedIndex = (int)ENCapShape.Arrow;

			m_PaintOnScaleBreaksCheckBox = new NCheckBox("Paint on Scale Breaks");
			stack.Add(m_PaintOnScaleBreaksCheckBox);
			m_PaintOnScaleBreaksCheckBox.Checked = false;

			m_SizeUpDown = new NNumericUpDown();
			stack.Add(NPairBox.Create("Cap Size:", m_SizeUpDown));
			m_SizeUpDown.Value = 5;

			// wire for events
			m_BeginCapShapeComboBox.SelectedIndexChanged += OnRulerStyleChanged;
			m_ScaleBreakCapShapeComboBox.SelectedIndexChanged += OnRulerStyleChanged;
			m_EndCapShapeComboBox.SelectedIndexChanged += OnRulerStyleChanged;
			m_PaintOnScaleBreaksCheckBox.CheckedChanged += OnRulerStyleChanged;
			m_SizeUpDown.ValueChanged += OnRulerStyleChanged;

			OnRulerStyleChanged(null);

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

This example demonstrates how to alter the appearance of axis ruler caps.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html"), }; } #endregion #region Implementation private void UpdateRulerStyleForAxis(NCartesianAxis axis) { NStandardScale scale = (NStandardScale)axis.Scale; NSize capSize = new NSize(m_SizeUpDown.Value, m_SizeUpDown.Value); // apply style to begin and end caps scale.Ruler.BeginCap = new NScaleRulerCapStyle((ENCapShape)m_BeginCapShapeComboBox.SelectedIndex, capSize, 0, new NColorFill(NColor.Black), new NStroke(NColor.Black)); scale.Ruler.EndCap = new NScaleRulerCapStyle((ENCapShape)m_EndCapShapeComboBox.SelectedIndex, capSize, 3, new NColorFill(NColor.Black), new NStroke(NColor.Black)); scale.Ruler.ScaleBreakCap = new NScaleRulerCapStyle((ENCapShape)m_ScaleBreakCapShapeComboBox.SelectedIndex, capSize, 0, new NColorFill(NColor.Black), new NStroke(NColor.Black)); scale.Ruler.PaintOnScaleBreaks = m_PaintOnScaleBreaksCheckBox.Checked; } private NScaleGridLines CreateScaleGrid() { NScaleGridLines scaleGrid = new NScaleGridLines(); scaleGrid.Visible = true; scaleGrid.Stroke = new NStroke(1, NColor.Gray, ENDashStyle.Dash); return scaleGrid; } #endregion #region Event Handlers private void OnRulerStyleChanged(NValueChangeEventArgs arg) { UpdateRulerStyleForAxis(m_Chart.Axes[ENCartesianAxis.PrimaryX]); UpdateRulerStyleForAxis(m_Chart.Axes[ENCartesianAxis.PrimaryY]); } #endregion #region Fields NCartesianChart m_Chart; NComboBox m_BeginCapShapeComboBox; NComboBox m_ScaleBreakCapShapeComboBox; NComboBox m_EndCapShapeComboBox; NCheckBox m_PaintOnScaleBreaksCheckBox; NNumericUpDown m_SizeUpDown; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Scale Ruler Caps Example for WPF Solution

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

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Examples.ExamplesUI
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf
Imports System

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 - NScaleRulerCapsExample"

		' 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 = "Axis Ruler Caps"

            ' configure chart
            m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
            m_Chart.Padding = New NMargins(20)

            ' configure axes
            m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear)

            ' feed some random data 
            Dim point As NPointSeries = New NPointSeries()
            point.UseXValues = True
            point.DataLabelStyle = New NDataLabelStyle(False)

            ' fill in some random data
            Dim random As Random = New Random()

            For i = 0 To 29
                point.DataPoints.Add(New NPointDataPoint(5 + random.Next(90), 5 + random.Next(90)))
            Next

            m_Chart.Series.Add(point)

            ' X Axis
            Dim xScale As NLinearScale = New NLinearScale()
            xScale.MajorGridLines = CreateScaleGrid()

            Dim xScaleBreak As NCustomScaleBreak = New NCustomScaleBreak()

            xScaleBreak.Style = ENScaleBreakStyle.Line
            xScaleBreak.Fill = New NColorFill(New NColor(NColor.Orange, 124))
            xScaleBreak.Length = 20
            xScaleBreak.Range = New NRange(29, 41)

            xScale.ScaleBreaks.Add(xScaleBreak)

            ' add an interlaced strip to the X axis
            Dim xInterlacedStrip As NScaleStrip = New NScaleStrip()

            xInterlacedStrip.Interlaced = True
            xInterlacedStrip.Fill = New NColorFill(New NColor(NColor.Beige, 125))

            xScale.Strips.Add(xInterlacedStrip)

            Dim xAxis = m_Chart.Axes(ENCartesianAxis.PrimaryX)
            xAxis.Scale = xScale

            Dim xAxisAnchor As NDockCartesianAxisAnchor = New NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Bottom)
            xAxisAnchor.BeforeSpace = 10
            xAxis.Anchor = xAxisAnchor

            ' Y Axis
            Dim yScale As NLinearScale = New NLinearScale()
            yScale.MajorGridLines = CreateScaleGrid()

            Dim yScaleBreak As NCustomScaleBreak = New NCustomScaleBreak()

            yScaleBreak.Style = ENScaleBreakStyle.Line
            yScaleBreak.Fill = New NColorFill(New NColor(NColor.Orange, 124))
            yScaleBreak.Length = 20
            yScaleBreak.Range = New NRange(29, 41)

            yScale.ScaleBreaks.Add(yScaleBreak)

            ' add an interlaced strip to the Y axis
            Dim yInterlacedStrip As NScaleStrip = New NScaleStrip()
            yInterlacedStrip.Interlaced = True
            yInterlacedStrip.Fill = New NColorFill(New NColor(NColor.Beige, 125))
            yInterlacedStrip.Interval = 1
            yInterlacedStrip.Length = 1
            yScale.Strips.Add(yInterlacedStrip)

            Dim yAxis = m_Chart.Axes(ENCartesianAxis.PrimaryY)
            yAxis.Scale = yScale

            Dim yAxisAnchor As NDockCartesianAxisAnchor = New NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Left)
            yAxisAnchor.BeforeSpace = 10
            yAxis.Anchor = yAxisAnchor

            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)

            m_BeginCapShapeComboBox = New NComboBox()
            m_BeginCapShapeComboBox.Items.FillFromEnum(Of ENCapShape)()
            stack.Add(NPairBox.Create("Begin Cap Shape:", m_BeginCapShapeComboBox))
            m_BeginCapShapeComboBox.SelectedIndex = CInt(ENCapShape.Ellipse)

            m_ScaleBreakCapShapeComboBox = New NComboBox()
            m_ScaleBreakCapShapeComboBox.Items.FillFromEnum(Of ENCapShape)()
            stack.Add(NPairBox.Create("Scale Break Cap Shape:", m_ScaleBreakCapShapeComboBox))
            m_ScaleBreakCapShapeComboBox.SelectedIndex = CInt(ENCapShape.VerticalLine)

            m_EndCapShapeComboBox = New NComboBox()
            m_EndCapShapeComboBox.Items.FillFromEnum(Of ENCapShape)()
            stack.Add(NPairBox.Create("End Cap Shape:", m_EndCapShapeComboBox))
            m_EndCapShapeComboBox.SelectedIndex = CInt(ENCapShape.Arrow)

            m_PaintOnScaleBreaksCheckBox = New NCheckBox("Paint on Scale Breaks")
            stack.Add(m_PaintOnScaleBreaksCheckBox)
            m_PaintOnScaleBreaksCheckBox.Checked = False

            m_SizeUpDown = New NNumericUpDown()
            stack.Add(NPairBox.Create("Cap Size:", m_SizeUpDown))
            m_SizeUpDown.Value = 5

            ' wire for events
            Me.m_BeginCapShapeComboBox.SelectedIndexChanged += AddressOf OnRulerStyleChanged
            Me.m_ScaleBreakCapShapeComboBox.SelectedIndexChanged += AddressOf OnRulerStyleChanged
            Me.m_EndCapShapeComboBox.SelectedIndexChanged += AddressOf OnRulerStyleChanged
            Me.m_PaintOnScaleBreaksCheckBox.CheckedChanged += AddressOf OnRulerStyleChanged
            Me.m_SizeUpDown.ValueChanged += AddressOf OnRulerStyleChanged

            OnRulerStyleChanged(Nothing)

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

This example demonstrates how to alter the appearance of axis ruler caps.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"), ("Scales Overview", "https://www.nevron.com/docs/openvision/scales-overview.html"), ("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html"), ("Stroke", "https://www.nevron.com/docs/openvision/graphics-stroke.html")} End Function #End Region #Region "Implementation" Private Sub UpdateRulerStyleForAxis(axis As NCartesianAxis) Dim scale = CType(axis.Scale, NStandardScale) Dim capSize As NSize = New NSize(m_SizeUpDown.Value, m_SizeUpDown.Value) ' apply style to begin and end caps scale.Ruler.BeginCap = New NScaleRulerCapStyle(m_BeginCapShapeComboBox.SelectedIndex, capSize, 0, New NColorFill(NColor.Black), New NStroke(NColor.Black)) scale.Ruler.EndCap = New NScaleRulerCapStyle(m_EndCapShapeComboBox.SelectedIndex, capSize, 3, New NColorFill(NColor.Black), New NStroke(NColor.Black)) scale.Ruler.ScaleBreakCap = New NScaleRulerCapStyle(m_ScaleBreakCapShapeComboBox.SelectedIndex, capSize, 0, New NColorFill(NColor.Black), New NStroke(NColor.Black)) scale.Ruler.PaintOnScaleBreaks = m_PaintOnScaleBreaksCheckBox.Checked End Sub Private Function CreateScaleGrid() As NScaleGridLines Dim scaleGrid As NScaleGridLines = New NScaleGridLines() scaleGrid.Visible = True scaleGrid.Stroke = New NStroke(1, NColor.Gray, ENDashStyle.Dash) Return scaleGrid End Function #End Region #Region "Event Handlers" Private Sub OnRulerStyleChanged(arg As NValueChangeEventArgs) Me.UpdateRulerStyleForAxis(m_Chart.Axes(ENCartesianAxis.PrimaryX)) Me.UpdateRulerStyleForAxis(m_Chart.Axes(ENCartesianAxis.PrimaryY)) End Sub #End Region #Region "Fields" Private m_Chart As NCartesianChart Private m_BeginCapShapeComboBox As NComboBox Private m_ScaleBreakCapShapeComboBox As NComboBox Private m_EndCapShapeComboBox As NComboBox Private m_PaintOnScaleBreaksCheckBox As NCheckBox Private m_SizeUpDown As NNumericUpDown #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) Scale Ruler Caps Example for WPF Solution