Basic Functions Example for WPF

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.

Basic Functions Example for WPF Description

This example demonstrates the basic arithmethic functions (+, -, *, /) and the HIGH and LOW functions between data series.

The Green and Blue bar series serve as input parameters for the currently selected function, while the Red line series is used to display the result.


Basic Functions Example

C# Basic Functions Example Code for Nevron Chart for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Chart;
using Nevron.Nov.Dom;
using Nevron.Nov.Formulas;
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 - NBasicFunctionsExample";

			// 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 = "Basic Functions";

            // configure chart
            NCartesianChart chart = (NCartesianChart)chartView.Surface.Charts[0];

            // add interlaced stripe for Y axis
            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);

            // add the first bar
            m_GreenBars = new NBarSeries();
            chart.Series.Add(m_GreenBars);
            m_GreenBars.Name = "Green";
            m_GreenBars.ValueFormatter = new NNumericValueFormatter("0.00");
            m_GreenBars.MultiBarMode = ENMultiBarMode.Series;

            m_GreenBars.DataLabelStyle = new NDataLabelStyle();
            m_GreenBars.DataLabelStyle.Visible = false;

            m_GreenBars.LegendView = new NSeriesLegendView();
            m_GreenBars.LegendView.Mode = ENSeriesLegendMode.DataPoints;

            m_GreenBars.Fill = new NColorFill(NColor.SeaGreen);
            m_GreenBars.Stroke = new NStroke(NColor.Black);
            m_GreenBars.Shape = ENBarShape.Rectangle;

            // add the second bar
            m_BlueBars = new NBarSeries();
            chart.Series.Add(m_BlueBars);
            m_BlueBars.Name = "Blue";
            m_BlueBars.ValueFormatter = new NNumericValueFormatter("0.00");
            m_BlueBars.MultiBarMode = ENMultiBarMode.Clustered;

            m_GreenBars.DataLabelStyle = new NDataLabelStyle();
            m_GreenBars.DataLabelStyle.Visible = false;

            m_BlueBars.LegendView = new NSeriesLegendView();
            m_BlueBars.LegendView.Mode = ENSeriesLegendMode.DataPoints;

            m_BlueBars.Fill  = new NColorFill(NColor.CornflowerBlue);
            m_BlueBars.Stroke = new NStroke(NColor.Black);
            m_BlueBars.Shape = ENBarShape.Rectangle;

            // add a line series for the function
            m_LineSeries = new NLineSeries();
            chart.Series.Add(m_LineSeries);
            m_LineSeries.Name = "Function";
            m_LineSeries.DataLabelStyle = new NDataLabelStyle();
            m_LineSeries.DataLabelStyle.Format = "";

            m_LineSeries.MarkerStyle = new NMarkerStyle();
            m_LineSeries.MarkerStyle.Shape = ENPointShape3D.Ellipse;
            m_LineSeries.MarkerStyle.Visible = true;
            m_LineSeries.MarkerStyle.Border = new NStroke(1, NColor.Crimson);
            m_LineSeries.MarkerStyle.Fill = new NColorFill(NColor.MistyRose);
            m_LineSeries.MarkerStyle.Size = new NSize(10, 10);

            m_LineSeries.LegendView.Mode = ENSeriesLegendMode.None;
            m_LineSeries.ValueFormatter = new NNumericValueFormatter("0.00");

            // fill with random data
            FillDataSeries(m_GreenBars , 5);
            FillDataSeries(m_BlueBars, 5);
            
            return chartViewWithCommandBars;
        }
        public NWidget CreateExampleControls()
        {
            NStackPanel stack = new NStackPanel();
            NUniSizeBoxGroup boxGroup = new NUniSizeBoxGroup(stack);

            // function combo
            m_FunctionComboBox = new NComboBox();
            m_FunctionComboBox.Items.Add(new NComboBoxItem("Green + Blue"));
            m_FunctionComboBox.Items.Add(new NComboBoxItem("Green - Blue"));
            m_FunctionComboBox.Items.Add(new NComboBoxItem("Green * Blue"));
            m_FunctionComboBox.Items.Add(new NComboBoxItem("Green / Blue"));
            m_FunctionComboBox.Items.Add(new NComboBoxItem("HIGH(Green, Blue)"));
            m_FunctionComboBox.Items.Add(new NComboBoxItem("LOW(Green, Blue)"));
            m_FunctionComboBox.SelectedIndex = 0;
            m_FunctionComboBox.SelectedIndexChanged += OnFunctionComboBoxSelectedIndexChanged;
            stack.Add(NPairBox.Create("Function: ", m_FunctionComboBox));

            // new data button
            NButton newDataButton = new NButton("New Data");
            newDataButton.Click += OnNewDataButtonClick;
            stack.Add(newDataButton);

            CalculateFunction();

            return boxGroup;
        }
        

        public string GetExampleDescription()
        {
            return @"

This example demonstrates the basic arithmethic functions (+, -, *, /) and the HIGH and LOW functions between data series.

The Green and Blue bar series serve as input parameters for the currently selected function, while the Red line series is used to display the result.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html"), ("Statistical Functions", "https://www.nevron.com/docs/openvision/formula-statistical-functions.html"), ("Formulas Overview", "https://www.nevron.com/docs/openvision/formula-overview.html"), ("Array Functions", "https://www.nevron.com/docs/openvision/formula-array-functions.html"), }; } #endregion #region Implementation void CalculateFunction() { // determine the formula to use string formula; switch (m_FunctionComboBox.SelectedIndex) { case 0: // add formula = "Green + Blue"; break; case 1: // sub formula = "Green - Blue"; break; case 2: // mul formula = "Green * Blue"; break; case 3: // div formula = "Green / Blue"; break; case 4: // HIGH formula = "HIGH(Green, Blue)"; break; case 5: // LOW formula = "LOW(Green, Blue)"; break; default: return; } // create a chart formula calculator in which: // Green variable represents m_GreenBars Values and // Blue variable represents m_BlueBars Values NFormulaCalculator calculator = new NFormulaCalculator(); calculator.Formula = formula; calculator.Variables["Green"] = m_GreenBars.DataPoints.GetDataSeriesVariant("Value"); calculator.Variables["Blue"] = m_BlueBars.DataPoints.GetDataSeriesVariant("Value"); // calculate NVariant result = calculator.Evaluate(); // update result line series data points m_LineSeries.DataPoints.SetDataSeriesVariant(result, "Value"); NLineSeries lineSeries = new NLineSeries(); lineSeries.DataPoints.Add(new NLineDataPoint() { Value = 10, X = 50 }); lineSeries.DataPoints.Add(new NLineDataPoint() { Value = 20, X = 70 }); lineSeries.DataPoints.Add(new NLineDataPoint() { Value = 30, X = 90 }); } private void FillDataSeries(NBarSeries ds, int count) { double[] randomData = CreateRandomData(count, -100, 100); ds.DataPoints.Clear(); for (int i = 0; i < randomData.Length; i++) { NBarDataPoint dp = new NBarDataPoint(); dp.Value = randomData[i]; ds.DataPoints.Add(dp); } } #endregion #region Event Handlers private void OnNewDataButtonClick(NEventArgs arg) { // fill with random data FillDataSeries(m_GreenBars, 5); FillDataSeries(m_BlueBars, 5); // calculate function CalculateFunction(); } void OnFunctionComboBoxSelectedIndexChanged(NValueChangeEventArgs arg) { CalculateFunction(); } #endregion #region Fields NBarSeries m_GreenBars; NBarSeries m_BlueBars; NLineSeries m_LineSeries; NComboBox m_FunctionComboBox; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Basic Functions Example for WPF Solution

VB.NET Basic Functions Example Code for Nevron Chart for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Chart
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Formulas
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf

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 - NBasicFunctionsExample"

		' 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()
            Dim chartView = chartViewWithCommandBars.View
            chartView.Surface.CreatePredefinedChart(ENPredefinedChartType.Cartesian)

            ' configure title
            chartView.Surface.Titles(0).Text = "Basic Functions"

            ' configure chart
            Dim chart = CType(chartView.Surface.Charts(0), NCartesianChart)

            ' add interlaced stripe for Y axis
            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)

            ' add the first bar
            m_GreenBars = New NBarSeries()
            chart.Series.Add(m_GreenBars)
            m_GreenBars.Name = "Green"
            m_GreenBars.ValueFormatter = New NNumericValueFormatter("0.00")
            m_GreenBars.MultiBarMode = ENMultiBarMode.Series

            m_GreenBars.DataLabelStyle = New NDataLabelStyle()
            m_GreenBars.DataLabelStyle.Visible = False

            m_GreenBars.LegendView = New NSeriesLegendView()
            m_GreenBars.LegendView.Mode = ENSeriesLegendMode.DataPoints

            m_GreenBars.Fill = New NColorFill(NColor.SeaGreen)
            m_GreenBars.Stroke = New NStroke(NColor.Black)
            m_GreenBars.Shape = ENBarShape.Rectangle

            ' add the second bar
            m_BlueBars = New NBarSeries()
            chart.Series.Add(m_BlueBars)
            m_BlueBars.Name = "Blue"
            m_BlueBars.ValueFormatter = New NNumericValueFormatter("0.00")
            m_BlueBars.MultiBarMode = ENMultiBarMode.Clustered

            m_GreenBars.DataLabelStyle = New NDataLabelStyle()
            m_GreenBars.DataLabelStyle.Visible = False

            m_BlueBars.LegendView = New NSeriesLegendView()
            m_BlueBars.LegendView.Mode = ENSeriesLegendMode.DataPoints

            m_BlueBars.Fill = New NColorFill(NColor.CornflowerBlue)
            m_BlueBars.Stroke = New NStroke(NColor.Black)
            m_BlueBars.Shape = ENBarShape.Rectangle

            ' add a line series for the function
            m_LineSeries = New NLineSeries()
            chart.Series.Add(m_LineSeries)
            m_LineSeries.Name = "Function"
            m_LineSeries.DataLabelStyle = New NDataLabelStyle()
            m_LineSeries.DataLabelStyle.Format = ""

            m_LineSeries.MarkerStyle = New NMarkerStyle()
            m_LineSeries.MarkerStyle.Shape = ENPointShape3D.Ellipse
            m_LineSeries.MarkerStyle.Visible = True
            m_LineSeries.MarkerStyle.Border = New NStroke(1, NColor.Crimson)
            m_LineSeries.MarkerStyle.Fill = New NColorFill(NColor.MistyRose)
            m_LineSeries.MarkerStyle.Size = New NSize(10, 10)

            m_LineSeries.LegendView.Mode = ENSeriesLegendMode.None
            m_LineSeries.ValueFormatter = New NNumericValueFormatter("0.00")

            ' fill with random data
            FillDataSeries(m_GreenBars, 5)
            FillDataSeries(m_BlueBars, 5)

            Return chartViewWithCommandBars
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()
            Dim boxGroup As NUniSizeBoxGroup = New NUniSizeBoxGroup(stack)

            ' function combo
            m_FunctionComboBox = New NComboBox()
            m_FunctionComboBox.Items.Add(New NComboBoxItem("Green + Blue"))
            m_FunctionComboBox.Items.Add(New NComboBoxItem("Green - Blue"))
            m_FunctionComboBox.Items.Add(New NComboBoxItem("Green * Blue"))
            m_FunctionComboBox.Items.Add(New NComboBoxItem("Green / Blue"))
            m_FunctionComboBox.Items.Add(New NComboBoxItem("HIGH(Green, Blue)"))
            m_FunctionComboBox.Items.Add(New NComboBoxItem("LOW(Green, Blue)"))
            m_FunctionComboBox.SelectedIndex = 0
            Me.m_FunctionComboBox.SelectedIndexChanged += AddressOf OnFunctionComboBoxSelectedIndexChanged
            stack.Add(NPairBox.Create("Function: ", m_FunctionComboBox))

            ' new data button
            Dim newDataButton As NButton = New NButton("New Data")
            newDataButton.Click += AddressOf OnNewDataButtonClick
            stack.Add(newDataButton)

            CalculateFunction()

            Return boxGroup
        End Function


        Public Function GetExampleDescription() As String
            Return "

