This example demonstrates how to create a standard box and whisker chart.

| 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 - NStandardBoxAndWhiskersExample";
// 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 = "Standard Box and Whiskers";
// configure chart
m_Chart = (NCartesianChart)chartView.Surface.Charts[0];
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
NLinearScale linearScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
// add interlace stripe
NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
strip.Interlaced = true;
linearScale.Strips.Add(strip);
m_BoxAndWhiskerSeries = new NBoxAndWhiskerSeries();
m_BoxAndWhiskerSeries.WidthSizeMode = ENBarSizeMode.Fixed;
m_Chart.Series.Add(m_BoxAndWhiskerSeries);
m_BoxAndWhiskerSeries.Fill = new NStockGradientFill(ENGradientStyle.Vertical, ENGradientVariant.Variant4, NColor.LightYellow, NColor.DarkOrange);
m_BoxAndWhiskerSeries.DataLabelStyle = new NDataLabelStyle(false);
m_BoxAndWhiskerSeries.MedianStroke = new NStroke(NColor.Indigo);
m_BoxAndWhiskerSeries.AverageStroke = new NStroke(1, NColor.DarkRed, ENDashStyle.Dot);
m_BoxAndWhiskerSeries.OutlierStroke = new NStroke(NColor.DarkCyan);
m_BoxAndWhiskerSeries.OutlierFill = new NColorFill(NColor.Red);
GenerateData(m_BoxAndWhiskerSeries, 7);
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);
NNumericUpDown boxWidthUpDown = new NNumericUpDown();
boxWidthUpDown.Value = m_BoxAndWhiskerSeries.FixedWidth;
boxWidthUpDown.ValueChanged += OnBoxWidthUpDownValueChanged;
stack.Add(NPairBox.Create("Box Width:", boxWidthUpDown));
NNumericUpDown whiskerWidthPercentUpDown = new NNumericUpDown();
whiskerWidthPercentUpDown.Value = m_BoxAndWhiskerSeries.WhiskerWidthPercent;
whiskerWidthPercentUpDown.ValueChanged += OnWhiskerWidthPercentUpDownValueChanged;
stack.Add(NPairBox.Create("Whisker Width %:", whiskerWidthPercentUpDown));
NCheckBox inflateMarginsCheckBox = new NCheckBox("Inflate Margins");
inflateMarginsCheckBox.CheckedChanged += OnInflateMarginsCheckBoxCheckedChanged;
inflateMarginsCheckBox.Checked = true;
stack.Add(inflateMarginsCheckBox);
NCheckBox yAxisRoundToTickCheckBox = new NCheckBox("Y Axis Round To Tick");
yAxisRoundToTickCheckBox.CheckedChanged += OnYAxisRoundToTickCheckBoxCheckedChanged;
yAxisRoundToTickCheckBox.Checked = true;
stack.Add(yAxisRoundToTickCheckBox);
NButton generateDataButton = new NButton("Generate Data");
generateDataButton.Click += OnGenerateDataButtonClick;
stack.Add(generateDataButton);
return boxGroup;
}
public string GetExampleDescription()
{
return @"This example demonstrates how to create a standard box and whisker chart.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Box And Whiskers Series", "https://www.nevron.com/docs/openvision/box-and-whiskers-chart-series.html"),
("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html"),
};
}
#endregion
#region Implementation
private void GenerateData(NBoxAndWhiskerSeries series, int nCount)
{
series.DataPoints.Clear();
Random random = new Random();
for (int i = 0; i < nCount; i++)
{
double boxLower = 1000 + random.NextDouble() * 200;
double boxUpper = boxLower + 200 + random.NextDouble() * 200;
double whiskersLower = boxLower - (20 + random.NextDouble() * 300);
double whiskersUpper = boxUpper + (20 + random.NextDouble() * 300);
double IQR = (boxUpper - boxLower);
double median = boxLower + IQR * 0.25 + random.NextDouble() * IQR * 0.5;
double average = boxLower + IQR * 0.25 + random.NextDouble() * IQR * 0.5;
int outliersCount = random.Next(5);
double[] outliers = new double[outliersCount];
for (int k = 0; k < outliersCount; k++)
{
double outlier = 0;
if (random.NextDouble() > 0.5)
{
outlier = boxUpper + IQR * 1.5 + random.NextDouble() * 100;
}
else
{
outlier = boxLower - IQR * 1.5 - random.NextDouble() * 100;
}
outliers[k] = outlier;
}
series.DataPoints.Add(new NBoxAndWhiskerDataPoint(i, boxUpper, boxLower, median, average, whiskersUpper, whiskersLower, outliers, string.Empty));
}
}
#endregion
#region Event Handlers
void OnBoxWidthUpDownValueChanged(NValueChangeEventArgs arg)
{
m_BoxAndWhiskerSeries.FixedWidth = ((NNumericUpDown)arg.TargetNode).Value;
}
void OnGenerateDataButtonClick(NEventArgs arg)
{
GenerateData(m_BoxAndWhiskerSeries, 7);
}
void OnWhiskerWidthPercentUpDownValueChanged(NValueChangeEventArgs arg)
{
m_BoxAndWhiskerSeries.WhiskerWidthPercent = ((NNumericUpDown)arg.TargetNode).Value;
}
void OnInflateMarginsCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
m_BoxAndWhiskerSeries.InflateMargins = ((NCheckBox)arg.TargetNode).Checked;
}
void OnYAxisRoundToTickCheckBoxCheckedChanged(NValueChangeEventArgs arg)
{
NLinearScale yScale = (NLinearScale)m_Chart.Axes[ENCartesianAxis.PrimaryY].Scale;
if (((NCheckBox)arg.TargetNode).Checked)
{
yScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.MajorTick;
yScale.InflateViewRangeBegin = true;
yScale.InflateViewRangeEnd = true;
}
else
{
yScale.InflateViewRangeBegin = false;
yScale.InflateViewRangeEnd = false;
}
}
#endregion
#region Fields
NCartesianChart m_Chart;
NBoxAndWhiskerSeries m_BoxAndWhiskerSeries;
#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 - NStandardBoxAndWhiskersExample"
' 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 = "Standard Box and Whiskers"
' configure chart
m_Chart = CType(chartView.Surface.Charts(0), NCartesianChart)
m_Chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
Dim linearScale As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale
' add interlace stripe
Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
strip.Interlaced = True
linearScale.Strips.Add(strip)
m_BoxAndWhiskerSeries = New NBoxAndWhiskerSeries()
m_BoxAndWhiskerSeries.WidthSizeMode = ENBarSizeMode.Fixed
m_Chart.Series.Add(m_BoxAndWhiskerSeries)
m_BoxAndWhiskerSeries.Fill = New NStockGradientFill(ENGradientStyle.Vertical, ENGradientVariant.Variant4, NColor.LightYellow, NColor.DarkOrange)
m_BoxAndWhiskerSeries.DataLabelStyle = New NDataLabelStyle(False)
m_BoxAndWhiskerSeries.MedianStroke = New NStroke(NColor.Indigo)
m_BoxAndWhiskerSeries.AverageStroke = New NStroke(1, NColor.DarkRed, ENDashStyle.Dot)
m_BoxAndWhiskerSeries.OutlierStroke = New NStroke(NColor.DarkCyan)
m_BoxAndWhiskerSeries.OutlierFill = New NColorFill(NColor.Red)
GenerateData(m_BoxAndWhiskerSeries, 7)
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Dim boxWidthUpDown As NNumericUpDown = New NNumericUpDown()
boxWidthUpDown.Value = m_BoxAndWhiskerSeries.FixedWidth
boxWidthUpDown.ValueChanged += AddressOf OnBoxWidthUpDownValueChanged
stack.Add(NPairBox.Create("Box Width:", boxWidthUpDown))
Dim whiskerWidthPercentUpDown As NNumericUpDown = New NNumericUpDown()
whiskerWidthPercentUpDown.Value = m_BoxAndWhiskerSeries.WhiskerWidthPercent
whiskerWidthPercentUpDown.ValueChanged += AddressOf OnWhiskerWidthPercentUpDownValueChanged
stack.Add(NPairBox.Create("Whisker Width %:", whiskerWidthPercentUpDown))
Dim inflateMarginsCheckBox As NCheckBox = New NCheckBox("Inflate Margins")
inflateMarginsCheckBox.CheckedChanged += AddressOf OnInflateMarginsCheckBoxCheckedChanged
inflateMarginsCheckBox.Checked = True
stack.Add(inflateMarginsCheckBox)
Dim yAxisRoundToTickCheckBox As NCheckBox = New NCheckBox("Y Axis Round To Tick")
yAxisRoundToTickCheckBox.CheckedChanged += AddressOf OnYAxisRoundToTickCheckBoxCheckedChanged
yAxisRoundToTickCheckBox.Checked = True
stack.Add(yAxisRoundToTickCheckBox)
Dim generateDataButton As NButton = New NButton("Generate Data")
generateDataButton.Click += AddressOf OnGenerateDataButtonClick
stack.Add(generateDataButton)
Return boxGroup
End Function
Public Function GetExampleDescription() As String
Return "This example demonstrates how to create a standard box and whisker chart.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Box And Whiskers Series", "https://www.nevron.com/docs/openvision/box-and-whiskers-chart-series.html"), ("Common Series Functionality", "https://www.nevron.com/docs/openvision/chart-common-series-functionality.html")}
End Function
#End Region
#Region "Implementation"
Private Sub GenerateData(series As NBoxAndWhiskerSeries, nCount As Integer)
series.DataPoints.Clear()
Dim random As Random = New Random()
For i = 0 To nCount - 1
Dim boxLower As Double = 1000 + random.NextDouble() * 200
Dim boxUpper As Double = boxLower + 200 + random.NextDouble() * 200
Dim whiskersLower As Double = boxLower - (20 + random.NextDouble() * 300)
Dim whiskersUpper As Double = boxUpper + (20 + random.NextDouble() * 300)
Dim IQR = boxUpper - boxLower
Dim median As Double = boxLower + IQR * 0.25 + random.NextDouble() * IQR * 0.5
Dim average As Double = boxLower + IQR * 0.25 + random.NextDouble() * IQR * 0.5
Dim outliersCount = random.Next(5)
Dim outliers = New Double(outliersCount - 1) {}
For k = 0 To outliersCount - 1
Dim outlier As Double = 0
If random.NextDouble() > 0.5 Then
outlier = boxUpper + IQR * 1.5 + random.NextDouble() * 100
Else
outlier = boxLower - IQR * 1.5 - random.NextDouble() * 100
End If
outliers(k) = outlier
Next
series.DataPoints.Add(New NBoxAndWhiskerDataPoint(i, boxUpper, boxLower, median, average, whiskersUpper, whiskersLower, outliers, String.Empty))
Next
End Sub
#End Region
#Region "Event Handlers"
Private Sub OnBoxWidthUpDownValueChanged(arg As NValueChangeEventArgs)
m_BoxAndWhiskerSeries.FixedWidth = CType(arg.TargetNode, NNumericUpDown).Value
End Sub
Private Sub OnGenerateDataButtonClick(arg As NEventArgs)
GenerateData(m_BoxAndWhiskerSeries, 7)
End Sub
Private Sub OnWhiskerWidthPercentUpDownValueChanged(arg As NValueChangeEventArgs)
m_BoxAndWhiskerSeries.WhiskerWidthPercent = CType(arg.TargetNode, NNumericUpDown).Value
End Sub
Private Sub OnInflateMarginsCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
m_BoxAndWhiskerSeries.InflateMargins = CType(arg.TargetNode, NCheckBox).Checked
End Sub
Private Sub OnYAxisRoundToTickCheckBoxCheckedChanged(arg As NValueChangeEventArgs)
Dim yScale As NLinearScale = m_Chart.Axes(ENCartesianAxis.PrimaryY).Scale
If CType(arg.TargetNode, NCheckBox).Checked Then
yScale.ViewRangeInflateMode = ENScaleViewRangeInflateMode.MajorTick
yScale.InflateViewRangeBegin = True
yScale.InflateViewRangeEnd = True
Else
yScale.InflateViewRangeBegin = False
yScale.InflateViewRangeEnd = False
End If
End Sub
#End Region
#Region "Fields"
Private m_Chart As NCartesianChart
Private m_BoxAndWhiskerSeries As NBoxAndWhiskerSeries
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class