Down Sampling version 3.0

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Fri Jun 01, 2007 6:54 am

Keith,

No, it shouldn't be necessary as the downsampling function does an internal redraw of the chart when CheckDataSource is called.

BTW, the example class I sent zooms and unzooms as expected with the DateTime values going forward.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

histry
Newbie
Newbie
Posts: 79
Joined: Thu Aug 10, 2006 12:00 am

Post by histry » Fri Jun 01, 2007 11:57 am

Christopher

With this sample I cannot get it to Unzoom, any idea what is missing as I have the times changed to ascending

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Steema.TeeChart;


namespace DownSample
{
public partial class Form1 : Form
{

private Steema.TeeChart.Styles.Points points;
private Steema.TeeChart.Styles.Line fastLine;
private Steema.TeeChart.Functions.DownSampling downSampling;
private Steema.TeeChart.Functions.DownSampling downSampling1;
private Nullable<double>[] xValues, yValues;


public Form1()
{
InitializeComponent();

InitializeChart();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void CreateArrays()
{
int length = 20000;

xValues = new Nullable<double>[length];
yValues = new Nullable<double>[length];

Random rnd = new Random();
for (int i = 0; i < length; i++)
{
DateTime dt = DateTime.Now - new TimeSpan(0, 0,( length -i ), 0);

xValues = dt.ToOADate();

if (i % 20 == 0)
{
yValues = null;
}
else
{
yValues = rnd.Next(100);
}
}
}

private void InitializeChart()
{
CreateArrays();
tChart1.Aspect.View3D = false;
tChart1.Zoom.Direction = ZoomDirections.Horizontal;
tChart1.Series.Add(new Steema.TeeChart.Styles.Points());
tChart1.Series.Add(new Steema.TeeChart.Styles.Line());

downSampling = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
downSampling1 = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
points = tChart1[0] as Steema.TeeChart.Styles.Points;
points.Add(xValues, yValues);
points.XValues.DateTime = true;
points.Active = false;

downSampling.DisplayedPointCount = 1000;
downSampling.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLastNull;
fastLine = tChart1[1] as Steema.TeeChart.Styles.Line;
fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
fastLine.XValues.DateTime = true;
fastLine.DataSource = points;
fastLine.Function = downSampling;
fastLine.Pointer.Visible = false;


CreateArrays();
downSampling1.DisplayedPointCount = 1000;
downSampling1.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLastNull;

tChart1.Series.Add(new Steema.TeeChart.Styles.Points());
tChart1.Series.Add(new Steema.TeeChart.Styles.Line());
points = tChart1[2] as Steema.TeeChart.Styles.Points;
points.Add(xValues, yValues);
points.XValues.DateTime = true;
points.Active = false;


fastLine = tChart1[3] as Steema.TeeChart.Styles.Line;
fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
fastLine.XValues.DateTime = true;
fastLine.DataSource = points;
fastLine.Function = downSampling1;

}

private void tChart1_Zoomed(object sender, EventArgs e)
{
tChart1[1].CheckDataSource(); //series 1 is the function series
tChart1[3].CheckDataSource();
}

private void tChart1_UndoneZoom(object sender, EventArgs e)
{
//tChart1.Axes.Bottom.SetMinMax(0, tChart1[0].Count); //series 0 is the original series, although you could use any value to set the maximum
tChart1[1].CheckDataSource();
tChart1[3].CheckDataSource();
}

private void udPointCount_ValueChanged(object sender, EventArgs e)
{
((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function).DisplayedPointCount = (int)udPointCount.Value;
((Steema.TeeChart.Functions.DownSampling)tChart1[3].Function).DisplayedPointCount = (int)udPointCount.Value;
//downSampling.DisplayedPointCount = (int)udPointCount.Value;
//downSampling1.DisplayedPointCount = (int)udPointCount.Value;
//tChart1.Axes.Bottom.SetMinMax(0, tChart1[0].Count);
tChart1[1].CheckDataSource();
tChart1[3].CheckDataSource();


}

}
}

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Mon Jun 04, 2007 8:59 am

Hello Keith,

I imagine that the problem is again related to the following line:

Code: Select all

 
DateTime dt = DateTime.Now - new TimeSpan(0, 0,( length -i ), 0); 
Try changing this line to this:

Code: Select all

 
DateTime dt = DateTime.Now + new TimeSpan(0, 0,( length -i ), 0); 
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

histry
Newbie
Newbie
Posts: 79
Joined: Thu Aug 10, 2006 12:00 am

Post by histry » Tue Jun 05, 2007 3:29 pm

Christopher

I made some modifications to the program to try and describe what I am finding when I have a small sample size. I used the line instead of fastline as I wanted to see the line points.

Issues:

1) If I do not display the points series only display the line series and its points when I check the downsample checkbox the line and its points are not displayed as well the count for the series is zero. I am seing this behavior in our project.

2) If I turn the visible of points series on and display the line and its points, I set the sample size to 10 there are points that are not being displayed and hence gaps in the line. There were no null points.


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Steema.TeeChart;


