This example demonstrates how to associate a palette with a bar series.

| 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 - NBarPaletteExample";
// 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 = "Bar 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 a bar series
m_Bar = new NBarSeries();
m_Bar.Name = "Bar Series";
m_Bar.InflateMargins = true;
m_Bar.UseXValues = false;
m_Bar.DataLabelStyle = new NDataLabelStyle(false);
m_Bar.Palette = new NColorValuePalette(new NColorValuePair[] { new NColorValuePair(0, NColor.Green), new NColorValuePair(60, NColor.Yellow), 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_Bar);
int indicatorCount = 10;
m_IndicatorPhase = new double[indicatorCount];
// add some data to the bar series
for (int i = 0; i < indicatorCount; i++)
{
m_IndicatorPhase[i] = i * 30;
m_Bar.DataPoints.Add(new NBarDataPoint(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);
NComboBox paletteColorModeCombo = new NComboBox();
paletteColorModeCombo.Items.FillFromEnum();
paletteColorModeCombo.SelectedIndexChanged += OnPaletteColorModeComboSelectedIndexChanged;
paletteColorModeCombo.SelectedIndex = (int)ENPaletteColorMode.Spread;
stack.Add(NPairBox.Create("Palette Color Mode:", paletteColorModeCombo));
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 a bar series.
";
}
///
/// 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"),
("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 OnChartViewRegistered(NEventArgs arg)
{
m_Timer = new NTimer();
m_Timer.Tick += OnTimerTick;
m_Timer.Start();
}
private void OnChartViewUnregistered(NEventArgs arg)
{
m_Timer.Stop();
m_Timer.Tick -= OnTimerTick;
m_Timer = null;
}
void OnInvertScaleCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale.Invert = ((NCheckBox)arg.TargetNode).Checked;
}
void OnPaletteColorModeComboSelectedIndexChanged(NValueChangeEventArgs arg)
{
ENPaletteColorMode paletteColorMode = (ENPaletteColorMode)((NComboBox)arg.TargetNode).SelectedIndex;
m_Bar.PaletteColorMode = paletteColorMode;
}
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_Bar.DataPoints.Count; i++)
{
double value = (m_AxisRange.Begin + m_AxisRange.End) / 2.0 + Math.Sin(m_IndicatorPhase[i] * NAngle.Degree2Rad) * m_AxisRange.GetLength() / 2 + random.Next(20);
value = m_AxisRange.GetValueInRange(value);
m_Bar.DataPoints[i].Value = value;
m_IndicatorPhase[i] += 10;
}
}
void OnSmoothPaletteCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
bool smoothPalette = ((NCheckBox)arg.TargetNode).Checked;
m_Bar.Palette.InterpolateColors = smoothPalette;
}
#endregion
#region Fields
NCartesianChart m_Chart;
NBarSeries m_Bar;
NTimer m_Timer;
double[] m_IndicatorPhase;
NRange m_AxisRange;
#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 - NBarPaletteExample"
' 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)
chartView.Registered += AddressOf OnChartViewRegistered
chartView.Unregistered += AddressOf OnChartViewUnregistered
' configure title
chartView.Surface.Titles(0).Text = "Bar Palette"
' 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)
' setup a bar series
m_Bar = New NBarSeries()
m_Bar.Name = "Bar Series"
m_Bar.InflateMargins = True
m_Bar.UseXValues = False
m_Bar.DataLabelStyle = New NDataLabelStyle(False)
m_Bar.Palette = New NColorValuePalette(New NColorValuePair() {New NColorValuePair(0, NColor.Green), New NColorValuePair(60, NColor.Yellow), New NColorValuePair(120, NColor.Red)})
m_AxisRange = New NRange(0, 130)
' limit the axis range to 0, 130
Dim 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_Bar)
Dim indicatorCount = 10
m_IndicatorPhase = New Double(indicatorCount - 1) {}
' add some data to the bar series
For i = 0 To indicatorCount - 1
m_IndicatorPhase(i) = i * 30
m_Bar.DataPoints.Add(New NBarDataPoint(0))
Next
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim toggleTimerButton As NButton = New NButton("Stop Timer")
toggleTimerButton.Click += AddressOf OnToggleTimerButtonClick
toggleTimerButton.Tag = 0
stack.Add(toggleTimerButton)
Dim paletteColorModeCombo As NComboBox = New NComboBox()
paletteColorModeCombo.Items.FillFromEnum(Of ENPaletteColorMode)()
paletteColorModeCombo.SelectedIndexChanged += AddressOf OnPaletteColorModeComboSelectedIndexChanged
paletteColorModeCombo.SelectedIndex = CInt(ENPaletteColorMode.Spread)
stack.Add(NPairBox.Create("Palette Color Mode:", paletteColorModeCombo))
Dim invertScaleCheckBox As NCheckBox = New NCheckBox("Invert Scale")
invertScaleCheckBox.CheckedChanged += AddressOf OnInvertScaleCheckBoxCheckedChanged
invertScaleCheckBox.Checked = False
stack.Add(invertScaleCheckBox)
Dim smoothPaletteCheckBox As NCheckBox = New NCheckBox("Smooth Palette")
smoothPaletteCheckBox.CheckedChanged += AddressOf OnSmoothPaletteCheckBoxCheckedChanged
smoothPaletteCheckBox.Checked = True
stack.Add(smoothPaletteCheckBox)
Return stack
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how to associate a palette with a bar series.
"
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"), ("chart-palettes", "https://www.nevron.com/docs/openvision/chart-palettes.html"), ("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html")}
End Function
#End Region
#Region "Implementation"
#End Region
#Region "Event Handlers"
Private Sub OnChartViewRegistered(arg As NEventArgs)
m_Timer = New NTimer()
Me.m_Timer.Tick += AddressOf OnTimerTick
m_Timer.Start()
End Sub
Private Sub OnChartViewUnregistered(arg As NEventArgs)
m_Timer.Stop()
Me.m_Timer.Tick -= AddressOf OnTimerTick
m_Timer = Nothing
End Sub
Private Sub OnInvertScaleCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale.Invert = CType(arg.TargetNode, NCheckBox).Checked
End Sub
Private Sub OnPaletteColorModeComboSelectedIndexChanged(arg As NValueChangeEventArgs)
Dim paletteColorMode As ENPaletteColorMode = CType(arg.TargetNode, NComboBox).SelectedIndex
m_Bar.PaletteColorMode = paletteColorMode
End Sub
Private Sub OnToggleTimerButtonClick(arg As NEventArgs)
Dim button = CType(arg.TargetNode, NButton)
If CInt(button.Tag) = 0 Then
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
End If
End Sub
Private Sub OnTimerTick()
Dim random As Random = New Random()
For i = 0 To m_Bar.DataPoints.Count - 1
Dim value As Double = (m_AxisRange.Begin + m_AxisRange.End) / 2.0 + Math.Sin(m_IndicatorPhase(i) * NAngle.Degree2Rad) * m_AxisRange.GetLength() / 2 + random.Next(20)
value = m_AxisRange.GetValueInRange(value)
m_Bar.DataPoints(i).Value = value
m_IndicatorPhase(i) += 10
Next
End Sub
Private Sub OnSmoothPaletteCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
Dim smoothPalette = CType(arg.TargetNode, NCheckBox).Checked
m_Bar.Palette.InterpolateColors = smoothPalette
End Sub
#End Region
#Region "Fields"
Private m_Chart As NCartesianChart
Private m_Bar As NBarSeries
Private m_Timer As NTimer
Private m_IndicatorPhase As Double()
Private m_AxisRange As NRange
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class