Page 1 of 1

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

Posted: Mon May 15, 2006 6:03 pm
by 9345103
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?

Posted: Tue May 16, 2006 7:21 am
by narcis
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.

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

Posted: Tue May 16, 2006 3:59 pm
by 9345103
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

Posted: Wed May 17, 2006 7:45 am
by narcis
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;

Posted: Wed May 17, 2006 7:33 pm
by 9345103
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?

Posted: Wed May 17, 2006 7:38 pm
by 9345103
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

Posted: Thu May 18, 2006 8:34 am
by narcis
Hi Wayne,

No problem, I'm glad you found a solution to your needs.