This example demonstrates how to dock axes to different sides of the chart (axis dock zones).

| 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 - NAxisDockingExample";
// 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 Docking";
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
// clear the default chart axes
chart.Axes.Clear();
m_RedAxis = CreateLinearAxis(ENCartesianAxisDockZone.Left, NColor.Red);
chart.Axes.Add(m_RedAxis);
m_GreenAxis = CreateLinearAxis(ENCartesianAxisDockZone.Left, NColor.Green);
chart.Axes.Add(m_GreenAxis);
// Add a custom vertical axis
m_BlueAxis = CreateLinearAxis(ENCartesianAxisDockZone.Left, NColor.Blue);
chart.Axes.Add(m_BlueAxis);
chart.Axes.Add(NCartesianChart.CreateDockedAxis(ENCartesianAxisDockZone.Bottom, ENScaleType.Ordinal, true));
// create three line series and dispay them on three vertical axes (red, green and blue axis)
NLineSeries line1 = CreateLineSeries(NColor.Red, NColor.DarkRed, 10, 20);
chart.Series.Add(line1);
NLineSeries line2 = CreateLineSeries(NColor.Green, NColor.DarkGreen, 50, 100);
chart.Series.Add(line2);
NLineSeries line3 = CreateLineSeries(NColor.Blue, NColor.DarkBlue, 100, 200);
chart.Series.Add(line3);
line1.VerticalAxis = m_RedAxis;
line2.VerticalAxis = m_GreenAxis;
line3.VerticalAxis = m_BlueAxis;
return chartViewWithCommandBars;
}
private NComboBox CreateAxisZoneCombo()
{
NComboBox axisZoneComboBox = new NComboBox();
axisZoneComboBox.Items.Add(new NComboBoxItem("Left"));
axisZoneComboBox.Items.Add(new NComboBoxItem("Right"));
axisZoneComboBox.SelectedIndex = 0;
axisZoneComboBox.SelectedIndexChanged += OnAxisZoneComboBoxSelectedIndexChanged;
return axisZoneComboBox;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
m_RedAxisZoneComboBox = CreateAxisZoneCombo();
stack.Add(NPairBox.Create("Red Axis Dock Zone:", m_RedAxisZoneComboBox));
m_GreenAxisZoneComboBox = CreateAxisZoneCombo();
stack.Add(NPairBox.Create("Green Axis Dock Zone:", m_GreenAxisZoneComboBox));
m_BlueAxisZoneComboBox = CreateAxisZoneCombo();
stack.Add(NPairBox.Create("Blue Axis Dock Zone:", m_BlueAxisZoneComboBox));
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to dock axes to different sides of the chart (axis dock zones).
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"),
("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html"),
};
}
#endregion
#region Implementation
private NCartesianAxis CreateLinearAxis(ENCartesianAxisDockZone dockZone, NColor color)
{
NCartesianAxis axis = new NCartesianAxis();
axis.Scale = CreateLinearScale(color);
axis.Anchor = new NDockCartesianAxisAnchor(dockZone);
return axis;
}
private NLinearScale CreateLinearScale(NColor color)
{
NLinearScale linearScale = new NLinearScale();
linearScale.Ruler.Stroke = new NStroke(1, color);
linearScale.InnerMajorTicks.Stroke = new NStroke(color);
linearScale.OuterMajorTicks.Stroke = new NStroke(color);
linearScale.MajorGridLines.Visible = false;
linearScale.Labels.Style.TextStyle.Fill = new NColorFill(color);
return linearScale;
}
private NLineSeries CreateLineSeries(NColor lightColor, NColor color, int begin, int end)
{
// Add a line series
NLineSeries line = new NLineSeries();
for (int i = 0; i < 5; i++)
{
line.DataPoints.Add(new NLineDataPoint(m_Random.Next(begin, end)));
}
line.Stroke = new NStroke(2, color);
NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
dataLabelStyle.Format = "";
dataLabelStyle.TextStyle.Background.Visible = false;
dataLabelStyle.ArrowStroke.Width = 0;
dataLabelStyle.ArrowLength = 10;
dataLabelStyle.TextStyle.Font = new NFont("Arial", 8);
dataLabelStyle.TextStyle.Background.Visible = true;
line.DataLabelStyle = dataLabelStyle;
NMarkerStyle markerStyle = new NMarkerStyle();
markerStyle.Visible = true;
markerStyle.Border = new NStroke(color);
markerStyle.Fill = new NColorFill(lightColor);
markerStyle.Shape = ENPointShape3D.Ellipse;
markerStyle.Size = new NSize(5, 5);
line.MarkerStyle = markerStyle;
return line;
}
#endregion
#region Event Handlers
void OnAxisZoneComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
if (m_RedAxisZoneComboBox.SelectedIndex == 0)
{
m_RedAxis.Anchor = new NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Left);
}
else
{
m_RedAxis.Anchor = new NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Right);
}
if (m_GreenAxisZoneComboBox.SelectedIndex == 0)
{
m_GreenAxis.Anchor = new NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Left);
}
else
{
m_GreenAxis.Anchor = new NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Right);
}
if (m_BlueAxisZoneComboBox.SelectedIndex == 0)
{
m_BlueAxis.Anchor = new NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Left);
}
else
{
m_BlueAxis.Anchor = new NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Right);
}
}
#endregion
#region Fields
Random m_Random = new Random();
NCartesianAxis m_RedAxis;
NCartesianAxis m_GreenAxis;
NCartesianAxis m_BlueAxis;
NComboBox m_RedAxisZoneComboBox;
NComboBox m_GreenAxisZoneComboBox;
NComboBox m_BlueAxisZoneComboBox;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
} | 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
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 - NAxisDockingExample"
' 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 Docking"
Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)
' clear the default chart axes
chart.Axes.Clear()
m_RedAxis = CreateLinearAxis(ENCartesianAxisDockZone.Left, NColor.Red)
chart.Axes.Add(m_RedAxis)
m_GreenAxis = CreateLinearAxis(ENCartesianAxisDockZone.Left, NColor.Green)
chart.Axes.Add(m_GreenAxis)
' Add a custom vertical axis
m_BlueAxis = CreateLinearAxis(ENCartesianAxisDockZone.Left, NColor.Blue)
chart.Axes.Add(m_BlueAxis)
chart.Axes.Add(NCartesianChart.CreateDockedAxis(ENCartesianAxisDockZone.Bottom, ENScaleType.Ordinal, True))
' create three line series and dispay them on three vertical axes (red, green and blue axis)
Dim line1 = CreateLineSeries(NColor.Red, NColor.DarkRed, 10, 20)
chart.Series.Add(line1)
Dim line2 = CreateLineSeries(NColor.Green, NColor.DarkGreen, 50, 100)
chart.Series.Add(line2)
Dim line3 = CreateLineSeries(NColor.Blue, NColor.DarkBlue, 100, 200)
chart.Series.Add(line3)
line1.VerticalAxis = m_RedAxis
line2.VerticalAxis = m_GreenAxis
line3.VerticalAxis = m_BlueAxis
Return chartViewWithCommandBars
End Function
Private Function CreateAxisZoneCombo() As NComboBox
Dim axisZoneComboBox As NComboBox = New NComboBox()
axisZoneComboBox.Items.Add(New NComboBoxItem("Left"))
axisZoneComboBox.Items.Add(New NComboBoxItem("Right"))
axisZoneComboBox.SelectedIndex = 0
axisZoneComboBox.SelectedIndexChanged += AddressOf OnAxisZoneComboBoxSelectedIndexChanged
Return axisZoneComboBox
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
m_RedAxisZoneComboBox = CreateAxisZoneCombo()
stack.Add(NPairBox.Create("Red Axis Dock Zone:", m_RedAxisZoneComboBox))
m_GreenAxisZoneComboBox = CreateAxisZoneCombo()
stack.Add(NPairBox.Create("Green Axis Dock Zone:", m_GreenAxisZoneComboBox))
m_BlueAxisZoneComboBox = CreateAxisZoneCombo()
stack.Add(NPairBox.Create("Blue Axis Dock Zone:", m_BlueAxisZoneComboBox))
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how to dock axes to different sides of the chart (axis dock zones).
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Common Axis Functionality", "https://www.nevron.com/docs/openvision/chart-common-axis-functionality.html")}
End Function
#End Region
#Region "Implementation"
Private Function CreateLinearAxis(dockZone As ENCartesianAxisDockZone, color As NColor) As NCartesianAxis
Dim axis As NCartesianAxis = New NCartesianAxis()
axis.Scale = CreateLinearScale(color)
axis.Anchor = New NDockCartesianAxisAnchor(dockZone)
Return axis
End Function
Private Function CreateLinearScale(color As NColor) As NLinearScale
Dim linearScale As NLinearScale = New NLinearScale()
linearScale.Ruler.Stroke = New NStroke(1, color)
linearScale.InnerMajorTicks.Stroke = New NStroke(color)
linearScale.OuterMajorTicks.Stroke = New NStroke(color)
linearScale.MajorGridLines.Visible = False
linearScale.Labels.Style.TextStyle.Fill = New NColorFill(color)
Return linearScale
End Function
Private Function CreateLineSeries(lightColor As NColor, color As NColor, begin As Integer, [end] As Integer) As NLineSeries
' Add a line series
Dim line As NLineSeries = New NLineSeries()
For i = 0 To 4
line.DataPoints.Add(New NLineDataPoint(m_Random.Next(begin, [end])))
Next
line.Stroke = New NStroke(2, color)
Dim dataLabelStyle As NDataLabelStyle = New NDataLabelStyle()
dataLabelStyle.Format = ""
dataLabelStyle.TextStyle.Background.Visible = False
dataLabelStyle.ArrowStroke.Width = 0
dataLabelStyle.ArrowLength = 10
dataLabelStyle.TextStyle.Font = New NFont("Arial", 8)
dataLabelStyle.TextStyle.Background.Visible = True
line.DataLabelStyle = dataLabelStyle
Dim markerStyle As NMarkerStyle = New NMarkerStyle()
markerStyle.Visible = True
markerStyle.Border = New NStroke(color)
markerStyle.Fill = New NColorFill(lightColor)
markerStyle.Shape = ENPointShape3D.Ellipse
markerStyle.Size = New NSize(5, 5)
line.MarkerStyle = markerStyle
Return line
End Function
#End Region
#Region "Event Handlers"
Private Sub OnAxisZoneComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
If m_RedAxisZoneComboBox.SelectedIndex = 0 Then
m_RedAxis.Anchor = New NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Left)
Else
m_RedAxis.Anchor = New NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Right)
End If
If m_GreenAxisZoneComboBox.SelectedIndex = 0 Then
m_GreenAxis.Anchor = New NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Left)
Else
m_GreenAxis.Anchor = New NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Right)
End If
If m_BlueAxisZoneComboBox.SelectedIndex = 0 Then
m_BlueAxis.Anchor = New NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Left)
Else
m_BlueAxis.Anchor = New NDockCartesianAxisAnchor(ENCartesianAxisDockZone.Right)
End If
End Sub
#End Region
#Region "Fields"
Private m_Random As Random = New Random()
Private m_RedAxis As NCartesianAxis
Private m_GreenAxis As NCartesianAxis
Private m_BlueAxis As NCartesianAxis
Private m_RedAxisZoneComboBox As NComboBox
Private m_GreenAxisZoneComboBox As NComboBox
Private m_BlueAxisZoneComboBox As NComboBox
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class