how to set individual color for each bar based on data label

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Wayne
Newbie
Newbie
Posts: 7
Joined: Fri Jan 27, 2006 12:00 am

how to set individual color for each bar based on data label

Post by Wayne » Mon May 15, 2006 6:03 pm

Hi,

I am currently using TeeChart Pro V 7.0 with Report Builder 7.0.4. I am creating a report of bar graphs. However, I need the ability to set the individual color of each bar for each graph to be based on the data label. Is there any way of doing this? If so, can you provide a sample on how this is done?

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

Post by Narcís » Tue May 16, 2006 7:21 am

Hi Wayne,

Can you please be more specific on what kind of information will be in the labels and how would you like to colors to be?

Thanks in advance.
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

Wayne
Newbie
Newbie
Posts: 7
Joined: Fri Jan 27, 2006 12:00 am

how to set individual color for each bar based on data label

Post by Wayne » Tue May 16, 2006 3:59 pm

Hi Narcis,

What I am trying do is this. I have a database of a survey that people took. I need to generate a bar graph report using report builder 7.0.4 of the data summary for each question answered. I would like to have the colors of the answers to be consistent. For example say 10 people took this survey:

The presentation was informative:
Strongly Agree (5) Blue
Agree (2) Yellow
Disagree (1) Green
Strongly Disagree(3) Red

The presenter was very knowledgeable:
Strongly Agree (3) White
Agree (3) Blue
No Opinion (2) Yellow
Disagree (1) Green
Strongly Disagree (1) red

I need to be able to assign colors based on what the label is such as "Agree" above needs to be assigned to specific color say "Blue" no matter what order it is in for each bar for each graph created in the report. Please keep in mine that each graph is created with only one serie. Any idea?

thanks!
--Wayne

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

Post by Narcís » Wed May 17, 2006 7:45 am

Hi Wayne,

You could do something like this:

Code: Select all

procedure TForm1.FormCreate(Sender: TObject);
var i: Integer;
begin
  With Series1 do
  begin
    ColorEachPoint:=true;

    Add(5,'Strongly Agree');
    Add(2,'Agree');
    Add(1,'Disagree');
    Add(3,'Strongly Disagree');

    for i:=0 to Count-1 do
    begin
      if Labels[i]='Strongly Agree' then ValueColor[i]:=clBlue
      else if Labels[i]='Agree' then ValueColor[i]:=clYellow
           else if Labels[i]='Disagree' then ValueColor[i]:=clGreen
                else ValueColor[i]:=clRed;
    end;
  end;
end;
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

Wayne
Newbie
Newbie
Posts: 7
Joined: Fri Jan 27, 2006 12:00 am

Post by Wayne » Wed May 17, 2006 7:33 pm

Hi Narcis,

I see where you are getting at with your example. However, the problem I am having with now is how to do this within ReportBuilder. The only event I access to is the OnPrint event for the Chart embedded inside the report. The other events I tried playing with was under report builder's detail band events which are AfterGenerate, AfterPrint, BeforeGenerate, and BeforePrint. The sample you provided is for the manual creation of the serie which is perfectly fine in a static scenario. However, the charts I am generating is using reportbuilder's DBpipeline to automatically populate the data for the serie. Any more ideas?

Wayne
Newbie
Newbie
Posts: 7
Joined: Fri Jan 27, 2006 12:00 am

Post by Wayne » Wed May 17, 2006 7:38 pm

Narcis,

Sorry I have answered my own question. I found the event I needed to accomplish this task. I am using the ontraversal event of reportbuilder's DBpipline and it's working for me. Thanks for the example to point me to the right direction!

--Wayne

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 May 18, 2006 8:34 am

Hi Wayne,

No problem, I'm glad you found a solution to your needs.
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

Post Reply