TeeCanvas polygons

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
Toreba
Newbie
Newbie
Posts: 3
Joined: Fri Aug 10, 2018 12:00 am

TeeCanvas polygons

Post by Toreba » Thu Jan 31, 2019 12:23 pm

Hi,

I want to shade a quadrilateral area of the TChart panel to indicate a certain range of validity of plotted values. I'm not sure of the best way to do this. I found that I can draw a polygon using TeCanvas.TCanvas3D.Polygon, and I have put that in the chart's AfterDraw event with other annotation. But the polygon is not clipped at chart axes, and so extends off onto the panel in which the TChart is embedded. Do I have to re-calculate intersection points of polygon and axes every time the users zooms or pans?

I would like the shading to appear beneath the plotted points and grid lines, but above the back wall. I can't find the combination of Brush.Style and BackMode that achieves this.

Is there a better way of achieving this shading effect?

Thanks for any advice

Toreba

Yeray
Site Admin
Site Admin
Posts: 8746
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: TeeCanvas polygons

Post by Yeray » Fri Feb 08, 2019 4:22 pm

Hello,

Excuse us for the delayed reply here.
Toreba wrote:
Thu Jan 31, 2019 12:23 pm
I want to shade a quadrilateral area of the TChart panel to indicate a certain range of validity of plotted values. I'm not sure of the best way to do this. I found that I can draw a polygon using TeCanvas.TCanvas3D.Polygon, and I have put that in the chart's AfterDraw event with other annotation. But the polygon is not clipped at chart axes, and so extends off onto the panel in which the TChart is embedded. Do I have to re-calculate intersection points of polygon and axes every time the users zooms or pans?
You should Clip the ChartRect: Ie:

Code: Select all

    ClipRectangle(Chart1.ChartRect);
    Rectangle(rect);  // or Polygon, etc
    UnClipRectangle;
Toreba wrote:
Thu Jan 31, 2019 12:23 pm
I would like the shading to appear beneath the plotted points and grid lines, but above the back wall. I can't find the combination of Brush.Style and BackMode that achieves this.
I see a couple of options.
You could draw your rectangle at the OnAfterDraw event with some transparency.
You could draw your rectangle at the OnBeforeDrawAxes event.

Ie:
Project1_2019-02-08_17-17-32.png
Project1_2019-02-08_17-17-32.png (16.38 KiB) Viewed 895 times

Code: Select all

uses TeCanvas;

procedure TForm1.Chart1AfterDraw(Sender: TObject);
var rect: TRect;
    blend: TTeeBlend;
begin
  with Chart1.Canvas do
  begin
    rect.Left:=Chart1.Axes.Bottom.CalcPosValue(14);
    rect.Right:=Chart1.Axes.Bottom.CalcPosValue(20);
    rect.Top:=Chart1.Axes.Left.CalcPosValue(1300);
    rect.Bottom:=Chart1.Axes.Left.CalcPosValue(1500);

    Brush.Color:=clRed;

    ClipRectangle(Chart1.ChartRect);
    blend:=BeginBlending(rect, 50);
    Rectangle(rect);
    EndBlending(blend);
    UnClipRectangle;
  end;
end;

procedure TForm1.Chart1BeforeDrawAxes(Sender: TObject);
var rect: TRect;
begin
  with Chart1.Canvas do
  begin
    rect.Left:=Chart1.Axes.Bottom.CalcPosValue(2);
    rect.Right:=Chart1.Axes.Bottom.CalcPosValue(8);
    rect.Top:=Chart1.Axes.Left.CalcPosValue(1100);
    rect.Bottom:=Chart1.Axes.Left.CalcPosValue(1300);

    Brush.Color:=clRed;

    ClipRectangle(Chart1.ChartRect);
    Rectangle(rect);
    UnClipRectangle;
  end;
end;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Toreba
Newbie
Newbie
Posts: 3
Joined: Fri Aug 10, 2018 12:00 am

Re: TeeCanvas polygons

Post by Toreba » Tue Feb 12, 2019 11:49 am

Yeray!

Thanks for a very helpful answer. I didn't realise these methods existed. The clipping works very well - fantastic!

As regards blending, the shape I'm drawing is a polygon, not a rectangle, and blending seems to require the specification of a rectangle. So I tried blending with the entire chart rectangle and that works okay too. If I plot the polygon in the OnBeforeDrawAxes event, then I get the result I want, which is that the series points sit above the blended polygon, and aren't blended themselves. Fantastic too!

My final step is to put an item into the legend describing the polygon... but I think I know how to do that...

Excellent support, thanks again!

Regards

Post Reply