painting background below y=0

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Andy
Newbie
Newbie
Posts: 3
Joined: Thu May 20, 2004 4:00 am

painting background below y=0

Post by Andy » Tue Jun 15, 2004 1:01 pm

How does one go about painting the chart background red below the y=0 line?

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

Post by Marjan » Wed Jun 16, 2004 7:11 am

Hi, Andy.

You could use chart OnBeforeDrawAxes event to paint a rectable directly on chart's Canvas. Something like this:

Code: Select all

Uses Math;

procedure TForm1.Chart1BeforeDrawAxes(Sender: TObject);
var R: TRect;
begin
  R.Left := Chart1.ChartRect.Left;
  R.Right := Chart1.ChartRect.Right;
  // trick to avoid costly clipping routine
  R.Top := Max(Chart1.Axes.Left.CalcYPosValue(0.0),Chart1.ChartRect.Top);
  R.Bottom := Chart1.ChartRect.Bottom;
  if R.Top < R.Bottom then
  With Chart1.Canvas do
  begin
    Brush.Color := clRed;
    Rectangle(R,0); // draw at z=0
  end;
end;
Marjan Slatinek,
http://www.steema.com

Post Reply