Page 1 of 1
DefaultNull Value property in TeeChart
Posted: Wed Jun 03, 2009 3:31 pm
by 15653415
Hello,
I am trying to plot some field data using Teechart. Since the dield data I get is intermittent, the measuring device fills time instances where it doesn't have a measurement with 0. I want to plot only the valid measured values (i.e. leave out the zeros). Currently I go through the following loop to add the points one by one to a fastline series and use the fastline.TreatNull property to not paint these null points
For i = 0 To (numRecords - 1)
m_frmChart.chart.Series(0).Add(time(i), RSSI(i))
If RSSI(i) = 0 Then
m_frmChart.chart.Series(0.SetNull(i)
End If
Next
Can I (and if Yes how) use the DefaultNull property of the series so that all I would have to do is
m_frmchart.chart.series(0).defaultnullvalue=0
m_frmchart.chart.series(0).add(RSSI)
m_frmchart.chart.fastlint1.TreatNulls=DoNotPaint
(Series(0) in this instance is fastline1).
Thanks,
Vivek
Posted: Thu Jun 04, 2009 1:26 pm
by narcis
Hi Vivek,
You have 2 options:
1. Using SetNull:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.DefaultNullValue = 0;
line1.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
Random y = new Random();
for (int i = 0; i < 100; i++)
{
if (i % 5 == 0)
{
line1.Add(line1.DefaultNullValue);
line1.SetNull(i);
}
else
{
line1.Add(y.Next());
}
}
}
2. Adding a point being transparent:
Code: Select all
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.DefaultNullValue = 0;
line1.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
Random y = new Random();
for (int i = 0; i < 100; i++)
{
if (i % 5 == 0)
{
line1.Add(line1.DefaultNullValue, Color.Transparent);
//line1.SetNull(i);
}
else
{
line1.Add(y.Next());
}
}
}
3. Calling Add() method without any argument:
Code: Select all
private void InitializeChart()
{
Steema.TeeChart.Styles.Line line1 = new Steema.TeeChart.Styles.Line(tChart1.Chart);
line1.DefaultNullValue = 0;
line1.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
Random y = new Random();
for (int i = 0; i < 100; i++)
{
if (i % 5 == 0)
{
line1.Add();
//line1.SetNull(i);
}
else
{
line1.Add(y.Next());
}
}
}
Posted: Thu Jun 04, 2009 1:51 pm
by 15653415
Hi,
Thanks for the clarification. My understanding of the defaultnullvalue was a little different. The name seems to suggest that one you specify the defaultnullvalue, any point in the series whose value was equal to the defaultnullvalue would be treated as a null point.
The only problem I see with the approaches you had suggested is that I need to loop through the data series and add one point at a time. I would think that this would be slower than specifying a value to be interpreted as a null and just adding the entire series i.e.
Series(0).defaultNullValue=0
Series(0).Add(data) where data() is the data I want to plot.
Do you have anyway by which I can add data to a series in a single shot and specify points with a particular value to be treated as a null?
Thanks,
Vivek
Posted: Thu Jun 04, 2009 2:12 pm
by narcis
Hi Vivek,
In that case you should have a colour field in your datatable having Color.Transparent for those points you want to be null so that you can do something like this:
Code: Select all
public Form1()
{
InitializeComponent();
InitializeChart();
}
private void InitializeChart()
{
Steema.TeeChart.Styles.FastLine fastLine1 = new Steema.TeeChart.Styles.FastLine(tChart1.Chart);
fastLine1.DefaultNullValue = 0;
fastLine1.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
fastLine1.DataSource = GetData();
fastLine1.YValues.DataMember = "Y";
fastLine1.ColorMember = "Color";
}
private DataTable GetData()
{
DataTable TeeDataTable = new DataTable();
DataRow newRow;
DataColumn yval = new DataColumn("Y", typeof(double));
DataColumn color = new DataColumn("Color", typeof(Color));
TeeDataTable.Columns.Add(yval);
TeeDataTable.Columns.Add(color);
for (int i = 0; i < 100; i++)
{
newRow = TeeDataTable.NewRow();
if (i % 5 == 0)
{
newRow[yval] = 0;
newRow[color] = Color.Transparent;
}
else
{
newRow[yval] = i;
newRow[color] = Color.Empty;
}
TeeDataTable.Rows.Add(newRow);
}
return TeeDataTable;
}
Posted: Thu Jun 04, 2009 2:16 pm
by narcis
Hi Vivek,
I forgot to tell you that I have also added your request to the wish-list to be considered for inclusion in future releases.