Page 1 of 1

TLineSeries.AddXY crashes with a label

Posted: Thu Jan 20, 2005 8:43 am
by 4206059
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

Posted: Thu Jan 20, 2005 11:05 am
by Marjan
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

Posted: Thu Jan 20, 2005 4:19 pm
by 4206059
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

Posted: Fri Jan 21, 2005 8:34 am
by Marjan
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;