Page 1 of 1

painting background below y=0

Posted: Tue Jun 15, 2004 1:01 pm
by 9337560
How does one go about painting the chart background red below the y=0 line?

Posted: Wed Jun 16, 2004 7:11 am
by Marjan
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;