This example demonstrates the basic arithmethic functions (+, -, *, /) and the HIGH and LOW functions between data series.

The Green and Blue bar series serve as input parameters for the currently selected function, while the Red line series is used to display the result.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Chart Data Series", "https://www.nevron.com/docs/openvision/chart-data-series.html"), ("Statistical Functions", "https://www.nevron.com/docs/openvision/formula-statistical-functions.html"), ("Formulas Overview", "https://www.nevron.com/docs/openvision/formula-overview.html"), ("Array Functions", "https://www.nevron.com/docs/openvision/formula-array-functions.html")} End Function #End Region #Region "Implementation" Private Sub CalculateFunction() ' determine the formula to use Dim formula As String Select Case m_FunctionComboBox.SelectedIndex Case 0 ' add formula = "Green + Blue" Case 1 ' sub formula = "Green - Blue" Case 2 ' mul formula = "Green * Blue" Case 3 ' div formula = "Green / Blue" Case 4 ' HIGH formula = "HIGH(Green, Blue)" Case 5 ' LOW formula = "LOW(Green, Blue)" Case Else Return End Select ' create a chart formula calculator in which: ' Green variable represents m_GreenBars Values and ' Blue variable represents m_BlueBars Values Dim calculator As NFormulaCalculator = New NFormulaCalculator() calculator.Formula = formula calculator.Variables("Green") = m_GreenBars.DataPoints.GetDataSeriesVariant("Value") calculator.Variables("Blue") = m_BlueBars.DataPoints.GetDataSeriesVariant("Value") ' calculate Dim result As NVariant = calculator.Evaluate() ' update result line series data points m_LineSeries.DataPoints.SetDataSeriesVariant(result, "Value") Dim lineSeries As NLineSeries = New NLineSeries() lineSeries.DataPoints.Add(New NLineDataPoint() With { .Value = 10, .X = 50 }) lineSeries.DataPoints.Add(New NLineDataPoint() With { .Value = 20, .X = 70 }) lineSeries.DataPoints.Add(New NLineDataPoint() With { .Value = 30, .X = 90 }) End Sub Private Sub FillDataSeries(ds As NBarSeries, count As Integer) Dim randomData As Double() = CreateRandomData(count, -100, 100) ds.DataPoints.Clear() For i = 0 To randomData.Length - 1 Dim dp As NBarDataPoint = New NBarDataPoint() dp.Value = randomData(i) ds.DataPoints.Add(dp) Next End Sub #End Region #Region "Event Handlers" Private Sub OnNewDataButtonClick(arg As NEventArgs) ' fill with random data FillDataSeries(m_GreenBars, 5) FillDataSeries(m_BlueBars, 5) ' calculate function CalculateFunction() End Sub Private Sub OnFunctionComboBoxSelectedIndexChanged(arg As NValueChangeEventArgs) CalculateFunction() End Sub #End Region #Region "Fields" Private m_GreenBars As NBarSeries Private m_BlueBars As NBarSeries Private m_LineSeries As NLineSeries Private m_FunctionComboBox As NComboBox #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) Basic Functions Example for WPF Solution