Discussion:
How to create a chart in code?
Felipe Monteiro de Carvalho
2011-07-02 13:11:13 UTC
Permalink
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

--
Felipe Monteiro de Carvalho
2011-07-02 13:31:58 UTC
Permalink
Ok, I found the answer myself =)

I should use TChart.AddSeries to add the series not TChart.Series.Lists.Add...
--
Felipe Monteiro de Carvalho

--
Alexander Klenin
2011-07-02 14:18:28 UTC
Permalink
Post by 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

--
Florian Klämpfl
2011-07-02 14:22:19 UTC
Permalink
Post by Alexander Klenin
Post by 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.

--
Sven Barth
2011-07-02 14:53:23 UTC
Permalink
Post by Florian Klämpfl
Post by Alexander Klenin
Post by 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

--

Continue reading on narkive:
Loading...