This example demonstrates how to create a standard bar chart.

| 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 - NStandardBarExample";
// 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);
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
// Set the title
chartView.Surface.Titles[0].Text = "Standard Bar";
// Add an interlace stripe
NLinearScale linearScale = 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);
// Setup a bar series
m_Bar = new NBarSeries();
m_Bar.Name = "Bar Series";
m_Bar.InflateMargins = true;
m_Bar.UseXValues = false;
m_Bar.Shadow = new NShadow(NColor.LightGray, 2, 2);
// Add some data to the bar series
m_Bar.LegendView.Mode = ENSeriesLegendMode.DataPoints;
m_Bar.DataPoints.Add(new NBarDataPoint(18, "C++"));
m_Bar.DataPoints.Add(new NBarDataPoint(15, "Ruby"));
m_Bar.DataPoints.Add(new NBarDataPoint(21, "Python"));
m_Bar.DataPoints.Add(new NBarDataPoint(23, "Java"));
m_Bar.DataPoints.Add(new NBarDataPoint(27, "JavaScript"));
m_Bar.DataPoints.Add(new NBarDataPoint(29, "C#"));
m_Bar.DataPoints.Add(new NBarDataPoint(26, "PHP"));
chart.Series.Add(m_Bar);
// Configure the X axis to show the language names
string[] labels = new string[m_Bar.DataPoints.Count];
for (int i = 0; i < m_Bar.DataPoints.Count; i++)
{
labels[i] = m_Bar.DataPoints[i].Label;
}
NOrdinalScale xAxisScale = (NOrdinalScale)chart.Axes[ENCartesianAxis.PrimaryX].Scale;
xAxisScale.Labels.TextProvider = new NOrdinalScaleLabelTextProvider(labels);
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
NCheckBox enable3DCheckBox = new NCheckBox();
enable3DCheckBox.CheckedChanged += Enable3DCheckBox_CheckedChanged;
stack.Add(enable3DCheckBox);
NComboBox originModeComboBox = new NComboBox();
originModeComboBox.Items.FillFromEnum();
originModeComboBox.SelectedIndexChanged += OnOriginModeComboBoxSelectedIndexChanged;
stack.Add(NPairBox.Create("Origin Mode: ", originModeComboBox));
NNumericUpDown customOriginUpDown = new NNumericUpDown();
customOriginUpDown.ValueChanged += OnCustomOriginUpDownValueChanged;
stack.Add(NPairBox.Create("Custom Origin: ", customOriginUpDown));
NCheckBox autoScaleBreakCheckBox = new NCheckBox();
autoScaleBreakCheckBox.CheckedChanged += AutoScaleBreakCheckBox_CheckedChanged;
stack.Add(NPairBox.Create("Custom Origin: ", autoScaleBreakCheckBox));
return boxGroup;
}
// Intercept : remove
private void Enable3DCheckBox_CheckedChanged(NValueChangeEventArgs arg)
{
m_Bar.GetFirstAncestor().Enable3D = (bool)arg.NewValue;
}
private void AutoScaleBreakCheckBox_CheckedChanged(NValueChangeEventArgs arg)
{
NCartesianChart cartesianChart = m_Bar.GetFirstAncestor();
if ((bool)arg.NewValue == true)
{
NAutoScaleBreak autoScaleBreak = new NAutoScaleBreak();
autoScaleBreak.MaxScaleBreakCount = 3;
autoScaleBreak.ThresholdFactor = 0.2f;
cartesianChart.Axes[ENCartesianAxis.PrimaryY].Scale.ScaleBreaks.Add(autoScaleBreak);
}
else
{
cartesianChart.Axes[ENCartesianAxis.PrimaryY].Scale.ScaleBreaks.Clear();
}
}
public string GetExampleDescription()
{
return @"This example demonstrates how to create a standard bar chart.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Bar Series", "https://www.nevron.com/docs/openvision/bar-chart-series.html"),
("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
void OnCustomOriginUpDownValueChanged(NValueChangeEventArgs arg)
{
m_Bar.CustomOrigin = (double)((NNumericUpDown)arg.TargetNode).Value;
}
void OnOriginModeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
m_Bar.OriginMode = (ENSeriesOriginMode)((NComboBox)arg.TargetNode).SelectedIndex;
}
#endregion
#region Fields
NBarSeries m_Bar;
#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
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 - NStandardBarExample"
' 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)
Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)
' Set the title
chartView.Surface.Titles(0).Text = "Standard Bar"
' Add an interlace stripe
Dim linearScale As NLinearScale = TryCast(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)
' Setup a bar series
m_Bar = New NBarSeries()
m_Bar.Name = "Bar Series"
m_Bar.InflateMargins = True
m_Bar.UseXValues = False
m_Bar.Shadow = New NShadow(NColor.LightGray, 2, 2)
' Add some data to the bar series
m_Bar.LegendView.Mode = ENSeriesLegendMode.DataPoints
m_Bar.DataPoints.Add(New NBarDataPoint(18, "C++"))
m_Bar.DataPoints.Add(New NBarDataPoint(15, "Ruby"))
m_Bar.DataPoints.Add(New NBarDataPoint(21, "Python"))
m_Bar.DataPoints.Add(New NBarDataPoint(23, "Java"))
m_Bar.DataPoints.Add(New NBarDataPoint(27, "JavaScript"))
m_Bar.DataPoints.Add(New NBarDataPoint(29, "C#"))
m_Bar.DataPoints.Add(New NBarDataPoint(26, "PHP"))
chart.Series.Add(m_Bar)
' Configure the X axis to show the language names
Dim labels = New String(m_Bar.DataPoints.Count - 1) {}
For i = 0 To m_Bar.DataPoints.Count - 1
labels(i) = m_Bar.DataPoints(i).Label
Next
Dim xAxisScale As NOrdinalScale = chart.Axes(ENCartesianAxis.PrimaryX).Scale
xAxisScale.Labels.TextProvider = New NOrdinalScaleLabelTextProvider(labels)
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim enable3DCheckBox As NCheckBox = New NCheckBox()
enable3DCheckBox.CheckedChanged += AddressOf Enable3DCheckBox_CheckedChanged
stack.Add(enable3DCheckBox)
Dim originModeComboBox As NComboBox = New NComboBox()
originModeComboBox.Items.FillFromEnum(Of ENSeriesOriginMode)()
originModeComboBox.SelectedIndexChanged += AddressOf OnOriginModeComboBoxSelectedIndexChanged
stack.Add(NPairBox.Create("Origin Mode: ", originModeComboBox))
Dim customOriginUpDown As NNumericUpDown = New NNumericUpDown()
customOriginUpDown.ValueChanged += AddressOf OnCustomOriginUpDownValueChanged
stack.Add(NPairBox.Create("Custom Origin: ", customOriginUpDown))
Dim autoScaleBreakCheckBox As NCheckBox = New NCheckBox()
autoScaleBreakCheckBox.CheckedChanged += AddressOf AutoScaleBreakCheckBox_CheckedChanged
stack.Add(NPairBox.Create("Custom Origin: ", autoScaleBreakCheckBox))
Return boxGroup
End Function
' Intercept : remove
Private Sub Enable3DCheckBox_CheckedChanged(arg As NValueChangeEventArgs)
m_Bar.GetFirstAncestor(Of NCartesianChart)().Enable3D = CBool(arg.NewValue)
End Sub
Private Sub AutoScaleBreakCheckBox_CheckedChanged(arg As NValueChangeEventArgs)
Dim cartesianChart As NCartesianChart = m_Bar.GetFirstAncestor(Of NCartesianChart)()
If CBool(arg.NewValue) = True Then
Dim autoScaleBreak As NAutoScaleBreak = New NAutoScaleBreak()
autoScaleBreak.MaxScaleBreakCount = 3
autoScaleBreak.ThresholdFactor = 0.2F
cartesianChart.Axes(ENCartesianAxis.PrimaryY).Scale.ScaleBreaks.Add(autoScaleBreak)
Else
cartesianChart.Axes(ENCartesianAxis.PrimaryY).Scale.ScaleBreaks.Clear()
End If
End Sub
Public Function GetExampleDescription() As String
Return "This example demonstrates how to create a standard bar chart.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Bar Series", "https://www.nevron.com/docs/openvision/bar-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnCustomOriginUpDownValueChanged(arg As NValueChangeEventArgs)
m_Bar.CustomOrigin = CType(arg.TargetNode, NNumericUpDown).Value
End Sub
Private Sub OnOriginModeComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
m_Bar.OriginMode = CType(CType(arg.TargetNode, NComboBox).SelectedIndex, ENSeriesOriginMode)
End Sub
#End Region
#Region "Fields"
Private m_Bar As NBarSeries
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class