Legend Appearance Example for Blazor

Nevron NOV Chart for Blazor ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All Blazor Chart examples are also available as a stand-alone Visual Studio solution in C#, which you can download from the links below.

Legend Appearance Example for Blazor Description

This example demonstrates how to modify the legend appearance.


Legend Appearance Example

C# Legend Appearance Example Code for Nevron Chart for Blazor
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.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NLegendAppearanceExample";

			// 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 = "Legend Appearance";

            m_Legend = chartView.Surface.Legends[0];
            m_Legend.ExpandMode = ENLegendExpandMode.ColsFixed;
            m_Legend.ColCount = 3;

            m_Legend.Border = NBorder.CreateFilledBorder(NColor.Black);
            m_Legend.BorderThickness = new NMargins(2);
            m_Legend.BackgroundFill = new NStockGradientFill(NColor.White, NColor.LightGray);
            m_Legend.VerticalPlacement = ENVerticalPlacement.Top;

            // 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);

			// setup a bar series
			NBarSeries bar = new NBarSeries();
			bar.Name = "Bar Series";
			bar.InflateMargins = true;
			bar.UseXValues = false;
            bar.LegendView.Mode = ENSeriesLegendMode.DataPoints;

			// add some data to the bar series
			bar.LegendView.Mode = ENSeriesLegendMode.DataPoints;
			bar.DataPoints.Add(new NBarDataPoint(18, "C++"));
			bar.DataPoints.Add(new NBarDataPoint(15, "Ruby"));
			bar.DataPoints.Add(new NBarDataPoint(21, "Python"));
			bar.DataPoints.Add(new NBarDataPoint(23, "Java"));
			bar.DataPoints.Add(new NBarDataPoint(27, "Javascript"));
			bar.DataPoints.Add(new NBarDataPoint(29, "C#"));
			bar.DataPoints.Add(new NBarDataPoint(26, "PHP"));
            bar.DataPoints.Add(new NBarDataPoint(17, "Objective C"));
            bar.DataPoints.Add(new NBarDataPoint(24, "SQL"));
            bar.DataPoints.Add(new NBarDataPoint(13, "Object Pascal"));
            bar.DataPoints.Add(new NBarDataPoint(19, "Visual Basic"));
            bar.DataPoints.Add(new NBarDataPoint(16, "Open Edge ABL"));

			chart.Series.Add(bar);

			return chartViewWithCommandBars;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);

            NTextBox legendHeaderTextBox = new NTextBox();
            legendHeaderTextBox.TextChanged += OnLegendHeaderTextBoxChanged;
			stack.Add(NPairBox.Create("Header: ", legendHeaderTextBox));

            NTextBox legendFooterTextBox = new NTextBox();
            legendFooterTextBox.TextChanged += OnLegendFooterTextBoxChanged;
            stack.Add(NPairBox.Create("Footer: ", legendFooterTextBox));

            m_HorizontalInterlaceStripesCheckBox = new NCheckBox("Horizontal Interlace Stripes");
            m_HorizontalInterlaceStripesCheckBox.CheckedChanged += OnVerticalInterlaceStripesCheckBoxCheckedChanged;
            stack.Add(m_HorizontalInterlaceStripesCheckBox);

            m_VerticalInterlaceStripesCheckBox = new NCheckBox("Vertical Interlace Stripes");
            m_VerticalInterlaceStripesCheckBox.CheckedChanged += OnHorizontalInterlaceStripesCheckBoxCheckedChanged;
            stack.Add(m_VerticalInterlaceStripesCheckBox);

            NCheckBox showHorizontalGridLinesCheckBox = new NCheckBox("Show Horizontal Gridlines");
            showHorizontalGridLinesCheckBox.Checked = true;
            showHorizontalGridLinesCheckBox.CheckedChanged += OnShowHorizontalGridLinesCheckBoxCheckedChanged;
            stack.Add(showHorizontalGridLinesCheckBox);

            NCheckBox showVerticalGridLinesCheckBox = new NCheckBox("Show Vertical Gridlines");
            showVerticalGridLinesCheckBox.Checked = true;
            showVerticalGridLinesCheckBox.CheckedChanged += OnShowVerticalGridLinesCheckBoxCheckedChanged;
            stack.Add(showVerticalGridLinesCheckBox);



            return boxGroup;
		}
        public string GetExampleDescription()
		{
			return @"

This example demonstrates how to modify the legend appearance.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Legend Appearance", "https://www.nevron.com/docs/openvision/chart-legend-appearance.html"), ("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html"), }; } #endregion #region Implementation private void ApplyInterlaceStyles() { NLegendInterlaceStylesCollection interlaceStyles = new NLegendInterlaceStylesCollection(); if (m_HorizontalInterlaceStripesCheckBox.Checked) { NLegendInterlaceStyle horzInterlaceStyle = new NLegendInterlaceStyle(); horzInterlaceStyle.Fill = new NColorFill(NColor.FromColor(NColor.LightBlue, 0.5f)); horzInterlaceStyle.Type = ENLegendInterlaceStyleType.Row; horzInterlaceStyle.Length = 1; horzInterlaceStyle.Interval = 1; interlaceStyles.Add(horzInterlaceStyle); } if (m_VerticalInterlaceStripesCheckBox.Checked) { NLegendInterlaceStyle vertInterlaceStyle = new NLegendInterlaceStyle(); vertInterlaceStyle.Fill = new NColorFill(NColor.FromColor(NColor.DarkGray, 0.5f)); vertInterlaceStyle.Type = ENLegendInterlaceStyleType.Col; vertInterlaceStyle.Length = 1; vertInterlaceStyle.Interval = 1; interlaceStyles.Add(vertInterlaceStyle); } m_Legend.InterlaceStyles = interlaceStyles; } #endregion #region Event Handlers private void OnShowVerticalGridLinesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { if (((NCheckBox)arg.TargetNode).Checked) { m_Legend.ClearLocalValue(NLegend.VerticalGridStrokeProperty); } else { m_Legend.VerticalGridStroke = null; } } private void OnShowHorizontalGridLinesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { if (((NCheckBox)arg.TargetNode).Checked) { m_Legend.ClearLocalValue(NLegend.HorizontalGridStrokeProperty); } else { m_Legend.HorizontalGridStroke = null; } } void OnLegendHeaderTextBoxChanged(NValueChangeEventArgs arg) { NLabel header = new NLabel(((NTextBox)arg.TargetNode).Text); header.HorizontalPlacement = ENHorizontalPlacement.Center; header.TextAlignment = ENContentAlignment.MiddleCenter; header.Font = new NFont("Arimo", 14, ENFontStyle.Bold); m_Legend.Header = header; } void OnLegendFooterTextBoxChanged(NValueChangeEventArgs arg) { NLabel footer = new NLabel(((NTextBox)arg.TargetNode).Text); footer.HorizontalPlacement = ENHorizontalPlacement.Center; footer.TextAlignment = ENContentAlignment.MiddleCenter; footer.Font = new NFont("Arimo", 14, ENFontStyle.Bold); m_Legend.Footer = footer; } void OnVerticalInterlaceStripesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { ApplyInterlaceStyles(); } void OnHorizontalInterlaceStripesCheckBoxCheckedChanged(NValueChangeEventArgs arg) { ApplyInterlaceStyles(); } #endregion #region Fields NLegend m_Legend; NCheckBox m_HorizontalInterlaceStripesCheckBox; NCheckBox m_VerticalInterlaceStripesCheckBox; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Legend Appearance Example for Blazor Solution

Related Documentation Links