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
TeeCanvas polygons
Re: TeeCanvas polygons
Hello,
Excuse us for the delayed reply here.
You could draw your rectangle at the OnAfterDraw event with some transparency.
You could draw your rectangle at the OnBeforeDrawAxes event.
Ie:
Excuse us for the delayed reply here.
You should Clip the ChartRect: Ie:Toreba wrote: ↑Thu Jan 31, 2019 12:23 pmI 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?
Code: Select all
ClipRectangle(Chart1.ChartRect);
Rectangle(rect); // or Polygon, etc
UnClipRectangle;
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:
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,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: TeeCanvas polygons
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
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