painting background below y=0
painting background below y=0
How does one go about painting the chart background red below the y=0 line?
Hi, Andy.
You could use chart OnBeforeDrawAxes event to paint a rectable directly on chart's Canvas. Something like this:
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
http://www.steema.com