Grouping and counting data

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Red77
Newbie
Newbie
Posts: 8
Joined: Mon Feb 14, 2005 5:00 am

Grouping and counting data

Post by Red77 » Wed Apr 20, 2005 8:37 pm

Hi,
(Im using Teechart through Digital Metaphors Report Builder.)

How do I count the number of records against a certain field parameter.
IE: if I have a table with 5 ford records, 2 volvo records, 3 saab records and so on. I want a bar chart with bar levels 5, 2, 3.
BUT If there are 4 red fords and 1 yellow one, I get two bars for ford (values 4 and 1).
And this happens even if I do not include the colour column in my table.

Thanks

Red

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

Post by Narcís » Thu Apr 21, 2005 9:30 am

Hi Red,

You can retrieve every bar value doing something like:

Code: Select all

  for i:=0 to Series1.Count-1 do
    Chart1.Title.Text.Add(FloatToStr(Series1.YValue[i]));
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

Red77
Newbie
Newbie
Posts: 8
Joined: Mon Feb 14, 2005 5:00 am

Post by Red77 » Thu Apr 21, 2005 2:05 pm

Hi,
Thanks but I get an "undeclared identifier" error on this too.
Im a novice at Teechart and maybe theres something Im missing here.

Should this work within the calc section or Digital Metphors Report Builder?

Red

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

Post by Marjan » Thu Apr 21, 2005 2:33 pm

Hi.

First thing to do is check what component are listed in the form IDE generated section. For example, if you drop a TChart on the (empty) form, the following classes will be added to form (published) section:

Code: Select all

type
  TForm1 = class(TForm)
    Chart1: TChart;
  private
This means that if you later in your code do:

Code: Select all

Chart1.Title.Text.Clear;
it will work fine, while on the other hand, if you do:

Code: Select all

Series1.FillSampleValues(5);
it will fail because Series1 (class) is NOT declared. I think in your case not Series1 nor Chart1 are declared (perhaps ppChart1 is declared). The code Narcis posted is ok, but you can't simpyl copy&paste it as you're most likely using different names. For example, the following code does te same thing, but it's adapted for my test application:

Code: Select all

for i:=0 to DBTeeChart1.Series[0].Count-1 do 
    DBTeeChart1.Title.Text.Add(FloatToStr(DBTeeChart1.Series[0].YValue[i]));
Marjan Slatinek,
http://www.steema.com

Red77
Newbie
Newbie
Posts: 8
Joined: Mon Feb 14, 2005 5:00 am

Post by Red77 » Thu Apr 21, 2005 2:43 pm

Hi Marjan,
Im a beginner but I do realise that I can not copy and paste your object names.
The only IDE object I have is "DPTeeChart1". No series listed.

Within my design tab I can edit my object. In there I have just one series called Series1.

Anyway I now get the error
"Undeclared identifier 'i'"

I really think Im missing a step somewhere.

Thanks

Red

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

Post by Marjan » Thu Apr 21, 2005 5:52 pm

Hi.

"i" should be declared as integer. You can do this in form private section or in the procedure where you call the code posted above.

Code: Select all

var i: Integer;
begin // your procedure
  for i:=0 to DPTeeChart1.Series[0].Count-1 do 
    DPTeeChart1.Title.Text.Add(FloatToStr(DPTeeChart1.Series[0].YValue[i]));
end;
Marjan Slatinek,
http://www.steema.com

Post Reply