Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-07

How to create a chart in code?

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Felipe Monteiro de Carvalho

Hello,

I am trying to use TAChart, so I dropped TChart in my form and I added some code to draw some lines:

var
  LineSeries: TLineSeries;
  i, j: Integer;
begin
  for i := 0 to Length(Model.PoliticalParties) - 1 do
  begin
    LineSeries := TLineSeries.Create(Application);
    for j := 0 to Length(Model.PoliticalParties[i].ElectionPools)-1 do
      LineSeries.AddXY(j, Model.PoliticalParties[i].ElectionPools[j]);
    chartPools.Series.List.Add(LineSeries);
  end;
end;

But then it crashes here:

procedure TCustomChartSeries.GetGraphBounds(var ABounds: TDoubleRect);
begin
  GetBounds(ABounds);
  with ABounds do begin
    TransformByAxis(FChart.AxisList, AxisIndexX).UpdateBounds(a.X,
b.X); <---- crash
    TransformByAxis(FChart.AxisList, AxisIndexY).UpdateBounds(a.Y, b.Y);
    if IsRotated then begin
      Exchange(a.X, a.Y);
      Exchange(b.X, b.Y);
    end;
  end;
end;

Any ideas how I should add some lines to the chart instead?

The wiki is down, by the way.

thanks,

Felipe Monteiro de Carvalho

Reply by email

Alexander Klenin
to Felipe Monteiro de Carvalho

2011/7/3 Felipe Monteiro de Carvalho :

Ok, I found the answer myself =) I should use TChart.AddSeries to add the series not TChart.Series.Lists.Add...

Yes. Unfortunately, FPList does not support any notification mechanism, and its Add method is not virtual.

Alexander S. Klenin

Reply by email

Florian Klämpfl
to Alexander Klenin
Alexander Klenin wrote 8 lines
2011/7/3 Felipe Monteiro de Carvalho : > Ok, I found the answer myself =) > > I should use TChart.AddSeries to add the series not TChart.Series.Lists.Add... Yes. Unfortunately, FPList does not support any notification mechanism, and its Add method is not virtual.

Use TList then. The idea of TFPList to have a simple and fast list.

Reply by email

Sven Barth
to Florian Klämpfl
Florian Kl?mpfl wrote 11 lines
Am 02.07.2011 16:18, schrieb Alexander Klenin: > 2011/7/3 Felipe Monteiro de Carvalho: >> Ok, I found the answer myself =) >> >> I should use TChart.AddSeries to add the series not TChart.Series.Lists.Add... > > Yes. Unfortunately, FPList does not support any notification mechanism, > and its Add method is not virtual. > Use TList then. The idea of TFPList to have a simple and fast list.

This is even mentioned in the book "The Tomes of Delphi - Algorithms and Data Structures". "TList" used to be very fast until Borland introduced the notification mechanism (I don't remember which version of Delphi it was).
So if you don't need notifications, but prefer performance you should use something else like FPC's "TFPList" (or "TFPObjectList"). If you need the notification mechanism then you use "TList" (or "TObjectList"), but you'll have a performance impact.

As a sidenote: FPC's "TList" is implemented using a "TFPList" internally.

Regards,
Sven

Reply by email