Area Palette 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.

Area Palette Example for Blazor Description

This example demonstrates how to associate a palette with an area series.


Area Palette Example

C# Area Palette 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;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

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

			chartView.Registered += OnChartViewRegistered;
			chartView.Unregistered += OnChartViewUnregistered;

            // configure title
            chartView.Surface.Titles[0].Text = "Area Palette";

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

            // setup an area series
            m_Area = new NAreaSeries();
            m_Area.Name = "Area Series";
            m_Area.InflateMargins = true;
            m_Area.UseXValues = false;
			m_Area.DataLabelStyle = new NDataLabelStyle(false);

            // m_Area.Palette = new NColorValuePalette(new NColorValuePair[] { new NColorValuePair(0, NColor.Green), new NColorValuePair(60, NColor.Yellow), new NColorValuePair(120, NColor.Red) });
            m_Area.Palette = new NColorValuePalette(new NColorValuePair[] { new NColorValuePair(0, NColor.Green), new NColorValuePair(120, NColor.Red) });

            m_AxisRange = new NRange(0, 130);

			// limit the axis range to 0, 130
			NCartesianAxis yAxis = m_Chart.Axes[ENCartesianAxis.PrimaryY];
			yAxis.ViewRangeMode = ENAxisViewRangeMode.FixedRange;
			yAxis.MinViewRangeValue = m_AxisRange.Begin;
			yAxis.MaxViewRangeValue = m_AxisRange.End;
            m_Chart.Series.Add(m_Area);
			
            int indicatorCount = 10;
            m_IndicatorPhase = new double[indicatorCount];

            // add some data to the area series
            for (int i = 0; i < indicatorCount; i++)
			{
				m_IndicatorPhase[i] = i * 30;
                m_Area.DataPoints.Add(new NAreaDataPoint(0));
			}            

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

            NButton toggleTimerButton = new NButton("Stop Timer");
			toggleTimerButton.Click += OnToggleTimerButtonClick;
			toggleTimerButton.Tag = 0;
			stack.Add(toggleTimerButton);

			NCheckBox invertScaleCheckBox = new NCheckBox("Invert Scale");
			invertScaleCheckBox.CheckedChanged += OnInvertScaleCheckBoxCheckedChanged;
			invertScaleCheckBox.Checked = false;
			stack.Add(invertScaleCheckBox);

			NCheckBox smoothPaletteCheckBox = new NCheckBox("Smooth Palette");
			smoothPaletteCheckBox.CheckedChanged += OnSmoothPaletteCheckBoxCheckedChanged;
			smoothPaletteCheckBox.Checked = true;
			stack.Add(smoothPaletteCheckBox);

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

This example demonstrates how to associate a palette with an area series.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Area Series", "https://www.nevron.com/docs/openvision/area-chart-series.html"), ("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html"), ("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnChartViewUnregistered(NEventArgs arg) { m_Timer.Stop(); m_Timer.Tick -= OnTimerTick; m_Timer = null; } private void OnChartViewRegistered(NEventArgs arg) { m_Timer = new NTimer(); m_Timer.Tick += OnTimerTick; m_Timer.Start(); } void OnInvertScaleCheckBoxCheckedChanged(NValueChangeEventArgs arg) { m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale.Invert = ((NCheckBox)arg.TargetNode).Checked; } void OnToggleTimerButtonClick(NEventArgs arg) { NButton button = (NButton)arg.TargetNode; if ((int)button.Tag == 0) { m_Timer.Stop(); button.Content = new NLabel("Start Timer"); button.Tag = 1; } else { m_Timer.Start(); button.Content = new NLabel("Stop Timer"); button.Tag = 0; } } void OnTimerTick() { Random random = new Random(); for (int i = 0; i < m_Area.DataPoints.Count; i++) { double value = (m_AxisRange.Begin + m_AxisRange.End) / 2.0 + Math.Sin(m_IndicatorPhase[i] * NAngle.Degree2Rad) * m_AxisRange.GetLength() / 2; value = m_AxisRange.GetValueInRange(value); m_Area.DataPoints[i].Value = value; m_IndicatorPhase[i] += 10; } } void OnSmoothPaletteCheckBoxCheckedChanged(NValueChangeEventArgs arg) { bool smoothPalette = ((NCheckBox)arg.TargetNode).Checked; m_Area.Palette.InterpolateColors = smoothPalette; } #endregion #region Fields NCartesianChart m_Chart; NAreaSeries m_Area; NTimer m_Timer; double[] m_IndicatorPhase; NRange m_AxisRange; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Area Palette Example for Blazor Solution

Related Documentation Links