Page 1 of 1

Trendfunction

Posted: Tue Jul 21, 2009 1:38 pm
by 15653372
Hi,

If i want a trend line for a serie, but not for the whole range of the serie, what is the best way to do this?
I couldn't find any methods / properties in the trendfunction that allow me to only do a trend on a part of the serie.

I tried to hack the serie values, remove some values and give the "new" serie to the datasource. But this doesn't seem to work correct:

Steema.TeeChart.Functions.TrendFunction t = new Steema.TeeChart.Functions.TrendFunction();
t.TrendStyle = Steema.TeeChart.Functions.TrendStyles.Normal;

double[] originalX = series.XValues.Value;
double[] originalY = series.YValues.Value;
int orginalCountX = series.XValues.Count;
int orginalCountY = series.YValues.Count;

List<double> xvalues = new List<double>();
for (int i=0; i < series.XValues.Count - 500; i++) //Remove last 500 values
xvalues.Add(series.XValues.Value);

List<double> yvalues = new List<double>();
for (int i=0; i < series.YValues.Count - 500; i++) //remove last 500 values
yvalues.Add(series.YValues.Value);

//Overwrite the current serie with the new values
series.XValues.Count = xvalues.Count;
series.YValues.Count = yvalues.Count;
series.XValues.Value = xvalues.ToArray();
series.YValues.Value = yvalues.ToArray();

Line trendLine = new Line();
trendLine.DataSource = series;//this.Series;
trendLine.Function = t;

this.StartPos = new Steema.TeeChart.Drawing.PointDouble(trendLine[0].X, trendLine[0].Y); //Here the trendline Y value is not correct anymore.
this.EndPos = new Steema.TeeChart.Drawing.PointDouble(trendLine[trendLine.Count - 1].X, trendLine[trendLine.Count - 1].Y);
this.Pen.Style = System.Drawing.Drawing2D.DashStyle.Dash;
this.Pen.Color = this.Series.Color;
this.Pen.Width = 2;

//Restore the serie values to the original ones
int xc = originalX.Count();
int yc = originalY.Count();
series.XValues.Value = originalX;
series.YValues.Value = originalY;
series.XValues.Count = orginalCountX;
series.YValues.Count = orginalCountY;

Re: Trendfunction

Posted: Tue Jul 21, 2009 2:38 pm
by 15653372
My bad, i changed the series in the end that was used in the datasource. With a new serie it works ok. Just wondering if there isn't an easier way to do this?

Re: Trendfunction

Posted: Tue Jul 21, 2009 2:48 pm
by yeray
Hi SPS,

The functions are thought to have a series by source, not a part of them. So I'm afraid that I can't think on another way to do this right now.