Page 1 of 1

Downsampling without using an additional series.

Posted: Tue Dec 20, 2016 1:38 pm
by 16479504
Hello,

I would like to use the downsampling function to significantly reduce the amount of datapoints to speed up my application. In the demo example for downsampling, series2 uses series 1 as a datasource. How can I downsample series 1 without needing another series?

Re: Downsampling without using an additional series.

Posted: Wed Dec 21, 2016 8:25 am
by yeray
Hello,

All the functions in TeeChart need a series attached to draw the data calculated. You can use the same series you are using as DataSource, just note you'll be loosing the origin values doing it.
In the following example I'm using two charts. In the first chart I'm using a new TLineSeries to draw the output of the function and I'm hiding the source series. In the second chart I'm using the same origin series as output for the function.
The result is the same in both charts:

Code: Select all

uses TeeDownSampling;

var lineSeries1, lineSeries2: TLineSeries;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.View3D:=False;
  Chart2.View3D:=False;
  Chart1.Legend.Visible:=False;
  Chart2.Legend.Visible:=False;

  lineSeries1:=Chart1.AddSeries(TLineSeries) as TLineSeries;
  lineSeries2:=Chart2.AddSeries(TLineSeries) as TLineSeries;

  lineSeries1.FillSampleValues(2000);
  lineSeries2.DataSource:=lineSeries1;
end;

procedure TForm1.Button1Click(Sender: TObject);
var downSamplingFunction1, downSamplingFunction2: TDownSamplingFunction;
    downSamplingSeries: TLineSeries;
begin
  downSamplingSeries:=Chart1.AddSeries(TLineSeries) as TLineSeries;
  downSamplingSeries.DataSource:=lineSeries1;
  downSamplingSeries.Color:=lineSeries1.Color;

  downSamplingFunction1:=TDownSamplingFunction.Create(Self);
  downSamplingSeries.SetFunction(downSamplingFunction1);
  downSamplingFunction1.Tolerance:=10;
  lineSeries1.Visible:=False;

  downSamplingFunction2:=TDownSamplingFunction.Create(Self);
  lineSeries2.SetFunction(downSamplingFunction2);
  downSamplingFunction2.Tolerance:=10;
end;