namespace DownSample
{
public partial class Form1 : Form
{

private Steema.TeeChart.Styles.Points points;
private Steema.TeeChart.Styles.Line fastLine;
private Steema.TeeChart.Functions.DownSampling downSampling;
private Steema.TeeChart.Functions.DownSampling downSampling1;
private Nullable<double>[] xValues, yValues;


public Form1()
{
InitializeComponent();

InitializeChart();
}

private void Form1_Load(object sender, EventArgs e)
{

}

private void CreateArrays()
{
int length = 100;

xValues = new Nullable<double>[length];
yValues = new Nullable<double>[length];

Random rnd = new Random();
for (int i = 0; i < length; i++)
{

DateTime dt = DateTime.Now - new TimeSpan(0, 0,( length -i ), 0);

xValues = dt.ToOADate();

yValues = 100 * Math.Sin(i * 10 * (Math.PI/180)) + 100;

//if (i % 20 == 0)
//{
// yValues = null;
//}
//else
//{
// yValues = rnd.Next(100);
//}
}
}

private void InitializeChart()
{
CreateArrays();
tChart1.Aspect.View3D = false;
tChart1.Zoom.Direction = ZoomDirections.Horizontal;
tChart1.Series.Add(new Steema.TeeChart.Styles.Points());
tChart1.Series.Add(new Steema.TeeChart.Styles.Line());

downSampling = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
downSampling1 = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
points = tChart1[0] as Steema.TeeChart.Styles.Points;
points.Add(xValues, yValues);
points.XValues.DateTime = true;
points.Active = true;

downSampling.DisplayedPointCount = 10;
downSampling.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLastNull;
fastLine = tChart1[1] as Steema.TeeChart.Styles.Line;
fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
fastLine.XValues.DateTime = true;
fastLine.LinePen.Width = 2;
fastLine.DataSource = points;
fastLine.Pointer.Visible = true;

numOfPoints.Text = points.Count.ToString();
lineCount.Text = tChart1[1].Count.ToString();

this.tChart1.Axes.Left.Automatic = false;
this.tChart1.Axes.Left.Maximum = 300;
this.tChart1.Axes.Left.Minimum = -50;

//CreateArrays();
//downSampling1.DisplayedPointCount = 10;
//downSampling1.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLastNull;

//tChart1.Series.Add(new Steema.TeeChart.Styles.Points());
//tChart1.Series.Add(new Steema.TeeChart.Styles.Line());
//points = tChart1[2] as Steema.TeeChart.Styles.Points;
//points.Add(xValues, yValues);
//points.XValues.DateTime = true;
//points.Active = true;


//fastLine = tChart1[3] as Steema.TeeChart.Styles.Line;
//fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
//fastLine.XValues.DateTime = true;
//fastLine.DataSource = points;
//fastLine.Function = downSampling1;

}

private void tChart1_Zoomed(object sender, EventArgs e)
{
tChart1[1].CheckDataSource(); //series 1 is the function series
//tChart1[3].CheckDataSource();
}

private void tChart1_UndoneZoom(object sender, EventArgs e)
{
//tChart1.Axes.Bottom.SetMinMax(0, tChart1[0].Count); //series 0 is the original series, although you could use any value to set the maximum
tChart1.Axes.Bottom.SetMinMax(tChart1[0].XValues.Minimum, tChart1[0].XValues.Maximum); //series 0 is the original series, although you could use any value to set the maximum
tChart1[1].CheckDataSource();
//tChart1[3].CheckDataSource();
}

private void udPointCount_ValueChanged(object sender, EventArgs e)
{
if((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function != null)
{
((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function).DisplayedPointCount = (int)udPointCount.Value;
//((Steema.TeeChart.Functions.DownSampling)tChart1[3].Function).DisplayedPointCount = (int)udPointCount.Value;
//downSampling.DisplayedPointCount = (int)udPointCount.Value;
//downSampling1.DisplayedPointCount = (int)udPointCount.Value;
//tChart1.Axes.Bottom.SetMinMax(0, tChart1[0].Count);
tChart1[1].CheckDataSource();
//tChart1[3].CheckDataSource();
}



}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked)
{
tChart1[1].Function = downSampling;

downSampling.DisplayedPointCount = (int)udPointCount.Value;
tChart1[1].CheckDataSource();
}
else
{
tChart1[1].Function = null;
tChart1[1].CheckDataSource();
}

lineCount.Text = tChart1[1].Count.ToString();
}

}
}

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Jun 06, 2007 9:40 am

