This example demonstrates how change the chart aspect ratio in 2D.

| Language: C# |
using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Chart.Tools;
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 - NChartAspect3DExample";
// 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();
m_ChartView = chartViewWithCommandBars.View;
m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);
// configure title
m_ChartView.Surface.Titles[0].Text = "Chart Aspect 3D";
// configure chart
NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0];
chart.Interactor = new NInteractor(new NTrackballTool());
chart.Enable3D = true;
chart.ModelWidth = 50;
chart.ModelHeight = 50;
chart.ModelDepth = 50;
m_ModelWidth = 1;
m_ModelHeight = 1;
m_ModelDepth = 1;
chart.FitMode = ENCartesianChartFitMode.Aspect;
chart.Walls[ENChartWall.Back].Width = 0.01f;
chart.Walls[ENChartWall.Bottom].Width = 0.01f;
chart.Walls[ENChartWall.Left].Width = 0.01f;
// apply predefined projection and lighting
chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted);
chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.BrightCameraLight);
// add axis labels
NOrdinalScale ordinalScale = chart.Axes[ENCartesianAxis.Depth].Scale as NOrdinalScale;
ordinalScale.Labels.TextProvider = new NOrdinalScaleLabelTextProvider(new string[] { "Miami", "Chicago", "Los Angeles", "New York" });
ordinalScale.Labels.Style.Angle = new NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0);
ordinalScale = chart.Axes[ENCartesianAxis.PrimaryX].Scale as NOrdinalScale;
ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, true);
ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Back, true);
// add interlace stripe to the Y axis
NLinearScale linearScale = chart.Axes[ENCartesianAxis.PrimaryY].Scale as NLinearScale;
NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
strip.Interlaced = true;
strip.SetShowAtWall(ENChartWall.Back, true);
strip.SetShowAtWall(ENChartWall.Left, true);
linearScale.Strips.Add(strip);
// add the first bar
NBarSeries bar1 = new NBarSeries();
chart.Series.Add(bar1);
bar1.MultiBarMode = ENMultiBarMode.Series;
bar1.Name = "Bar1";
bar1.DataLabelStyle = new NDataLabelStyle(false);
bar1.Stroke = new NStroke(NColor.FromRGB(210, 210, 255));
// add the second bar
NBarSeries bar2 = new NBarSeries();
chart.Series.Add(bar2);
bar2.MultiBarMode = ENMultiBarMode.Series;
bar2.Name = "Bar2";
bar2.DataLabelStyle = new NDataLabelStyle(false);
bar2.Stroke = new NStroke(NColor.FromRGB(210, 255, 210));
// add the third bar
NBarSeries bar3 = new NBarSeries();
chart.Series.Add(bar3);
bar3.MultiBarMode = ENMultiBarMode.Series;
bar3.Name = "Bar3";
bar3.DataLabelStyle = new NDataLabelStyle(false);
bar3.Stroke = new NStroke(NColor.FromRGB(255, 255, 210));
// add the fourth bar
NBarSeries bar4 = new NBarSeries();
chart.Series.Add(bar4);
bar4.MultiBarMode = ENMultiBarMode.Series;
bar4.Name = "Bar4";
bar4.DataLabelStyle = new NDataLabelStyle(false);
bar4.Stroke = new NStroke(NColor.FromRGB(255, 210, 210));
// fill with random data
Random random = new Random();
for (int i = 0; i < 7; i++)
{
bar1.DataPoints.Add(new NBarDataPoint((random.Next() + 1.0) * 30 + 10));
bar2.DataPoints.Add(new NBarDataPoint((random.Next() + 1.0) * 30 + 30));
bar3.DataPoints.Add(new NBarDataPoint((random.Next() + 1.0) * 30 + 50));
bar4.DataPoints.Add(new NBarDataPoint((random.Next() + 1.0) * 30 + 70));
}
// apply theme
m_ChartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0];
NComboBox proportionXComboBox = CreateProportionComboBox();
proportionXComboBox.SelectedIndexChanged += OnProportionXComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Proportion X:", proportionXComboBox));
NComboBox proportionYComboBox = CreateProportionComboBox();
proportionYComboBox.SelectedIndexChanged += OnProportionYComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Proportion Y:", proportionYComboBox));
NComboBox proportionZComboBox = CreateProportionComboBox();
proportionZComboBox.SelectedIndexChanged += OnProportionZComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Proportion Z:", proportionZComboBox));
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how change the chart aspect ratio in 2D.
";
}
///
/// 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
private void NormalizeProportions()
{
NCartesianChart chart = (NCartesianChart)m_ChartView.Surface.Charts[0];
float max = Math.Max(Math.Max(m_ModelWidth, m_ModelHeight), m_ModelDepth);
float scale = 50 / max;
chart.ModelWidth = m_ModelWidth * scale;
chart.ModelHeight = m_ModelHeight * scale;
chart.ModelDepth = m_ModelDepth * scale;
}
private NComboBox CreateProportionComboBox()
{
NComboBox comboBox = new NComboBox();
for (int i = 0; i < 5; i++)
{
comboBox.Items.Add(new NComboBoxItem((i + 1).ToString()));
}
comboBox.SelectedIndex = 0;
return comboBox;
}
#endregion
#region Event Handlers
private void OnProportionXComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
m_ModelWidth = ((int)arg.NewValue + 1);
NormalizeProportions();
}
private void OnProportionYComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
m_ModelHeight = ((int)arg.NewValue + 1);
NormalizeProportions();
}
private void OnProportionZComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
m_ModelDepth = ((int)arg.NewValue + 1);
NormalizeProportions();
}
#endregion
#region Fields
private NChartView m_ChartView;
float m_ModelWidth;
float m_ModelHeight;
float m_ModelDepth;
#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.Chart.Tools
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Forms
Imports System
Public Class Form1
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Text = "NOV WinForms - NChartAspect3DExample"
' 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)
host.Dock = DockStyle.Fill
Controls.Add(host)
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
Dim chartViewWithCommandBars As NChartViewWithCommandBars = New NChartViewWithCommandBars()
m_ChartView = chartViewWithCommandBars.View
m_ChartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)
' configure title
m_ChartView.Surface.Titles(0).Text = "Chart Aspect 3D"
' configure chart
Dim chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart)
chart.Interactor = New NInteractor(New NTrackballTool())
chart.Enable3D = True
chart.ModelWidth = 50
chart.ModelHeight = 50
chart.ModelDepth = 50
m_ModelWidth = 1
m_ModelHeight = 1
m_ModelDepth = 1
chart.FitMode = ENCartesianChartFitMode.Aspect
chart.Walls(ENChartWall.Back).Width = 0.01F
chart.Walls(ENChartWall.Bottom).Width = 0.01F
chart.Walls(ENChartWall.Left).Width = 0.01F
' apply predefined projection and lighting
chart.Projection.SetPredefinedProjection(ENPredefinedProjection.PerspectiveTilted)
chart.LightModel.SetPredefinedLightModel(ENPredefinedLightModel.BrightCameraLight)
' add axis labels
Dim ordinalScale As NOrdinalScale = TryCast(chart.Axes(ENCartesianAxis.Depth).Scale, NOrdinalScale)
ordinalScale.Labels.TextProvider = New NOrdinalScaleLabelTextProvider(New String() {"Miami", "Chicago", "Los Angeles", "New York"})
ordinalScale.Labels.Style.Angle = New NScaleLabelAngle(ENScaleLabelAngleMode.Scale, 0)
ordinalScale = TryCast(chart.Axes(ENCartesianAxis.PrimaryX).Scale, NOrdinalScale)
ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Bottom, True)
ordinalScale.MajorGridLines.SetShowAtWall(ENChartWall.Back, True)
' add interlace stripe to the Y axis
Dim linearScale As NLinearScale = TryCast(chart.Axes(ENCartesianAxis.PrimaryY).Scale, NLinearScale)
Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
strip.Interlaced = True
strip.SetShowAtWall(ENChartWall.Back, True)
strip.SetShowAtWall(ENChartWall.Left, True)
linearScale.Strips.Add(strip)
' add the first bar
Dim bar1 As NBarSeries = New NBarSeries()
chart.Series.Add(bar1)
bar1.MultiBarMode = ENMultiBarMode.Series
bar1.Name = "Bar1"
bar1.DataLabelStyle = New NDataLabelStyle(False)
bar1.Stroke = New NStroke(NColor.FromRGB(210, 210, 255))
' add the second bar
Dim bar2 As NBarSeries = New NBarSeries()
chart.Series.Add(bar2)
bar2.MultiBarMode = ENMultiBarMode.Series
bar2.Name = "Bar2"
bar2.DataLabelStyle = New NDataLabelStyle(False)
bar2.Stroke = New NStroke(NColor.FromRGB(210, 255, 210))
' add the third bar
Dim bar3 As NBarSeries = New NBarSeries()
chart.Series.Add(bar3)
bar3.MultiBarMode = ENMultiBarMode.Series
bar3.Name = "Bar3"
bar3.DataLabelStyle = New NDataLabelStyle(False)
bar3.Stroke = New NStroke(NColor.FromRGB(255, 255, 210))
' add the fourth bar
Dim bar4 As NBarSeries = New NBarSeries()
chart.Series.Add(bar4)
bar4.MultiBarMode = ENMultiBarMode.Series
bar4.Name = "Bar4"
bar4.DataLabelStyle = New NDataLabelStyle(False)
bar4.Stroke = New NStroke(NColor.FromRGB(255, 210, 210))
' fill with random data
Dim random As Random = New Random()
For i = 0 To 6
bar1.DataPoints.Add(New NBarDataPoint((random.Next() + 1.0) * 30 + 10))
bar2.DataPoints.Add(New NBarDataPoint((random.Next() + 1.0) * 30 + 30))
bar3.DataPoints.Add(New NBarDataPoint((random.Next() + 1.0) * 30 + 50))
bar4.DataPoints.Add(New NBarDataPoint((random.Next() + 1.0) * 30 + 70))
Next
' apply theme
m_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)
Dim chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart)
Dim proportionXComboBox As NComboBox = CreateProportionComboBox()
proportionXComboBox.SelectedIndexChanged += AddressOf OnProportionXComboBoxSelectedIndexChanged
stack.Add(NPairBox.Create("Proportion X:", proportionXComboBox))
Dim proportionYComboBox As NComboBox = CreateProportionComboBox()
proportionYComboBox.SelectedIndexChanged += AddressOf OnProportionYComboBoxSelectedIndexChanged
stack.Add(NPairBox.Create("Proportion Y:", proportionYComboBox))
Dim proportionZComboBox As NComboBox = CreateProportionComboBox()
proportionZComboBox.SelectedIndexChanged += AddressOf OnProportionZComboBoxSelectedIndexChanged
stack.Add(NPairBox.Create("Proportion Z:", proportionZComboBox))
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how change the chart aspect ratio in 2D.
"
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"
Private Sub NormalizeProportions()
Dim chart = CType(m_ChartView.Surface.Charts(0), NCartesianChart)
Dim max = Math.Max(Math.Max(m_ModelWidth, m_ModelHeight), m_ModelDepth)
Dim scale = 50 / max
chart.ModelWidth = m_ModelWidth * scale
chart.ModelHeight = m_ModelHeight * scale
chart.ModelDepth = m_ModelDepth * scale
End Sub
Private Function CreateProportionComboBox() As NComboBox
Dim comboBox As NComboBox = New NComboBox()
For i = 0 To 4
comboBox.Items.Add(New NComboBoxItem((i + 1).ToString()))
Next
comboBox.SelectedIndex = 0
Return comboBox
End Function
#End Region
#Region "Event Handlers"
Private Sub OnProportionXComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
m_ModelWidth = CInt(arg.NewValue) + 1
NormalizeProportions()
End Sub
Private Sub OnProportionYComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
m_ModelHeight = CInt(arg.NewValue) + 1
NormalizeProportions()
End Sub
Private Sub OnProportionZComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
m_ModelDepth = CInt(arg.NewValue) + 1
NormalizeProportions()
End Sub
#End Region
#Region "Fields"
Private m_ChartView As NChartView
Private m_ModelWidth As Single
Private m_ModelHeight As Single
Private m_ModelDepth As Single
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class