Profile Picture

Function Calculator and Datasets

Posted By Jay Vicory 14 Years Ago
Author
Message
Jay Vicory
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 2, Visits: 1
Is there a mechanism to bind a NFunctionCalculator to a dataset?

I'd like to attach a function calculator to a dataset that is currently being also bound to a chart.

Here is the binding for two line series to a dataset with three columns,

// First line
this->nChartControl2->DataBindingManager->AddBinding(0,0,"XValues",ds->Tables["laserdata"],"Tick");
this->nChartControl2->DataBindingManager->AddBinding(0,0,"Values",ds->Tables["laserdata"],"Gain");

// Second line
this->nChartControl2->DataBindingManager->AddBinding(0,1,"XValues",ds->Tables["laserdata"],"Tick"); this->nChartControl2->DataBindingManager->AddBinding(0,1,"Values",ds->Tables["laserdata"],"Photodiode");

I would like to add a third series for bollinger calculation that uses the NFunctionCalculator based on the "Photodiode" data from the dataset.

However, I have not been able to figure out a mechanism to create a function calculator using the data from a dataset (Photodiode column). And, how to bind the calculator results to the third bollinger type series.


Any thoughts are appreciated.

Thanks.






Milen Metodiev
Posted 14 Years Ago
View Quick Profile
Forum Member

Forum Member (48 reputation)Forum Member (48 reputation)Forum Member (48 reputation)Forum Member (48 reputation)Forum Member (48 reputation)Forum Member (48 reputation)Forum Member (48 reputation)Forum Member (48 reputation)Forum Member (48 reputation)

Group: Nevron Team
Last Active: 14 Years Ago
Posts: 48, Visits: 1
Hello Jay,

Currently there is no built-in functionality that lets you data bind a function calculator. You can do this manually by subscribing to the ColumnChanged event of the ds->Tables["laserdata"] table. The following example demonstrates this approach.


------------------------------------------------------------

using System;
using System.Data;
using System.Windows.Forms;
using Nevron.Chart;
using Nevron.Chart.Functions;


namespace JayVicory
{
public partial class Form1 : Form
{
Random rand = new Random();
NLineSeries line;
DataTable dataTable;
NFunctionCalculator calculator;
NDataSeries dataSeries;

public Form1()
{
InitializeComponent();

dataTable = new DataTable();
dataTable.Columns.Add("SomeColumn", typeof(double));
dataTable.Columns.Add("Photodiode", typeof(double));
dataTable.Columns.Add("AnotherColumn", typeof(double));
dataTable.Rows.Add(new object[] { 0, 22, 0 });
dataTable.Rows.Add(new object[] { 0, 42, 0 });
dataTable.Rows.Add(new object[] { 0, 14, 0 });
dataTable.Rows.Add(new object[] { 0, 24, 0 });
dataTable.Rows.Add(new object[] { 0, 31, 0 });
dataTable.ColumnChanged += new DataColumnChangeEventHandler(dt_ColumnChanged);

dataSeries = new NDataSeries(DataSeriesType.Double, "Photodiode");

calculator = new NFunctionCalculator();
calculator.Arguments.Add(dataSeries);
calculator.Expression = "BOLLINGER(Photodiode; 3; 2)";
}

private void Form1_Load(object sender, EventArgs e)
{
line = (NLineSeries)nChartControl1.Charts[0].Series.Add(SeriesType.Line);

UpdateLine();
}

void dt_ColumnChanged(object sender, DataColumnChangeEventArgs e)
{
if (e.Column.ColumnName == "Photodiode")
{
UpdateLine();
nChartControl1.Refresh();
}
}

void UpdateLine()
{
dataSeries.FillFromDataTable(dataTable, "Photodiode");
NDataSeries result = calculator.Calculate();
line.Values = result;
}

private void button1_Click(object sender, EventArgs e)
{
dataTable.Rows[2].ItemArray = new object[] { 0, rand.NextDouble() * 50, 0 };
}
}
}

------------------------------------------------------------

I hope this helps, please let me know if you have any questions or comments.


Best Regards,
Milen


Jay Vicory
Posted 14 Years Ago
View Quick Profile
Forum Newbie

Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)Forum Newbie (2 reputation)

Group: Forum Members
Last Active: 14 Years Ago
Posts: 2, Visits: 1
Thanks Milen.

This seems like a reasonable solution, I didn't really think of this option. I'll give it a try and post the results.

Thanks again.

Best regards,

Jay.



Similar Topics


Reading This Topic