This example demonstrates how to create a cluster 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 - NClusterBarExample";
// 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 = "Cluster Bar Labels";
// configure chart
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
// add 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);
// add a bar series
m_Bar1 = new NBarSeries();
m_Bar1.Name = "Bar1";
m_Bar1.MultiBarMode = ENMultiBarMode.Series;
m_Bar1.DataLabelStyle = CreateDataLabelStyle();
m_Bar1.ValueFormatter = new NNumericValueFormatter("0.###");
chart.Series.Add(m_Bar1);
// add another bar series
m_Bar2 = new NBarSeries();
m_Bar2.Name = "Bar2";
m_Bar2.MultiBarMode = ENMultiBarMode.Clustered;
m_Bar2.DataLabelStyle = CreateDataLabelStyle();
m_Bar2.ValueFormatter = new NNumericValueFormatter("0.###");
chart.Series.Add(m_Bar2);
FillRandomData();
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel propertyStack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(propertyStack);
NNumericUpDown gapPercentNumericUpDown = new NNumericUpDown();
propertyStack.Add(NPairBox.Create("Gap Percent: ", gapPercentNumericUpDown));
gapPercentNumericUpDown.Value = m_Bar1.WidthGapFactor * 100.0;
gapPercentNumericUpDown.ValueChanged += gapPercentNumericUpDown_ValueChanged;
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to create a cluster 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"),
("Ordinal Scale", "https://www.nevron.com/docs/openvision/ordinal-scale.html"),
};
}
#endregion
#region Implementation
///
/// Creates a new data label style object
///
///
private NDataLabelStyle CreateDataLabelStyle()
{
NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
dataLabelStyle.Format = "";
return dataLabelStyle;
}
private void FillRandomData()
{
Random random = new Random();
for (int i = 0; i < 5; i++)
{
m_Bar1.DataPoints.Add(new NBarDataPoint(random.Next(10, 100)));
m_Bar2.DataPoints.Add(new NBarDataPoint(random.Next(10, 100)));
}
}
#endregion
#region Event Handlers
void gapPercentNumericUpDown_ValueChanged(NValueChangeEventArgs arg)
{
m_Bar1.WidthGapFactor = ((NNumericUpDown)arg.TargetNode).Value / 100.0;
}
#endregion
#region Fields
NBarSeries m_Bar1;
NBarSeries m_Bar2;
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}