brush in arbitrary triangle lazarus / 55-TAChart ---------------------------------------------------------------------- frederic · 2017-07-02 14:13 dear specialists in a chart i have 3 arbitrary lines crossing eachother. they form an arbitrary triangle. i want to brush the enclosed surface with a color is this possible in TAchart? frederic ---------------------------------------------------------------------- wp · 2017-07-02 14:33 Please post an example ---------------------------------------------------------------------- frederic · 2017-07-03 15:27 wp i prepared a small example ,see attachment. when you press  "showlinesbtn", then the 3 lines, which form the triangle ,will appear. it is the same as with the shape component but now in TAchart and with arbitrary appearance.( dimensions and slopes can be changed) frederic ---------------------------------------------------------------------- wp · 2017-07-03 16:20 Since you calculate the intersection points you could draw the triangle in the OnAfterDrawBackwall event. This occurs before axes and series are drawn. Since TAChart does all scaling calculations within its Draw method the chart must have been drawn at least once before the background triangle can be activated, but your ShowLinesBtnClick procedure is perfect for this... Write this procedure and assign it to the OnAfterDrawBackwall event of the chart: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Chart1AfterDrawBackWall(ASender: TChart; ACanvas: TCanvas;  const ARect: TRect);var  P: array[0..3] of TPoint;begin  if not TriangleOK then    exit;   P[0] := Chart1.GraphToImage(DoublePoint(xcross[0], ycross[0]));  P[1] := Chart1.GraphToImage(DoublePoint(xcross[1], ycross[1]));  P[2] := Chart1.GraphToImage(DoublePoint(xcross[2], ycross[2]));  P[3] := P[0];  ACanvas.Brush.Style := bsSolid;  ACanvas.Brush.Color := clRed;  ACanvas.Polygon(P);end; Then... Declare a boolean variable TriangleOK. You can see in the code above that the triangle is not painted if TriangleOK is falseSet TriangleOK to False at the end of FormCreate.Set it to false also at the beginning of DeleteLinesClick. The chart will be redrawn after lineA.Clear etc, but since TriangleOK is false, the triangle will not painted any more.Set it to TRUE at the end of successful completion of ShowLinesBtnClick and call Chart1.Invalidate afterwards. Before this line is reached the chart has been repainted, i.e. the axis scaling has been done, because you have added datapoints to the lineseries. And ShowLinesBtnClick calculates the intersection points. ---------------------------------------------------------------------- frederic · 2017-07-03 19:11 wp thanks a lot looking at the code i  expect that this approach can be used in a more generic way -   so 4 or more lines which enclose a surfrace ,as long as you can calculate P0.....Pn am i right? - or another mathematical function(for each x only one  y-value,no circles and introduce more P[n] to approach the curve) with a line     or am i streching it now too far? a last question:because i have to redraw the chart i suppose that this can only be done once for each chart with a number of these enclosures i have to combine them in the same OnAfterDrawBackwall event thanks anyway, we start experimenting frederic ---------------------------------------------------------------------- wp · 2017-07-03 20:19 Yes all this extra drawing must be done in the OnAfterDrawBackWall event. So if you have several items to appear subsequently you must add some logic to this procedure - a primitive logic was the TriangleOK variable of my example. You can draw anything you want. But since you are plotting data in axis units you must make sure that the chart has been drawn at least once before you show these extras - otherwise the conversion from axis coordinates to pixels would not be known. ---------------------------------------------------------------------- frederic · 2017-07-04 07:37 oke, this offers then also the possibility to use the textout function: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  pospx:=   chart1.XGraphToImage(xcross[0]+ xmarge); pospy:=   chart1.YGraphToImage(ycross[0]+ymarge); ACanvas.TextOut( pospx,pospy,'P0'); which would solve the previous  discussion of adding text to a chart nice now find out what the implecations are for zooming and panning frederic ---------------------------------------------------------------------- wp · 2017-07-04 09:13 Quote from: frederic on July 04, 2017, 09:37:12 amwhich would solve the previous  discussion of adding text to a chart Hmm... The OnAfterDrawBackwall event is called very early, before series are drawn. Therefore, you must expect that series can paint over your text... Maybe you should try the OnAfterDraw event which comes when everything is complete. Please note this event does not expose a Canvas but an IChartDrawer interface for painting. Here's an example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.Chart1AfterDraw(ASender: TChart; ADrawer: IChartDrawer);begin  ADrawer.SetFont(ASender.Title.Font);  ADrawer.TextOut.Pos(100, 100).Text('Hallo').Done;end; ---------------------------------------------------------------------- frederic · 2017-07-04 15:10 thanks, i experienced a hidden text already for the reason you mentioned i will try both methods and see what works best in coding the extreme points of the series. thanks again frederic