Keith,

Back to basics. Running the following code:

Code: Select all

	public partial class Form1 : Form
	{

		private Steema.TeeChart.Styles.Points points;
		private Steema.TeeChart.Styles.Line fastLine;
		private Steema.TeeChart.Functions.DownSampling downSampling;
		private Nullable<double>[] xValues, yValues;


		public Form1()
		{
			InitializeComponent();
			InitializeChart();
		}

		private void CreateArrays()
		{
			int length = 4;

			xValues = new Nullable<double>[length];
			yValues = new Nullable<double>[length];

			Random rnd = new Random();
			for (int i = 0; i < length; i++)
			{
				xValues[i] = i;
				//yValues[i] = Utils.Round(rnd.NextDouble() * 100);
			}
			yValues[0] = 40;
			yValues[1] = 20;
			yValues[2] = 50;
			yValues[3] = 70;
		
		}

		private void AddValues()
		{
			CreateArrays();
			points.Clear();
			fastLine.Clear();
			points.Add(xValues, yValues);
			fastLine.CheckDataSource();
		}

		private void InitializeChart()
		{
			tChart1.Aspect.View3D = false;
			tChart1.Zoom.Direction = ZoomDirections.Horizontal;
			tChart1.Series.Add(new Steema.TeeChart.Styles.Points());
			tChart1.Series.Add(new Steema.TeeChart.Styles.Line());

			downSampling = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
			points = tChart1[0] as Steema.TeeChart.Styles.Points;

			downSampling.DisplayedPointCount = 4;
			downSampling.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLastNull;
			fastLine = tChart1[1] as Steema.TeeChart.Styles.Line;
			fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
			fastLine.LinePen.Width = 2;
			fastLine.DataSource = points;
			fastLine.Function = downSampling;
			fastLine.Pointer.Visible = true;
			fastLine.Active = true;

			AddValues();
		}

		private void tChart1_Zoomed(object sender, EventArgs e)
		{
			tChart1[1].CheckDataSource(); //series 1 is the function series
		}

		private void tChart1_UndoneZoom(object sender, EventArgs e)
		{
			tChart1.Axes.Bottom.SetMinMax(tChart1[0].XValues.Minimum, tChart1[0].XValues.Maximum); //series 0 is the original series, although you could use any value to set the maximum
			tChart1[1].CheckDataSource();
		}

		private void button1_Click(object sender, EventArgs e)
		{
			AddValues();
		}
	} 
Gives me the following chart:
Image

The debug variables look like this:

Code: Select all

*******************************
tmpsum 180
tmpmax 70
tmpmin 20
tmpfirst 40
tmpXfirst 0
tmpXmax 3
tmpXmin 1
tmplast 70
tmpXlast 3
*******************************
That is, the chart is plotting the first (0, 40), the min (1, 20), the max (3, 70) and the last (3, 70) in ascending xvalue order. This is, in theory, correct. I believe it is this, feature, which is causing the effects you are seeing. How would you like the algorithm to work in such cases? Exactly, what are the cases in which you'd like to see an alternative behaviour?
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

histry
Newbie
Newbie
Posts: 79
Joined: Thu Aug 10, 2006 12:00 am

Post by histry » Wed Jun 06, 2007 12:12 pm

Christopher

This is what I would have expected to see. If there were null points then the first null point would be displayed if not then would only display the first,last min and max

Why in the sample I sent when I have points.active = false and I set the number of downsample points to 10 the series count is showing zero. If I set the points.active to true I see the count as 11 but only 9 points displayed.
[/img]

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Jun 06, 2007 1:55 pm

Keith,

Ok, that's because the original series has values which are not null but which coincide with the Series.DefaultNullValue and so are treated as such. You can try changing this value, thus:

