Page 1 of 1
Grouping and counting data
Posted: Wed Apr 20, 2005 8:37 pm
by 9340972
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
Posted: Thu Apr 21, 2005 9:30 am
by narcis
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]));
Posted: Thu Apr 21, 2005 2:05 pm
by 9340972
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
Posted: Thu Apr 21, 2005 2:33 pm
by Marjan
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:
it will work fine, while on the other hand, if you do:
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]));
Posted: Thu Apr 21, 2005 2:43 pm
by 9340972
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
Posted: Thu Apr 21, 2005 5:52 pm
by Marjan
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;