Confused by Chart1[i] notation

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
bfalter
Newbie
Newbie
Posts: 4
Joined: Wed Oct 13, 2010 12:00 am

Confused by Chart1[i] notation

Post by bfalter » Wed Oct 27, 2010 5:30 pm

Hi,

I'm reading through a code example provided by Yeray » 03 May 2007 08:44. Here's a piece of that code.

for i := 0 to nSeries-1 do
begin
Chart1.AddSeries(TLineSeries);
Chart1.CustomAxes.Add;
Chart1.CustomVertAxis := Chart1.CustomAxes.Items;
Chart1.CustomAxes.Items.Axis.Color := Chart1.Color;
Chart1.CustomAxes.Items.Grid.Visible := False;
ComboBox2.Items.Add('Series' + inttostr(i + 1));
Chart1.FillSampleValues(20000);
Chart1.CustomAxes.Items.PositionUnits := muPixels;
if ((i+1) mod 2 = 0) then
Chart1.CustomAxes.Items.OtherSide := True;
end;

I'm confused by the array index attached to some of the Chart1 references in that code. I'm clearly missing something because that notation doesn't make any sense to me. The notation Chart1 suggests there is an array of several charts, however, I'm reasonably sure the example was meant to apply to a single instance of a single TChart component. I haven't been able to find anything in the documentation that suggests why this notation is valid. Can you explain what Yeray is up to there?
Thanks!
Brian

ChartIt
Newbie
Newbie
Posts: 29
Joined: Tue Mar 13, 2007 12:00 am

Re: Confused by Chart1[i] notation

Post by ChartIt » Thu Oct 28, 2010 2:13 am

Chart1 refers to the series for Chart1.

bfalter
Newbie
Newbie
Posts: 4
Joined: Wed Oct 13, 2010 12:00 am

Re: Confused by Chart1[i] notation

Post by bfalter » Thu Oct 28, 2010 3:05 am

Thank you for the reply. That's very helpful. I accept that answer although the syntax still doesn't make sense to me. I can't quite picture the underlying structure. It's probably obvious if you study the TeeChart source code - which I don't have. It's enough for my purposes right now to understand what the code does even if I don't know why that particular syntax works. Thanks again.

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

Re: Confused by Chart1[i] notation

Post by Narcís » Thu Oct 28, 2010 11:38 am

Hi bfalter,

Using Chart1 is the same as using Chart1.Series. I guess it was made for simplicity since most common objects to be in a chart are series but you can freely use the latter if you prefer.
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

bfalter
Newbie
Newbie
Posts: 4
Joined: Wed Oct 13, 2010 12:00 am

Re: Confused by Chart1[i] notation

Post by bfalter » Thu Oct 28, 2010 4:36 pm

Hi Narcis,

Thanks for the explanation. Everything makes sense now.

Best regards,
Brian

Post Reply