This example demonstrates how to create an interactive legend.

| 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 - NInteractiveLegendExample";
// 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 = "Interactive Legend";
// configure chart
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
// add interlace stripe
NLinearScale linearScale = (NLinearScale)chart.Axes[ENCartesianAxis.PrimaryY].Scale;
NScaleStrip stripStyle = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
stripStyle.Interlaced = true;
linearScale.Strips.Add(stripStyle);
// add the first bar
NBarSeries bar1 = new NBarSeries();
bar1.Name = "Bar1";
bar1.MultiBarMode = ENMultiBarMode.Series;
bar1.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility;
chart.Series.Add(bar1);
// add the second bar
NBarSeries bar2 = new NBarSeries();
bar2.Name = "Bar2";
bar2.MultiBarMode = ENMultiBarMode.Stacked;
bar2.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility;
chart.Series.Add(bar2);
// add the third bar
NBarSeries bar3 = new NBarSeries();
bar3.Name = "Bar3";
bar3.MultiBarMode = ENMultiBarMode.Stacked;
bar3.LegendView.Mode = ENSeriesLegendMode.SeriesVisibility;
chart.Series.Add(bar3);
// setup value formatting
bar1.ValueFormatter = new NNumericValueFormatter("0.###");
bar2.ValueFormatter = new NNumericValueFormatter("0.###");
bar3.ValueFormatter = new NNumericValueFormatter("0.###");
// position data labels in the center of the bars
bar1.DataLabelStyle = CreateDataLabelStyle();
bar2.DataLabelStyle = CreateDataLabelStyle();
bar3.DataLabelStyle = CreateDataLabelStyle();
chartView.Document.StyleSheets.ApplyTheme(new NChartTheme(ENChartPalette.Bright, ENChartPaletteTarget.Series));
// pass some random data
Random random = new Random();
for (int i = 0; i < 12; i++)
{
bar1.DataPoints.Add(new NBarDataPoint(random.Next(90) + 10));
bar2.DataPoints.Add(new NBarDataPoint(random.Next(90) + 10));
bar3.DataPoints.Add(new NBarDataPoint(random.Next(90) + 10));
}
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to create an interactive legend.
";
}
///
/// 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"),
("Hit Testing", "https://www.nevron.com/docs/openvision/chart-interactivity-hit-testing.html"),
("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"),
("Legend Layout", "https://www.nevron.com/docs/openvision/chart-legend-layout.html"),
};
}
#endregion
#region Implementation
///
/// Creates a new data label style object
///
///
private NDataLabelStyle CreateDataLabelStyle()
{
NDataLabelStyle dataLabelStyle = new NDataLabelStyle();
dataLabelStyle.VertAlign = ENVerticalAlignment.Center;
dataLabelStyle.ArrowLength = 0;
return dataLabelStyle;
}
#endregion
#region Event Handlers
#endregion
#region Fields
#endregion
#region Static Methods
#endregion
#region Constants
#endregion
#region Nested Types
#endregion
}
}