This example demonstrates how automatic data label layout works with cluster stack bar labels.

| 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 - NClusterStackBarLabelsExample";
// 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 Stack Bar Labels";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
// configure Y axis
NLinearScale scaleY = new NLinearScale();
scaleY.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dash;
m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale = scaleY;
// add interlaced stripe for Y axis
NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
stripStyle.Interlaced = true;
scaleY.Strips.Add(stripStyle);
NSize dataPointSafeguardSize = new NSize(2, 2);
// series 1
m_Bar1 = new NBarSeries();
m_Chart.Series.Add(m_Bar1);
m_Bar1.Name = "Bar 1";
m_Bar1.Fill = new NColorFill(NColor.DarkOrange);
m_Bar1.DataLabelStyle = CreateDataLabelStyle(ENVerticalAlignment.Center);
// series 2
m_Bar2 = new NBarSeries();
m_Chart.Series.Add(m_Bar2);
m_Bar2.Name = "Bar 2";
m_Bar2.MultiBarMode = ENMultiBarMode.Stacked;
m_Bar2.Fill = new NColorFill(NColor.OrangeRed);
m_Bar2.DataLabelStyle = CreateDataLabelStyle(ENVerticalAlignment.Center);
// series 3
m_Bar3 = new NBarSeries();
m_Chart.Series.Add(m_Bar3);
m_Bar3.Name = "Bar 3";
m_Bar3.MultiBarMode = ENMultiBarMode.Clustered;
m_Bar3.Fill = new NColorFill(NColor.LightGreen);
m_Bar3.DataLabelStyle = CreateDataLabelStyle(ENVerticalAlignment.Top);
// enable initial labels positioning
m_Chart.LabelLayout.EnableInitialPositioning = true;
// enable label adjustment
m_Chart.LabelLayout.EnableLabelAdjustment = true;
// series 1 data points must not be overlapped
m_Bar1.LabelLayout.EnableDataPointSafeguard = true;
m_Bar1.LabelLayout.DataPointSafeguardSize = dataPointSafeguardSize;
// do not use label location proposals for series 1
m_Bar1.LabelLayout.UseLabelLocations = false;
// series 2 data points must not be overlapped
m_Bar2.LabelLayout.EnableDataPointSafeguard = true;
m_Bar2.LabelLayout.DataPointSafeguardSize = dataPointSafeguardSize;
// do not use label location proposals for series 2
m_Bar2.LabelLayout.UseLabelLocations = false;
// series 3 data points must not be overlapped
m_Bar3.LabelLayout.EnableDataPointSafeguard = true;
m_Bar3.LabelLayout.DataPointSafeguardSize = dataPointSafeguardSize;
// series 3 data labels can be placed above and below the origin point
m_Bar3.LabelLayout.UseLabelLocations = true;
m_Bar3.LabelLayout.LabelLocations = new NDomArray(new ENLabelLocation[] { ENLabelLocation.Top, ENLabelLocation.Bottom });
m_Bar3.LabelLayout.InvertLocationsIfIgnored = false;
m_Bar3.LabelLayout.OutOfBoundsLocationMode = ENOutOfBoundsLocationMode.PushWithinBounds;
// fill with random data
OnGenerateDataButtonClick(null);
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
m_EnableInitialPositioningCheckBox = new NCheckBox("Enable Initial Positioning");
m_EnableInitialPositioningCheckBox.CheckedChanged += OnEnableInitialPositioningCheckBoxCheckedChanged;
stack.Add(m_EnableInitialPositioningCheckBox);
m_EnableLabelAdjustmentCheckBox = new NCheckBox("Enable Label Adjustment");
m_EnableLabelAdjustmentCheckBox.CheckedChanged += OnEnableLabelAdjustmentCheckBoxCheckedChanged;
stack.Add(m_EnableLabelAdjustmentCheckBox);
NButton generateDataButton = new NButton("Generate Data");
generateDataButton.Click += OnGenerateDataButtonClick;
stack.Add(generateDataButton);
m_EnableInitialPositioningCheckBox.Checked = true;
m_EnableLabelAdjustmentCheckBox.Checked = true;
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how automatic data label layout works with cluster stack bar labels.
";
}
///
/// 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"),
("Series Label Layout", "https://www.nevron.com/docs/openvision/chart-series-label-layout.html"),
("Series Labels Appearance", "https://www.nevron.com/docs/openvision/chart-series-labels-appearance.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
NDataLabelStyle CreateDataLabelStyle(ENVerticalAlignment vertAlign)
{
NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
dataLabelStyle.Visible = true;
dataLabelStyle.VertAlign = ENVerticalAlignment.Top;
dataLabelStyle.ArrowLength = 20;
dataLabelStyle.Format = "";
return dataLabelStyle;
}
#endregion
#region Event Handlers
void OnEnableLabelAdjustmentCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
m_Chart.LabelLayout.EnableLabelAdjustment = m_EnableLabelAdjustmentCheckBox.Checked;
}
void OnEnableInitialPositioningCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
m_Chart.LabelLayout.EnableInitialPositioning = m_EnableInitialPositioningCheckBox.Checked;
}
void OnGenerateDataButtonClick(NEventArgs arg)
{
m_Bar1.DataPoints.Clear();
m_Bar2.DataPoints.Clear();
m_Bar3.DataPoints.Clear();
Random random = new Random();
for (int i = 0; i < 10; i++)
{
m_Bar1.DataPoints.Add(new NBarDataPoint(random.Next(5, 20)));
m_Bar2.DataPoints.Add(new NBarDataPoint(random.Next(5, 20)));
m_Bar3.DataPoints.Add(new NBarDataPoint(random.Next(5, 20)));
}
}
#endregion
#region Fields
NCartesianChart m_Chart;
NBarSeries m_Bar1;
NBarSeries m_Bar2;
NBarSeries m_Bar3;
NCheckBox m_EnableInitialPositioningCheckBox;
NCheckBox m_EnableLabelAdjustmentCheckBox;
#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 - NClusterStackBarLabelsExample"
' 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 = "Cluster Stack Bar Labels"
' configure chart
m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
' configure Y axis
Dim scaleY As NLinearScale = New NLinearScale()
scaleY.MajorGridLines.Stroke.DashStyle = ENDashStyle.Dash
m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale = scaleY
' add interlaced stripe for Y axis
Dim stripStyle As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
stripStyle.Interlaced = True
scaleY.Strips.Add(stripStyle)
Dim dataPointSafeguardSize As NSize = New NSize(2, 2)
' series 1
m_Bar1 = New NBarSeries()
m_Chart.Series.Add(m_Bar1)
m_Bar1.Name = "Bar 1"
m_Bar1.Fill = New NColorFill(NColor.DarkOrange)
m_Bar1.DataLabelStyle = CreateDataLabelStyle(ENVerticalAlignment.Center)
' series 2
m_Bar2 = New NBarSeries()
m_Chart.Series.Add(m_Bar2)
m_Bar2.Name = "Bar 2"
m_Bar2.MultiBarMode = ENMultiBarMode.Stacked
m_Bar2.Fill = New NColorFill(NColor.OrangeRed)
m_Bar2.DataLabelStyle = CreateDataLabelStyle(ENVerticalAlignment.Center)
' series 3
m_Bar3 = New NBarSeries()
m_Chart.Series.Add(m_Bar3)
m_Bar3.Name = "Bar 3"
m_Bar3.MultiBarMode = ENMultiBarMode.Clustered
m_Bar3.Fill = New NColorFill(NColor.LightGreen)
m_Bar3.DataLabelStyle = CreateDataLabelStyle(ENVerticalAlignment.Top)
' enable initial labels positioning
m_Chart.LabelLayout.EnableInitialPositioning = True
' enable label adjustment
m_Chart.LabelLayout.EnableLabelAdjustment = True
' series 1 data points must not be overlapped
m_Bar1.LabelLayout.EnableDataPointSafeguard = True
m_Bar1.LabelLayout.DataPointSafeguardSize = dataPointSafeguardSize
' do not use label location proposals for series 1
m_Bar1.LabelLayout.UseLabelLocations = False
' series 2 data points must not be overlapped
m_Bar2.LabelLayout.EnableDataPointSafeguard = True
m_Bar2.LabelLayout.DataPointSafeguardSize = dataPointSafeguardSize
' do not use label location proposals for series 2
m_Bar2.LabelLayout.UseLabelLocations = False
' series 3 data points must not be overlapped
m_Bar3.LabelLayout.EnableDataPointSafeguard = True
m_Bar3.LabelLayout.DataPointSafeguardSize = dataPointSafeguardSize
' series 3 data labels can be placed above and below the origin point
m_Bar3.LabelLayout.UseLabelLocations = True
m_Bar3.LabelLayout.LabelLocations = New NDomArray(Of ENLabelLocation)(New ENLabelLocation() {ENLabelLocation.Top, ENLabelLocation.Bottom})
m_Bar3.LabelLayout.InvertLocationsIfIgnored = False
m_Bar3.LabelLayout.OutOfBoundsLocationMode = ENOutOfBoundsLocationMode.PushWithinBounds
' fill with random data
OnGenerateDataButtonClick(Nothing)
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
m_EnableInitialPositioningCheckBox = New NCheckBox("Enable Initial Positioning")
Me.m_EnableInitialPositioningCheckBox.CheckedChanged += AddressOf OnEnableInitialPositioningCheckBoxCheckedChanged
stack.Add(m_EnableInitialPositioningCheckBox)
m_EnableLabelAdjustmentCheckBox = New NCheckBox("Enable Label Adjustment")
Me.m_EnableLabelAdjustmentCheckBox.CheckedChanged += AddressOf OnEnableLabelAdjustmentCheckBoxCheckedChanged
stack.Add(m_EnableLabelAdjustmentCheckBox)
Dim generateDataButton As NButton = New NButton("Generate Data")
generateDataButton.Click += AddressOf OnGenerateDataButtonClick
stack.Add(generateDataButton)
m_EnableInitialPositioningCheckBox.Checked = True
m_EnableLabelAdjustmentCheckBox.Checked = True
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how automatic data label layout works with cluster stack bar labels.
"
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"), ("Series Label Layout", "https://www.nevron.com/docs/openvision/chart-series-label-layout.html"), ("Series Labels Appearance", "https://www.nevron.com/docs/openvision/chart-series-labels-appearance.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")}
End Function
#End Region
#Region "Implementation"
Private Function CreateDataLabelStyle(vertAlign As ENVerticalAlignment) As NDataLabelStyle
Dim dataLabelStyle As NDataLabelStyle = New NDataLabelStyle()
dataLabelStyle.Visible = True
dataLabelStyle.VertAlign = ENVerticalAlignment.Top
dataLabelStyle.ArrowLength = 20
dataLabelStyle.Format = ""
Return dataLabelStyle
End Function
#End Region
#Region "Event Handlers"
Private Sub OnEnableLabelAdjustmentCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
m_Chart.LabelLayout.EnableLabelAdjustment = m_EnableLabelAdjustmentCheckBox.Checked
End Sub
Private Sub OnEnableInitialPositioningCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
m_Chart.LabelLayout.EnableInitialPositioning = m_EnableInitialPositioningCheckBox.Checked
End Sub
Private Sub OnGenerateDataButtonClick(arg As NEventArgs)
m_Bar1.DataPoints.Clear()
m_Bar2.DataPoints.Clear()
m_Bar3.DataPoints.Clear()
Dim random As Random = New Random()
For i = 0 To 9
m_Bar1.DataPoints.Add(New NBarDataPoint(random.Next(5, 20)))
m_Bar2.DataPoints.Add(New NBarDataPoint(random.Next(5, 20)))
m_Bar3.DataPoints.Add(New NBarDataPoint(random.Next(5, 20)))
Next
End Sub
#End Region
#Region "Fields"
Private m_Chart As NCartesianChart
Private m_Bar1 As NBarSeries
Private m_Bar2 As NBarSeries
Private m_Bar3 As NBarSeries
Private m_EnableInitialPositioningCheckBox As NCheckBox
Private m_EnableLabelAdjustmentCheckBox As NCheckBox
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class