TLineSeries.AddXY crashes with a label

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Jorg B
Newbie
Newbie
Posts: 6
Joined: Thu Mar 01, 2001 5:00 am
Location: Netherlands

TLineSeries.AddXY crashes with a label

Post by Jorg B » Thu Jan 20, 2005 8:43 am

Excuse me for putting this problem in the wrong forum. I deleted it and moved it to this one:

Hi there,

Delphi5, TeeChart 5.01, Windows 2K

Whenever I try to call AddXY of a TLineSeries with a label as well like;

aSerie.addXY(I + 1, 100, 'label here');

The TeeChart raises an exception. Is there somethign special I need to do to get labels on my axis ? The exception is cought by ReportBuilder, thus I cannot see what TeeChart notifies me (reportbuilder replaces the exception with "Cannot create report") ..

There is nothing odd about the lineseries, nor the chart, this also happens on a plain chart with one series.

Thank you for your help,
- Jorgen

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Thu Jan 20, 2005 11:05 am

Hi.

Old TeeChart v4 Standard (version shipped with Delphi) has axis label related bug. It is triggered only if you have one series with one value or if all series values are the same. A workaround has been posted in this forum. But I think we fixed this in TeeChart v4.03 release.

Do you get the error only if series has one point or if all point values are equal ? Perhaps the problem is with multiline label (I remember one of older TeeChart versions raised AV error when multiline labels were being used. Try setting axis labels multiline property to false. If it works, then you can still use TChart OnGetAxisLabel event to make the labels multiline. Example:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
begin
  Chart1.BottomAxis.LabelsMultiLine := False;
  Series1.AddXY(1,2,'Multiline label');
end;

procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis;
  Series: TChartSeries; ValueIndex: Integer; var LabelText: String);
begin
  if Sender = Chart1.BottomAxis then
    TeeSplitInLines(LabelText,' ');
end;
I think this bug was fixed in TeeChart v6.0
Marjan Slatinek,
http://www.steema.com

Jorg B
Newbie
Newbie
Posts: 6
Joined: Thu Mar 01, 2001 5:00 am
Location: Netherlands

Post by Jorg B » Thu Jan 20, 2005 4:19 pm

Hi Marjan,

I am using TChart 5.01 .. As you tell me this bug should not exist in 5 since it was fixed in 4 ?

I probably get this error when there are series with 1 point, because that is what I see, it stays at the 0 level.

So what you suggest is that I use the event OnGetAxisLabel instead of giving the AddXY series a label as parameter?

Thank you for your help!
- Jorgen

Marjan
Site Admin
Site Admin
Posts: 745
Joined: Fri Nov 07, 2003 5:00 am
Location: Slovenia
Contact:

Post by Marjan » Fri Jan 21, 2005 8:34 am

Hi, Joerg.

No. The OnGetAxisLabel trick will solve the multiline label bug. For single point problem/bug you should manually set axis ranges to (point_value-offset, point_value+offset). You can do this in TChartSeries.OnAfterAdd event and check if series minimum is equal to maximum. If yes, manually set axis minimum and maximum value, otherwise leave it automatic.

Code: Select all

procedure TForm1.Series1BeforeDrawValues(Sender: TObject);
begin
  if (Sender is TChartSeries) then
    with Sender as TChartSeries do
    begin
      if YValues.MaxValue = YValues.MinValue then
        GetVertAxis.SetMinMax(YValues.MaxValue-1.0,YValues.MaxValue+1.0)
      else GetVertAxis.Automatic := True;
    end;
end;
Marjan Slatinek,
http://www.steema.com

Post Reply