Nevron NOV Chart for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite.
All WPF Chart examples are also available as a stand-alone Visual Studio solution
in C# and VB.NET,
which you can download from the links below.
Fan Chart Example for WPF Description
This example demonstrates how to create a combo chart consisting of a line chart and several high-low series to represent a fan chart.
C# Fan Chart Example Code for Nevron Chart for WPF
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 - NFanChartExample";
// 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();
// create the chart view
NChartView chartView = chartViewWithCommandBars.View;
chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian);
// Configure title
chartView.Surface.Titles[0].Text = "Fan Chart";
// Get cartesian chart
NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];
chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear);
// add interlace stripe
NScaleStrip strip = new NScaleStrip(new NColorFill(NColor.Beige), null, true, 0, 0, 1, 1);
strip.Interlaced = true;
chart.Axes[ENCartesianAxis.PrimaryY].Scale.Strips.Add(strip);
NColor[] palette = NChartPalette.GetColors(ENChartPalette.Bright);
// Create a line series (main projection/forecast)
NLineSeries lineSeries = new NLineSeries();
chart.Series.Add(lineSeries);
lineSeries.Name = "Projection";
lineSeries.InflateMargins = true;
lineSeries.Stroke = new NStroke(3, NColor.Black);
lineSeries.DataLabelStyle = new NDataLabelStyle(false);
NHighLowSeries[] confidenceIntervals = new NHighLowSeries[5];
float confidenceStep = 10f;
// Create a range series (uncertainty band)
for (int i = 0; i < confidenceIntervals.Length; i++)
{
NHighLowSeries highLowSeries = new NHighLowSeries();
chart.Series.Insert(0, highLowSeries);
confidenceIntervals[i] = highLowSeries;
highLowSeries.Name = "Confidence Interval " + (i * confidenceStep + confidenceStep).ToString() + "%";
float baseAlpha = 0.3f;
highLowSeries.HighFill = new NColorFill(NColor.FromColor(palette[i], baseAlpha - baseAlpha * (float)i / (float)confidenceIntervals.Length));
highLowSeries.LowFill = new NColorFill(NColor.FromColor(palette[i], baseAlpha - baseAlpha * (float)i / (float)confidenceIntervals.Length));
highLowSeries.Stroke = new NStroke(0, NColor.White); // no outline
}
// Sample data
double[] baseValues = { 10, 12, 15, 18, 22, 26, 30, 34, 38 };
Random random = new Random();
for (int i = 0; i < baseValues.Length; i++)
{
lineSeries.DataPoints.Add(new NLineDataPoint(baseValues[i]));
double baseValue = baseValues[i];
double lowBaseValue = baseValues[i];
double highBaseValue = baseValues[i];
for (int j = 0; j < confidenceIntervals.Length; j++)
{
lowBaseValue += -baseValues[i] * random.NextDouble() * confidenceStep / 100;
highBaseValue += baseValues[i] * random.NextDouble() * confidenceStep / 100;
confidenceIntervals[j].DataPoints.Add(new NHighLowDataPoint(highBaseValue, lowBaseValue));
}
}
return chartViewWithCommandBars;
}
public NWidget CreateExampleControls()
{
NStackPanel stack = new NStackPanel();
NUniSizeBoxGroup group = new NUniSizeBoxGroup(stack);
return group;
}
public string GetExampleDescription()
{
return @"
This example demonstrates how to create a combo chart consisting of a line chart and several high-low series to represent a fan chart.
";
}
///
/// Gets the relevant documentation links for the example
///
///
public (string Name, string Url)[] GetDocumentationUrls()
{
return new[]
{
("Range Series", "https://www.nevron.com/docs/openvision/range-chart-series.html"),
("Line Series", "https://www.nevron.com/docs/openvision/line-chart-series.html"),
("Cartesian Chart", "https://www.nevron.com/docs/openvision/cartesian-chart.html"),
("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"),
("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html"),
};
}
#endregion
#region Implementation
private NComboBox CreateLegendFormatCombo()
{
NComboBox comboBox = new NComboBox();
NComboBoxItem item = new NComboBoxItem("Value and Label");
item.Tag = "
Download a fully functional C# (.cs) Fan Chart Example for WPF Solution
VB.NET Fan Chart Example Code for Nevron Chart for WPF
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.Wpf
Imports System
Class MainWindow
#Region "Constructors"
Public Sub New()
' This call is required by the designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
' Set form title
Title = "NOV WPF - NFanChartExample"
' 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)
Content = host
End Sub
#End Region
#Region "Example"
Public Function CreateExampleContent() As NWidget
Dim chartViewWithCommandBars As NChartViewWithCommandBars = New NChartViewWithCommandBars()
' create the chart view
Dim chartView = chartViewWithCommandBars.View
chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)
' Configure title
chartView.Surface.Titles(0).Text = "Fan Chart"
' Get cartesian chart
Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)
chart.SetPredefinedCartesianAxes(ENPredefinedCartesianAxis.XOrdinalYLinear)
' add interlace stripe
Dim strip As NScaleStrip = New NScaleStrip(New NColorFill(NColor.Beige), Nothing, True, 0, 0, 1, 1)
strip.Interlaced = True
chart.Axes(ENCartesianAxis.PrimaryY).Scale.Strips.Add(strip)
Dim palette = NChartPalette.GetColors(ENChartPalette.Bright)
' Create a line series (main projection/forecast)
Dim lineSeries As NLineSeries = New NLineSeries()
chart.Series.Add(lineSeries)
lineSeries.Name = "Projection"
lineSeries.InflateMargins = True
lineSeries.Stroke = New NStroke(3, NColor.Black)
lineSeries.DataLabelStyle = New NDataLabelStyle(False)
Dim confidenceIntervals = New NHighLowSeries(4) {}
Dim confidenceStep = 10F
' Create a range series (uncertainty band)
For i = 0 To confidenceIntervals.Length - 1
Dim highLowSeries As NHighLowSeries = New NHighLowSeries()
chart.Series.Insert(0, highLowSeries)
confidenceIntervals(i) = highLowSeries
highLowSeries.Name = "Confidence Interval " & (i * confidenceStep + confidenceStep).ToString() & "%"
Dim baseAlpha = 0.3F
highLowSeries.HighFill = New NColorFill(NColor.FromColor(palette(i), baseAlpha - baseAlpha * CSng(i) / CSng(confidenceIntervals.Length)))
highLowSeries.LowFill = New NColorFill(NColor.FromColor(palette(i), baseAlpha - baseAlpha * CSng(i) / CSng(confidenceIntervals.Length)))
highLowSeries.Stroke = New NStroke(0, NColor.White) ' no outline
Next
' Sample data
Dim baseValues As Double() = {10, 12, 15, 18, 22, 26, 30, 34, 38}
Dim random As Random = New Random()
For i = 0 To baseValues.Length - 1
lineSeries.DataPoints.Add(New NLineDataPoint(baseValues(i)))
Dim baseValue = baseValues(i)
Dim lowBaseValue = baseValues(i)
Dim highBaseValue = baseValues(i)
For j = 0 To confidenceIntervals.Length - 1
lowBaseValue += -baseValues(i) * random.NextDouble() * confidenceStep / 100
highBaseValue += baseValues(i) * random.NextDouble() * confidenceStep / 100
confidenceIntervals(j).DataPoints.Add(New NHighLowDataPoint(highBaseValue, lowBaseValue))
Next
Next
Return chartViewWithCommandBars
End Function
Public Function CreateExampleControls() As NWidget
Dim stack As NStackPanel = New NStackPanel()
Dim group As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)
Return group
End Function
Public Function GetExampleDescription() As String
Return "
This example demonstrates how to create a combo chart consisting of a line chart and several high-low series to represent a fan chart.
"
End Function
'''
''' Gets the relevant documentation links for the example
'''
'''
Public Function GetDocumentationUrls() As (String, String)()
Return {("Range Series", "https://www.nevron.com/docs/openvision/range-chart-series.html"), ("Line Series", "https://www.nevron.com/docs/openvision/line-chart-series.html"), ("Cartesian Chart", "https://www.nevron.com/docs/openvision/cartesian-chart.html"), ("Cartesian Axes", "https://www.nevron.com/docs/openvision/cartesian-chart-axes.html"), ("Overview", "https://www.nevron.com/docs/openvision/chart-legeng-overview.html")}
End Function
#End Region
#Region "Implementation"
Private Function CreateLegendFormatCombo() As NComboBox
Dim comboBox As NComboBox = New NComboBox()
Dim item As NComboBoxItem = New NComboBoxItem("Value and Label")
item.Tag = ""
comboBox.Items.Add(item)
item = New NComboBoxItem("Value")
item.Tag = ""
comboBox.Items.Add(item)
item = New NComboBoxItem("Label")
item.Tag = ""
comboBox.Items.Add(item)
item = New NComboBoxItem("Size")
item.Tag = ""
comboBox.Items.Add(item)
Return comboBox
End Function
#End Region
#Region "Event Handlers"
#End Region
#Region "Fields"
#End Region
#Region "Static Methods"
#End Region
#Region "Constants"
#End Region
#Region "Nested Types"
#End Region
End Class
Download a fully functional VB.NET (.vb) Fan Chart Example for WPF Solution