How To Color Chart / Back Wall to Align with X-Axis values

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
madupree
Newbie
Newbie
Posts: 5
Joined: Thu Aug 06, 2015 12:00 am

How To Color Chart / Back Wall to Align with X-Axis values

Post by madupree » Sun Jul 31, 2016 6:06 pm

Hi Support
I am building an application and would like to color/paint the back wall to indicate system operating conditions.
This color needs to match X-Axis values as this color 1 of 7 can vary with time or the X-Axis value.
I would like for this color to follow when the chart is zoomed.
Any hints would be great.
Regards
Mike

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How To Color Chart / Back Wall to Align with X-Axis values

Post by Sandra » Mon Aug 01, 2016 8:59 am

Hello Mike,

I think you can be useful define a colors table and use the Chart GetAxisLabel event to change the walls color as you want. The simple code below give you an idea as you can do:

Code: Select all

uses Series;
var Series1:TLineSeries;
colorTable : array[1..7] of TColor;
procedure TForm1.Chart1GetAxisLabel(Sender: TChartAxis; Series: TChartSeries;
  ValueIndex: Integer; var LabelText: string);
begin
if ValueIndex = 1 then
begin
Chart1.Walls.Back.Gradient.Visible :=false;
Chart1.Walls.Back.Color := colorTable[2];
end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D := false;
Series1 := TLineSeries.Create(Self);
Chart1.AddSeries(Series1);
Series1.FillSampleValues(10);
//CrecteTableColrs
AddColors;
end;
 procedure TForm1.AddColors;
 begin
 colorTable[1]:=clWhite;
 colorTable[2] := clBlack;
 colorTable[3] := clGray;
 colorTable[4] := clRed;
 colorTable[5] := clBlue;
 colorTable[6] := clGreen;
 colorTable[7] := clYellow;
 end;
end.
Hoping this helps you
Thanks in advance
Best Regards,
Sandra Pazos / 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

madupree
Newbie
Newbie
Posts: 5
Joined: Thu Aug 06, 2015 12:00 am

Re: How To Color Chart / Back Wall to Align with X-Axis values

Post by madupree » Mon Aug 01, 2016 11:28 am

Hello Sandra,
Thanks for the reply, I will use the code to get started and give you a reply
Regards
Mike

madupree
Newbie
Newbie
Posts: 5
Joined: Thu Aug 06, 2015 12:00 am

Re: How To Color Chart / Back Wall to Align with X-Axis values

Post by madupree » Mon Aug 01, 2016 4:21 pm

Hello Sandra,
Tried your code and it works and I understand what is going on.

However, I may not have stated clearly what I am wanting to do.
In the example there are 10 X-Axis points.
Here's what I am trying to do
From points 0 to 2 use Color[3]
From points 3 to 7 use Color[6]
From points 8 to 9 use Color[4].

Basically painting the back wall a color as a function of X-Axis position.
Again Thanks for a clever way to paint the back wall.
Is what I'd like to do possible?
Regards
Mike

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How To Color Chart / Back Wall to Align with X-Axis values

Post by Sandra » Tue Aug 02, 2016 12:53 pm

Good afternon Mike,

Many thanks for the clarification.

I have modified the previous code we sent you, so Chart wall changes when you click in the concretely axis value position using the ClickAxis event. The code below shows you how:

Code: Select all

uses Series;
var Series1:TLineSeries;
colorTable : array[1..7] of TColor;
procedure TForm1.Chart1ClickAxis(Sender: TCustomChart; Axis: TChartAxis;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if Axis = Chart1.Axes.Bottom then
  begin
     if Axis.Clicked(X,Y) then
     begin
       if  (Trunc(Axis.CalcPosPoint(X))= 0) or (Trunc(Axis.CalcPosPoint(X))= 1) or (Trunc(Axis.CalcPosPoint(X))= 2) then
       begin
              Chart1.Walls.Back.Gradient.Visible :=false;
              Chart1.Walls.Back.Color := colorTable[2];
       end
       else if (Trunc(Axis.CalcPosPoint(X))= 3) or (Trunc(Axis.CalcPosPoint(X))= 4) or (Trunc(Axis.CalcPosPoint(X))= 5)or (Trunc(Axis.CalcPosPoint(X))= 6) or (Trunc(Axis.CalcPosPoint(X))= 7)then
       begin
             Chart1.Walls.Back.Gradient.Visible :=false;
             Chart1.Walls.Back.Color := colorTable[1];
       end
       else if (Trunc(Axis.CalcPosPoint(X))= 8) or (Trunc(Axis.CalcPosPoint(X))= 9) or (Trunc(Axis.CalcPosPoint(X))= 10) then
       begin
             Chart1.Walls.Back.Gradient.Visible :=false;
             Chart1.Walls.Back.Color := colorTable[3];
       end;

     end;

  end;
end;



procedure TForm1.FormCreate(Sender: TObject);
begin
Chart1.View3D := false;
Series1 := TLineSeries.Create(Self);
Chart1.AddSeries(Series1);
Series1.FillSampleValues(10);
//CrecteTableColrs
AddColors;
end;
procedure TForm1.AddColors;
begin
colorTable[1]:=clWhite;
colorTable[2] := clBlack;
colorTable[3] := clGray;
colorTable[4] := clRed;
colorTable[5] := clBlue;
colorTable[6] := clGreen;
colorTable[7] := clYellow;
end;
Could you confirm is the code above works in your end?

Thanks in advance,
Best Regards,
Sandra Pazos / 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

madupree
Newbie
Newbie
Posts: 5
Joined: Thu Aug 06, 2015 12:00 am

Re: How To Color Chart / Back Wall to Align with X-Axis values

Post by madupree » Wed Aug 03, 2016 7:57 pm

Hello Sandra,
I thought I had posted a reply however cannot find it.
I tried the code it works however not what I am looking to do.

While poking about I found a tool Color Band, looks like what I am trying to do.
The color band's orientation can be set so it looks promising.
Now am I correct each ColorBand can set a single color?
So for multiple colors I will need several bands?
Is there a preferred way to implement this so as not slow the execution?
Regards
Mike

Sandra
Site Admin
Site Admin
Posts: 3132
Joined: Fri Nov 07, 2008 12:00 am

Re: How To Color Chart / Back Wall to Align with X-Axis values

Post by Sandra » Thu Aug 04, 2016 9:05 am

Hello Mike,
Now am I correct each ColorBand can set a single color?
Yes, you can set a solid color for each color band. Also, if you are interested, you can set a hatch or gradient to ColorBand Tool
So for multiple colors I will need several bands?
If you want see multiple colors simultaneously, is needed use multiple color bands, but is possible use a Colorband and changes the color if you want use that in different time periods.
Is there a preferred way to implement this so as not slow the execution?
The uses of colorbands tool shouldn’t cause performance problems, but in the case you detected any problems, don’t hesitate to contact with us.

Hoping this helps
Thanks in advance
Best Regards,
Sandra Pazos / 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

madupree
Newbie
Newbie
Posts: 5
Joined: Thu Aug 06, 2015 12:00 am

Re: How To Color Chart / Back Wall to Align with X-Axis values

Post by madupree » Thu Aug 04, 2016 11:28 am

Hello Sandra,
Thanks for the reply.
I will let you know if there are any performance issues
Mike

Post Reply