Code: Select all

	public partial class Form1 : Form
	{

		private Steema.TeeChart.Styles.Points points;
		private Steema.TeeChart.Styles.Line fastLine;
		private Steema.TeeChart.Functions.DownSampling downSampling;
		private Steema.TeeChart.Functions.DownSampling downSampling1;
		private Nullable<double>[] xValues, yValues;


		public Form1()
		{
			InitializeComponent();

			InitializeChart();
		}

		private void Form1_Load(object sender, EventArgs e)
		{

		}

		private void CreateArrays()
		{
			int length = 100;

			xValues = new Nullable<double>[length];
			yValues = new Nullable<double>[length];

			Random rnd = new Random();
			for (int i = 0; i < length; i++)
			{

				DateTime dt = DateTime.Now - new TimeSpan(0, 0, (length - i), 0);

				xValues[i] = dt.ToOADate();

				yValues[i] = 100 * Math.Sin(i * 10 * (Math.PI / 180)) + 100;
			}
		}

		private void InitializeChart()
		{
			CreateArrays();
			tChart1.Aspect.View3D = false;
			tChart1.Zoom.Direction = ZoomDirections.Horizontal;
			tChart1.Series.Add(new Steema.TeeChart.Styles.Points());
			tChart1.Series.Add(new Steema.TeeChart.Styles.Line());

			downSampling = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
			downSampling1 = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
			points = tChart1[0] as Steema.TeeChart.Styles.Points;
			points.DefaultNullValue = double.NegativeInfinity;
			points.Add(xValues, yValues);
			points.XValues.DateTime = true;
			points.Active = false;

			downSampling.DisplayedPointCount = 10;
			udPointCount.Value = downSampling.DisplayedPointCount;
			downSampling.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLastNull;
			fastLine = tChart1[1] as Steema.TeeChart.Styles.Line;
			fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
			fastLine.XValues.DateTime = true;
			fastLine.LinePen.Width = 2;
			fastLine.DataSource = points;
			fastLine.Pointer.Visible = true;

			numOfPoints.Text = points.Count.ToString();
			lineCount.Text = tChart1[1].Count.ToString();

			this.tChart1.Axes.Left.Automatic = false;
			this.tChart1.Axes.Left.Maximum = 300;
			this.tChart1.Axes.Left.Minimum = -50;

			checkBox1_CheckedChanged(checkBox1, EventArgs.Empty);

		}

		private void tChart1_Zoomed(object sender, EventArgs e)
		{
			tChart1[1].CheckDataSource(); //series 1 is the function series
		}

		private void tChart1_UndoneZoom(object sender, EventArgs e)
		{
			tChart1.Axes.Bottom.SetMinMax(tChart1[0].XValues.Minimum, tChart1[0].XValues.Maximum); //series 0 is the original series, although you could use any value to set the maximum
			tChart1[1].CheckDataSource();
		}

		private void udPointCount_ValueChanged(object sender, EventArgs e)
		{
			if ((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function != null)
			{
				((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function).DisplayedPointCount = (int)udPointCount.Value;
				tChart1[1].CheckDataSource();
			}
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			if (checkBox1.Checked)
			{
				downSampling.DisplayedPointCount = (int)udPointCount.Value;
				tChart1[1].Function = downSampling;
			}
			else
			{
				tChart1[1].Function = null;
			}
			tChart1[1].CheckDataSource();
			lineCount.Text = tChart1[1].Count.ToString();
		}

		private void checkBox2_CheckedChanged(object sender, EventArgs e)
		{
			points.Active = !points.Active;
		}

	} 
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

histry
Newbie
Newbie
Posts: 79
Joined: Thu Aug 10, 2006 12:00 am

Post by histry » Wed Jun 06, 2007 2:08 pm

Christopher

That corrects the issue with displaying the zero Point. Why is it when I set the Point.Active = false that the line series count goes to zero and nothing is displayed.

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Wed Jun 06, 2007 3:10 pm

Keith,

Running the following code:

Code: Select all

	public partial class Form1 : Form
	{

		private Steema.TeeChart.Styles.Points points;
		private Steema.TeeChart.Styles.Line fastLine;
		private Steema.TeeChart.Functions.DownSampling downSampling;
		private Steema.TeeChart.Functions.DownSampling downSampling1;
		private Nullable<double>[] xValues, yValues;


		public Form1()
		{
			InitializeComponent();

			InitializeChart();
		}

		private void Form1_Load(object sender, EventArgs e)
		{

		}

		private void CreateArrays()
		{
			int length = 100;

			xValues = new Nullable<double>[length];
			yValues = new Nullable<double>[length];

			Random rnd = new Random();
			for (int i = 0; i < length; i++)
			{

				DateTime dt = DateTime.Now - new TimeSpan(0, 0, (length - i), 0);

				xValues[i] = dt.ToOADate();

				yValues[i] = 100 * Math.Sin(i * 10 * (Math.PI / 180)) + 100;
			}
		}

		private void InitializeChart()
		{
			CreateArrays();
			checkBox1.Checked = true;
			tChart1.Aspect.View3D = false;
			tChart1.Zoom.Direction = ZoomDirections.Horizontal;
			tChart1.Series.Add(new Steema.TeeChart.Styles.Points());
			tChart1.Series.Add(new Steema.TeeChart.Styles.Line());

			downSampling = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
			downSampling1 = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
			points = tChart1[0] as Steema.TeeChart.Styles.Points;
			points.DefaultNullValue = double.NegativeInfinity;
			points.Add(xValues, yValues);
			points.XValues.DateTime = true;
			points.Active = true;

			downSampling.DisplayedPointCount = 10;
			udPointCount.Value = downSampling.DisplayedPointCount;
			downSampling.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLastNull;
			fastLine = tChart1[1] as Steema.TeeChart.Styles.Line;
			fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
			fastLine.XValues.DateTime = true;
			fastLine.LinePen.Width = 2;
			fastLine.DataSource = points;
			fastLine.Pointer.Visible = true;

			numOfPoints.Text = points.Count.ToString();
			lineCount.Text = tChart1[1].Count.ToString();

			this.tChart1.Axes.Left.Automatic = false;
			this.tChart1.Axes.Left.Maximum = 300;
			this.tChart1.Axes.Left.Minimum = -50;

			checkBox1_CheckedChanged(checkBox1, EventArgs.Empty);

		}

		private void tChart1_Zoomed(object sender, EventArgs e)
		{
			tChart1[1].CheckDataSource(); //series 1 is the function series
		}

		private void tChart1_UndoneZoom(object sender, EventArgs e)
		{
			tChart1.Axes.Bottom.SetMinMax(tChart1[0].XValues.Minimum, tChart1[0].XValues.Maximum); //series 0 is the original series, although you could use any value to set the maximum
			tChart1[1].CheckDataSource();
		}

		private void udPointCount_ValueChanged(object sender, EventArgs e)
		{
			if ((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function != null)
			{
				((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function).DisplayedPointCount = (int)udPointCount.Value;
				tChart1[1].CheckDataSource();
			}
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			if (checkBox1.Checked)
			{
				downSampling.DisplayedPointCount = (int)udPointCount.Value;
				tChart1[1].Function = downSampling;
			}
			else
			{
				tChart1[1].Function = null;
			}
			tChart1[1].CheckDataSource();
			lineCount.Text = tChart1[1].Count.ToString();
		}

		private void checkBox2_CheckedChanged(object sender, EventArgs e)
		{
			points.Active = !points.Active;
		}

	} 
Gives me the following image:
Image

Clicking on checkBox2 (Points.Active) gives me:
Image

That is, I can't seem to reproduce this issue using the above code and the lastest (unpublished) source for TeeChart v3.
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

histry
Newbie
Newbie
Posts: 79
Joined: Thu Aug 10, 2006 12:00 am

Post by histry » Wed Jun 06, 2007 5:01 pm

Christopher

I set the points to on and click the Downsample on and off everything works okay. I set the points to off and click the Downsample on and off and I get the problem. I emailed you screen shots as well as the assembly that I am using.

Christopher
Site Admin
Site Admin
Posts: 1349
Joined: Thu Jan 01, 1970 12:00 am
Location: Riudellots de la Selva, Catalonia
Contact:

Post by Christopher » Thu Jun 07, 2007 7:20 am

Keith,

This is because the FirstMinMaxLast function is sensitive to the first and last visible values of the source series, which it has to be in order to recalculate itself correctly when the chart is zoomed. With the source series set to inactive, these two values are also set to zero and the algorithm returns an empty set. You can, as before, set the bottom axis min and max values manually to work around this, e.g.

Code: Select all

	public partial class Form1 : Form
	{

		private Steema.TeeChart.Styles.Points points;
		private Steema.TeeChart.Styles.Line fastLine;
		private Steema.TeeChart.Functions.DownSampling downSampling;
		private Steema.TeeChart.Functions.DownSampling downSampling1;
		private Nullable<double>[] xValues, yValues;


		public Form1()
		{
			InitializeComponent();

			InitializeChart();
		}

		private void Form1_Load(object sender, EventArgs e)
		{

		}

		private void CreateArrays()
		{
			int length = 100;

			xValues = new Nullable<double>[length];
			yValues = new Nullable<double>[length];

			Random rnd = new Random();
			for (int i = 0; i < length; i++)
			{

				DateTime dt = DateTime.Now - new TimeSpan(0, 0, (length - i), 0);

				xValues[i] = dt.ToOADate();

				yValues[i] = 100 * Math.Sin(i * 10 * (Math.PI / 180)) + 100;
			}
		}

		private void InitializeChart()
		{
			CreateArrays();
			checkBox1.Checked = true;
			tChart1.Aspect.View3D = false;
			tChart1.Zoom.Direction = ZoomDirections.Horizontal;
			tChart1.Series.Add(new Steema.TeeChart.Styles.Points());
			tChart1.Series.Add(new Steema.TeeChart.Styles.Line());

			downSampling = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
			downSampling1 = new Steema.TeeChart.Functions.DownSampling(tChart1.Chart);
			points = tChart1[0] as Steema.TeeChart.Styles.Points;
			points.DefaultNullValue = double.NegativeInfinity;
			points.Add(xValues, yValues);
			points.XValues.DateTime = true;
			points.Active = false;

			downSampling.DisplayedPointCount = 10;
			udPointCount.Value = downSampling.DisplayedPointCount;
			downSampling.Method = Steema.TeeChart.Functions.DownSamplingMethod.MinMaxFirstLastNull;
			fastLine = tChart1[1] as Steema.TeeChart.Styles.Line;
			fastLine.TreatNulls = Steema.TeeChart.Styles.TreatNullsStyle.DoNotPaint;
			fastLine.XValues.DateTime = true;
			fastLine.LinePen.Width = 2;
			fastLine.DataSource = points;
			fastLine.Pointer.Visible = true;

			numOfPoints.Text = points.Count.ToString();
			lineCount.Text = tChart1[1].Count.ToString();

			this.tChart1.Axes.Left.Automatic = false;
			this.tChart1.Axes.Left.Maximum = 300;
			this.tChart1.Axes.Left.Minimum = -50;

		
			checkBox2.Checked = points.Active;
			checkBox1.Checked = false;

		}

		private void tChart1_Zoomed(object sender, EventArgs e)
		{
			tChart1[1].CheckDataSource(); //series 1 is the function series
		}

		private void tChart1_UndoneZoom(object sender, EventArgs e)
		{
			tChart1.Axes.Bottom.SetMinMax(tChart1[0].XValues.Minimum, tChart1[0].XValues.Maximum); //series 0 is the original series, although you could use any value to set the maximum
			tChart1[1].CheckDataSource();
		}

		private void udPointCount_ValueChanged(object sender, EventArgs e)
		{
			if ((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function != null)
			{
				((Steema.TeeChart.Functions.DownSampling)tChart1[1].Function).DisplayedPointCount = (int)udPointCount.Value;
				tChart1[1].CheckDataSource();
			}
		}

		private void checkBox1_CheckedChanged(object sender, EventArgs e)
		{
			if (checkBox1.Checked)
			{
				downSampling.DisplayedPointCount = (int)udPointCount.Value;
				tChart1[1].Function = downSampling;
			}
			else
			{
				tChart1[1].Function = null;
			}
			tChart1.Axes.Bottom.SetMinMax(tChart1[0].XValues.Minimum, tChart1[0].XValues.Maximum);
			tChart1[1].CheckDataSource();
			lineCount.Text = tChart1[1].Count.ToString();
		}

		private void checkBox2_CheckedChanged(object sender, EventArgs e)
		{
			points.Active = checkBox2.Checked;
		}

	} 
Thank you!

Christopher Ireland (Steema crew)
Please be aware of the newsgroup archives:
http://www.teechart.net/support/search.php
http://groups.google.com
http://codenewsfast.com/

histry
Newbie
Newbie
Posts: 79
Joined: Thu Aug 10, 2006 12:00 am

Post by histry » Thu Jun 07, 2007 12:31 pm

Christopher

That seems to have corrected the problem, I am not sure I understand why I need to set min max a number of times to get it to work or if it should be done within the object if required.

Post Reply