Page 1 of 1

Bottom axis and smoothed line series

Posted: Tue Jan 07, 2014 9:26 pm
by 16467963
Hi,

I want to smooth a line series, but the Y values of this series may change.
Reading other posts on this forum, I understood that I cannot simply use the Smoothed property, I must update the smoothed series manually.

So I have added two line series to my chart, Series1 and Series2.
Series2 is a line series with an associated smoothing function, and the Source Series for Series2 is Series1.

The problem is : when I hide Series1 and show the smoothed series Series2 the bottom axis changes and no longer shows all the X axis labels, as shown below :

Image

Image

Am I doing something wrong ? How can I preserve and show all X axis labels ?

Thank You

Fabio Lyrio

Re: Bottom axis and smoothed line series

Posted: Tue Jan 07, 2014 9:28 pm
by 16467963
My source code :

unit Test;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, TeeGDIPlus, TeEngine, TeeSpline, Series, ExtCtrls, TeeProcs,
Chart, StdCtrls, Buttons;

type
TForm1 = class(TForm)
Chart1: TChart;
Series1: TLineSeries;
Series2: TLineSeries;
TeeFunction1: TSmoothingFunction;
BitBtn1: TBitBtn;
procedure FormShow(Sender: TObject);
procedure BitBtn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
var
i : word;
begin
for i:= 1 to 12 do
Series1.AddY(Random(100),Chr(64+i), clTeecolor);
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
i : word;
begin
Series2.CheckDataSource;
Series1.Active := False;
Series2.Active := True;
for i:= 1 to 12 do
Series2.XLabel := Chr(64+i);
end;

end.

Re: Bottom axis and smoothed line series

Posted: Thu Jan 09, 2014 9:19 am
by narcis
Hi Fabio,

What happens here is that smoothed series has many more points than the original series. Original text labels are not related to X values but index values. Therefore, they only last for the first few points in the smoothed series. It's clearly seen at the Data tab in the chart editor:
SmoothedData.jpg
SmoothedData.jpg (146.21 KiB) Viewed 4856 times
An easy solution to your problem might be using custom axis labels, for example:

Code: Select all

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  i : word;
begin
  Series2.CheckDataSource;
  Series1.Active := False;
  Series2.Active := True;

  Chart1.Axes.Bottom.Items.Clear;

  for i:= 0 to 12 do
    Chart1.Axes.Bottom.Items.Add(i, Chr(65+i));
end;

Code: Select all

I want to smooth a line series, but the Y values of this series may change.
Reading other posts on this forum, I understood that I cannot simply use the Smoothed property, I must update the smoothed series manually.
Why not? The code snippet below works fine for me:

Code: Select all

procedure TForm1.FormShow(Sender: TObject);
var
  i : word;
begin
  for i:= 1 to 12 do
    Series1.AddY(Random(100),Chr(64+i), clTeecolor);

  Series1.Smoothed:=True;
  Series2.Active := False;
end;

procedure TForm1.BitBtn1Click(Sender: TObject);
var
  i : word;
begin
  Chart1.Axes.Bottom.Items.Clear;

  for i:= 0 to Series1.Count-1 do
  begin
    Series1.YValues[i]:=i + i mod 2;
    Chart1.Axes.Bottom.Items.Add(i, Chr(65+i));
  end;
end;

Re: Bottom axis and smoothed line series

Posted: Thu Jan 09, 2014 11:57 pm
by 16467963
Ok NarcĂ­s,

The custom axis labels solution worked fine, problem solved for me, thank you!

Regarding the comment about using the Smoothed parameter, I saw later that before changing the Y values on my application I was clearing the series with Series1.Clear, and apparently that disabled the smoothing property.

Fabio