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
}
}