This example demonstrates how to cross two axes at a specified model offset.

| 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 - NAxisModelCrossingExample";
// 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 Model Crossing";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XYLinear);
NCartesianAxis primaryX = m_Chart.Axes[ENCartesianAxis.PrimaryX];
NCartesianAxis primaryY = m_Chart.Axes[ENCartesianAxis.PrimaryY];
// configure axes
NLinearScale yScale = (NLinearScale)primaryY.Scale;
yScale.MajorGridLines = CreateDottedGrid();
NScaleStrip yStrip = new NScaleStrip(new NColorFill(new NColor(NColor.Beige, 40)), null, true, 0, 0, 1, 1);
yStrip.Interlaced = true;
yScale.Strips.Add(yStrip);
NLinearScale xScale = (NLinearScale)primaryX.Scale;
xScale.MajorGridLines = CreateDottedGrid();
NScaleStrip xStrip = new NScaleStrip(new NColorFill(new NColor(NColor.Beige, 40)), null, true, 0, 0, 1, 1);
xStrip.Interlaced = true;
xScale.Strips.Add(xStrip);
// cross X and Y axes
NCrossCartesianAxisAnchor xCrossAnchor = new NCrossCartesianAxisAnchor(ENCartesianAxisOrientation.Horizontal, ENScaleOrientation.Right, 0.0f, 100.0f);
xCrossAnchor.YAxisCrossing = new NModelAxisCrossing(primaryY, 0, ENAxisCrossAlignment.Center);
primaryX.Anchor = xCrossAnchor;
NCrossCartesianAxisAnchor yCrossAnchor = new NCrossCartesianAxisAnchor(ENCartesianAxisOrientation.Vertical, ENScaleOrientation.Left, 0.0f, 100.0f);
yCrossAnchor.XAxisCrossing = new NModelAxisCrossing(primaryX, 0, ENAxisCrossAlignment.Center);
primaryY.Anchor = yCrossAnchor;
// setup bubble series
NBubbleSeries bubble = new NBubbleSeries();
bubble.Name = "Bubble Series";
bubble.InflateMargins = true;
bubble.DataLabelStyle = new NDataLabelStyle(false);
bubble.UseXValues = true;
// fill with random data
Random random = new Random();
for (int i = 0; i < 10; i++)
{
bubble.DataPoints.Add(new NBubbleDataPoint(random.Next(-20, 20), random.Next(-20, 20), random.Next(1, 6)));
}
m_Chart.Series.Add(bubble);
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.DataPoints));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
stack.Add(new NLabel("Vertical Axis"));
NComboBox verticalAxisAlignmentComboBox = new NComboBox();
verticalAxisAlignmentComboBox.Items.FillFromEnum();
verticalAxisAlignmentComboBox.SelectedIndexChanged += OnVerticalAxisAlignmentComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Alignment:", verticalAxisAlignmentComboBox));
verticalAxisAlignmentComboBox.SelectedIndex = (int)ENAxisCrossAlignment.Center;
NNumericUpDown verticalAxisOffsetUpDown = new NNumericUpDown();
verticalAxisOffsetUpDown.ValueChanged += OnVerticalAxisOffsetUpDownValueChanged;
stack.Add(NPairBox.Create("Offset:", verticalAxisOffsetUpDown));
stack.Add(new NLabel("Horizontal Axis"));
NComboBox horizontalAxisAlignmentComboBox = new NComboBox();
horizontalAxisAlignmentComboBox.Items.FillFromEnum();
horizontalAxisAlignmentComboBox.SelectedIndexChanged += OnHorizontalAxisAlignmentComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Alignment:", horizontalAxisAlignmentComboBox));
horizontalAxisAlignmentComboBox.SelectedIndex = (int)ENAxisCrossAlignment.Center;
NNumericUpDown horizontalAxisOffsetUpDown = new NNumericUpDown();
horizontalAxisOffsetUpDown.ValueChanged += OnHorizontalAxisOffsetUpDownValueChanged;
stack.Add(NPairBox.Create("Offset:", horizontalAxisOffsetUpDown));
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to cross two axes at a specified model offset.
";
}
///
/// 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 NScaleGridLines CreateDottedGrid()
{
NScaleGridLines scaleGrid = new NScaleGridLines();
scaleGrid.Visible = true;
scaleGrid.Stroke.Width = 1;
scaleGrid.Stroke.DashStyle = ENDashStyle.Dot;
scaleGrid.Stroke.Color = NColor.Gray;
return scaleGrid;
}
#endregion
#region Event Handlers
void OnHorizontalAxisOffsetUpDownValueChanged(NValueChangeEventArgs arg)
{
NCrossCartesianAxisAnchor anchor = m_Chart.Axes[ENCartesianAxis.PrimaryX].Anchor as NCrossCartesianAxisAnchor;
(anchor.YAxisCrossing as NModelAxisCrossing).Offset = ((NNumericUpDown)arg.TargetNode).Value;
}
void OnVerticalAxisOffsetUpDownValueChanged(NValueChangeEventArgs arg)
{
NCrossCartesianAxisAnchor anchor = m_Chart.Axes[ENCartesianAxis.PrimaryY].Anchor as NCrossCartesianAxisAnchor;
(anchor.XAxisCrossing as NModelAxisCrossing).Offset = ((NNumericUpDown)arg.TargetNode).Value;
}
void OnHorizontalAxisAlignmentComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
NCrossCartesianAxisAnchor anchor = m_Chart.Axes[ENCartesianAxis.PrimaryX].Anchor as NCrossCartesianAxisAnchor;
(anchor.YAxisCrossing as NModelAxisCrossing).Alignment = (ENAxisCrossAlignment)((NComboBox)arg.TargetNode).SelectedIndex;
}
void OnVerticalAxisAlignmentComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
NCrossCartesianAxisAnchor anchor = m_Chart.Axes[ENCartesianAxis.PrimaryY].Anchor as NCrossCartesianAxisAnchor;
(anchor.XAxisCrossing as NModelAxisCrossing).Alignment = (ENAxisCrossAlignment)((NComboBox)arg.TargetNode).SelectedIndex;
}
#endregion
#region Fields
NCartesianChart m_Chart;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}