This example demonstrates the effect of different series legend view settings.

| 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 - NSeriesLegendViewExample";
// 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 = "Series Legend View";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
// add interlace stripe
NLinearScale linearScale = m_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
NBarSeries bar1 = new NBarSeries();
bar1.Name = "Bar1";
bar1.MultiBarMode = ENMultiBarMode.Series;
bar1.DataLabelStyle = new NDataLabelStyle(false);
bar1.ValueFormatter = new NNumericValueFormatter("0.###");
m_Chart.Series.Add(bar1);
// add another bar series
NBarSeries bar2 = new NBarSeries();
bar2.Name = "Bar2";
bar2.MultiBarMode = ENMultiBarMode.Clustered;
bar2.DataLabelStyle = new NDataLabelStyle(false);
bar2.ValueFormatter = new NNumericValueFormatter("0.###");
m_Chart.Series.Add(bar2);
// add another bar series
NBarSeries bar3 = new NBarSeries();
bar3.Name = "Bar2";
bar3.MultiBarMode = ENMultiBarMode.Clustered;
bar3.DataLabelStyle = new NDataLabelStyle(false);
bar3.ValueFormatter = new NNumericValueFormatter("0.###");
m_Chart.Series.Add(bar3);
Random random = new Random();
for (int i = 0; i < 5; i++)
{
bar1.DataPoints.Add(new NBarDataPoint(random.Next(10, 100)));
bar2.DataPoints.Add(new NBarDataPoint(random.Next(10, 100)));
bar3.DataPoints.Add(new NBarDataPoint(random.Next(10, 100)));
}
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
NComboBox seriesLegendModeComboBox = new NComboBox();
seriesLegendModeComboBox.Items.FillFromEnum();
seriesLegendModeComboBox.SelectedIndexChanged += OnSeriesLegendModeComboBoxSelectedIndexChanged;
seriesLegendModeComboBox.SelectedIndex = (int)ENSeriesLegendMode.Series;
stack.Add(NPairBox.Create("Legend Mode: ", seriesLegendModeComboBox));
NComboBox seriesLegendOrderComboBox = new NComboBox();
seriesLegendOrderComboBox.Items.FillFromEnum();
seriesLegendOrderComboBox.SelectedIndexChanged += OnSeriesLegendOrderComboBoxSelectedIndexChanged;
seriesLegendOrderComboBox.SelectedIndex = (int)ENSeriesLegendOrder.Append;
stack.Add(NPairBox.Create("Legend Order: ", seriesLegendOrderComboBox));
NNumericUpDown markSizeUpDown = new NNumericUpDown();
markSizeUpDown.ValueChanged += OnMarkSizeUpDownValueChanged;
markSizeUpDown.Value = 10;
stack.Add(NPairBox.Create("Mark Size: ", markSizeUpDown));
NNumericUpDown fontSizeUpDown = new NNumericUpDown();
fontSizeUpDown.ValueChanged += OnFontSizeUpDownValueChanged;
fontSizeUpDown.Value = 10;
stack.Add(NPairBox.Create("Font Size: ", fontSizeUpDown));
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates the effect of different series legend view settings.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html"),
("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"),
("Legend Appearance", "https://www.nevron.com/docs/openvision/chart-legend-appearance.html"),
("Legend Layout", "https://www.nevron.com/docs/openvision/chart-legend-layout.html"),
};
}
#endregion
#region Implementation
#endregion
#region Event Handlers
void OnSeriesLegendModeComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
ENSeriesLegendMode seriesLegendMode = (ENSeriesLegendMode)((NComboBox)arg.TargetNode).SelectedIndex;
for (int i = 0; i < m_Chart.Series.Count; i++)
{
m_Chart.Series[i].LegendView.Mode = seriesLegendMode;
}
}
void OnSeriesLegendOrderComboBoxSelectedIndexChanged(NValueChangeEventArgs arg)
{
ENSeriesLegendOrder seriesLegendOrder = (ENSeriesLegendOrder)((NComboBox)arg.TargetNode).SelectedIndex;
for (int i = 0; i < m_Chart.Series.Count; i++)
{
m_Chart.Series[i].LegendView.Order = seriesLegendOrder;
}
}
void OnFontSizeUpDownValueChanged(NValueChangeEventArgs arg)
{
double fontSize = ((NNumericUpDown)arg.TargetNode).Value;
for (int i = 0; i < m_Chart.Series.Count; i++)
{
m_Chart.Series[i].LegendView.TextStyle.Font.Size = fontSize;
}
}
void OnMarkSizeUpDownValueChanged(NValueChangeEventArgs arg)
{
double markSize = ((NNumericUpDown)arg.TargetNode).Value;
for (int i = 0; i < m_Chart.Series.Count; i++)
{
m_Chart.Series[i].LegendView.MarkSize = new NSize(markSize, markSize);
}
}
#endregion
#region Fields
NCartesianChart m_Chart;
#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.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 - NSeriesLegendViewExample"
' 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()
Dim chartView = chartViewWithCommandBars.View
chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)
' configure title
chartView.Surface.Titles(0).Text = "Series Legend View"
' configure chart
m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
' add interlace stripe
Dim linearScale As NLinearScale = TryCast(m_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)
' add a bar series
Dim bar1 As NBarSeries = New NBarSeries()
bar1.Name = "Bar1"
bar1.MultiBarMode = ENMultiBarMode.Series
bar1.DataLabelStyle = New NDataLabelStyle(False)
bar1.ValueFormatter = New NNumericValueFormatter("0.###")
m_Chart.Series.Add(bar1)
' add another bar series
Dim bar2 As NBarSeries = New NBarSeries()
bar2.Name = "Bar2"
bar2.MultiBarMode = ENMultiBarMode.Clustered
bar2.DataLabelStyle = New NDataLabelStyle(False)
bar2.ValueFormatter = New NNumericValueFormatter("0.###")
m_Chart.Series.Add(bar2)
' add another bar series
Dim bar3 As NBarSeries = New NBarSeries()
bar3.Name = "Bar2"
bar3.MultiBarMode = ENMultiBarMode.Clustered
bar3.DataLabelStyle = New NDataLabelStyle(False)
bar3.ValueFormatter = New NNumericValueFormatter("0.###")
m_Chart.Series.Add(bar3)
Dim random As Random = New Random()
For i = 0 To 4
bar1.DataPoints.Add(New NBarDataPoint(random.Next(10, 100)))
bar2.DataPoints.Add(New NBarDataPoint(random.Next(10, 100)))
bar3.DataPoints.Add(New NBarDataPoint(random.Next(10, 100)))
Next
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 seriesLegendModeComboBox As NComboBox = New NComboBox()
seriesLegendModeComboBox.Items.FillFromEnum(Of ENSeriesLegendMode)()
seriesLegendModeComboBox.SelectedIndexChanged += AddressOf OnSeriesLegendModeComboBoxSelectedIndexChanged
seriesLegendModeComboBox.SelectedIndex = CInt(ENSeriesLegendMode.Series)
stack.Add(NPairBox.Create("Legend Mode: ", seriesLegendModeComboBox))
Dim seriesLegendOrderComboBox As NComboBox = New NComboBox()
seriesLegendOrderComboBox.Items.FillFromEnum(Of ENSeriesLegendOrder)()
seriesLegendOrderComboBox.SelectedIndexChanged += AddressOf OnSeriesLegendOrderComboBoxSelectedIndexChanged
seriesLegendOrderComboBox.SelectedIndex = CInt(ENSeriesLegendOrder.Append)
stack.Add(NPairBox.Create("Legend Order: ", seriesLegendOrderComboBox))
Dim markSizeUpDown As NNumericUpDown = New NNumericUpDown()
markSizeUpDown.ValueChanged += AddressOf OnMarkSizeUpDownValueChanged
markSizeUpDown.Value = 10
stack.Add(NPairBox.Create("Mark Size: ", markSizeUpDown))
Dim fontSizeUpDown As NNumericUpDown = New NNumericUpDown()
fontSizeUpDown.ValueChanged += AddressOf OnFontSizeUpDownValueChanged
fontSizeUpDown.Value = 10
stack.Add(NPairBox.Create("Font Size: ", fontSizeUpDown))
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates the effect of different series legend view settings.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"), ("Legend Appearance", "https://www.nevron.com/docs/openvision/chart-legend-appearance.html"), ("Legend Layout", "https://www.nevron.com/docs/openvision/chart-legend-layout.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnSeriesLegendModeComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
Dim seriesLegendMode As ENSeriesLegendMode = CType(arg.TargetNode, NComboBox).SelectedIndex
For i = 0 To m_Chart.Series.Count - 1
m_Chart.Series(i).LegendView.Mode = seriesLegendMode
Next
End Sub
Private Sub OnSeriesLegendOrderComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs)
Dim seriesLegendOrder As ENSeriesLegendOrder = CType(arg.TargetNode, NComboBox).SelectedIndex
For i = 0 To m_Chart.Series.Count - 1
m_Chart.Series(i).LegendView.Order = seriesLegendOrder
Next
End Sub
Private Sub OnFontSizeUpDownValueChanged(arg As NValueChangeEventArgs)
Dim fontSize = CType(arg.TargetNode, NNumericUpDown).Value
For i = 0 To m_Chart.Series.Count - 1
m_Chart.Series(i).LegendView.TextStyle.Font.Size = fontSize
Next
End Sub
Private Sub OnMarkSizeUpDownValueChanged(arg As NValueChangeEventArgs)
Dim markSize = CType(arg.TargetNode, NNumericUpDown).Value
For i = 0 To m_Chart.Series.Count - 1
m_Chart.Series(i).LegendView.MarkSize = New NSize(markSize, markSize)
Next
End Sub
#End Region
#Region "Fields"
Private m_Chart As NCartesianChart
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class