This example demonstrates how change the chart orientation. This feature allows you to display left to right and right to left charts

| 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 - NChartOrientationExample";
// 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 = "Chart Orientation";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
m_Chart.Orientation = ENCartesianChartOrientation.LeftToRight;
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
// add interlace stripe
NLinearScale linearScale = m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLinearScale;
NScaleStrip strip = new NScaleStrip(new NColorFill(ENNamedColor.Beige), null, true, 0, 0, 1, 1);
strip.Interlaced = true;
linearScale.Strips.Add(strip);
// add a bar series
m_Bar1 = new NBarSeries();
m_Bar1.MultiBarMode = ENMultiBarMode.Series;
m_Bar1.Name = "Bar 1";
NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
dataLabelStyle.Format = "";
dataLabelStyle.Visible = true;
m_Bar1.DataLabelStyle = dataLabelStyle;
m_Bar1.LegendView.Mode = ENSeriesLegendMode.DataPoints;
m_Chart.Series.Add(m_Bar1);
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.DataPoints));
OnPositiveDataButtonClick(null);
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
NComboBox orientationComboBox = new NComboBox();
orientationComboBox.Items.FillFromEnum();
orientationComboBox.SelectedIndex = (int)m_Chart.Orientation;
orientationComboBox.SelectedIndexChanged += OnOrientationComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Orientation:", orientationComboBox));
NButton positiveDataButton = new NButton("Positive Values");
positiveDataButton.Click += OnPositiveDataButtonClick;
stack.Add(positiveDataButton);
NButton positiveAndNegativeDataButton = new NButton("Positive and Negative Values");
positiveAndNegativeDataButton.Click += OnPositiveAndNegativeDataButtonClick;
stack.Add(positiveAndNegativeDataButton);
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how change the chart orientation. This feature allows you to display left to right and right to left charts
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"),
("Cartesian Chart", "https://www.nevron.com/docs/openvision/cartesian-chart.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
void OnOrientationComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
m_Chart.Orientation = (ENCartesianChartOrientation)((NComboBox)arg.TargetNode).SelectedIndex;
}
void OnPositiveAndNegativeDataButtonClick(NEventArgs arg)
{
m_Bar1.DataPoints.Clear();
Random random = new Random();
for (int i = 0; i < 12; i++)
{
m_Bar1.DataPoints.Add(new NBarDataPoint(random.Next(100) - 50));
}
}
void OnPositiveDataButtonClick(NEventArgs arg)
{
m_Bar1.DataPoints.Clear();
Random random = new Random();
for (int i = 0; i < 12; i++)
{
m_Bar1.DataPoints.Add(new NBarDataPoint(random.Next(90) + 10));
}
}
#endregion
#region Fields
NCartesianChart m_Chart;
NBarSeries m_Bar1;
#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 - NChartOrientationExample"
' 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 = "Chart Orientation"
' configure chart
m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
m_Chart.Orientation = ENCartesianChartOrientation.LeftToRight
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
' add interlace stripe
Dim linearScale As NLinearScale = TryCast(m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale)
Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(ENNamedColor.Beige), Nothing, True, 0, 0, 1, 1)
strip.Interlaced = True
linearScale.Strips.Add(strip)
' add a bar series
m_Bar1 = New NBarSeries()
m_Bar1.MultiBarMode = ENMultiBarMode.Series
m_Bar1.Name = "Bar 1"
Dim dataLabelStyle As NDataLabelStyle = New NDataLabelStyle()
dataLabelStyle.Format = ""
dataLabelStyle.Visible = True
m_Bar1.DataLabelStyle = dataLabelStyle
m_Bar1.LegendView.Mode = ENSeriesLegendMode.DataPoints
m_Chart.Series.Add(m_Bar1)
chartView.Document.StyleSheets.ApplyTheme(New NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.DataPoints))
OnPositiveDataButtonClick(Nothing)
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim orientationComboBox As NComboBox = New NComboBox()
orientationComboBox.Items.FillFromEnum(Of ENCartesianChartOrientation)()
orientationComboBox.SelectedIndex = m_Chart.Orientation
orientationComboBox.SelectedIndexChanged += AddressOf OnOrientationComboBoxSelectedIndexChanged
stack.Add(NPairBox.Create("Orientation:", orientationComboBox))
Dim positiveDataButton As NButton = New NButton("Positive Values")
positiveDataButton.Click += AddressOf OnPositiveDataButtonClick
stack.Add(positiveDataButton)
Dim positiveAndNegativeDataButton As NButton = New NButton("Positive and Negative Values")
positiveAndNegativeDataButton.Click += AddressOf OnPositiveAndNegativeDataButtonClick
stack.Add(positiveAndNegativeDataButton)
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how change the chart orientation. This feature allows you to display left to right and right to left charts
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("3D Charts", "https://www.nevron.com/docs/openvision/3d-charts.html"), ("Cartesian Chart", "https://www.nevron.com/docs/openvision/cartesian-chart.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnOrientationComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
m_Chart.Orientation = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENCartesianChartOrientation)
End Sub
Private Sub OnPositiveAndNegativeDataButtonClick(arg As NEventArgs)
m_Bar1.DataPoints.Clear()
Dim random As Random = New Random()
For i = 0 To 11
m_Bar1.DataPoints.Add(New NBarDataPoint(random.Next(100) - 50))
Next
End Sub
Private Sub OnPositiveDataButtonClick(arg As NEventArgs)
m_Bar1.DataPoints.Clear()
Dim random As Random = New Random()
For i = 0 To 11
m_Bar1.DataPoints.Add(New NBarDataPoint(random.Next(90) + 10))
Next
End Sub
#End Region
#Region "Fields"
Private m_Chart As NCartesianChart
Private m_Bar1 As NBarSeries
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class