Bottom axis and smoothed line series

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Fabio Lyrio
Newbie
Newbie
Posts: 3
Joined: Wed Dec 04, 2013 12:00 am

Bottom axis and smoothed line series

Post by Fabio Lyrio » Tue Jan 07, 2014 9:26 pm

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

Fabio Lyrio
Newbie
Newbie
Posts: 3
Joined: Wed Dec 04, 2013 12:00 am

Re: Bottom axis and smoothed line series

Post by Fabio Lyrio » Tue Jan 07, 2014 9:28 pm

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.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Re: Bottom axis and smoothed line series

Post by Narcís » Thu Jan 09, 2014 9:19 am

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 4855 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;
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Fabio Lyrio
Newbie
Newbie
Posts: 3
Joined: Wed Dec 04, 2013 12:00 am

Re: Bottom axis and smoothed line series

Post by Fabio Lyrio » Thu Jan 09, 2014 11:57 pm

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

Post Reply