[SOLVED] Draw circle into a TAChart with axis transformation lazarus / 55-TAChart ---------------------------------------------------------------------- donnie · 2016-04-20 10:25 Hi there once again, This might be a silly question but I need to draw some circles into a tachart which already has some lines(series). I want the circles to have axis transormation and when I zoom I want them to be zoomed(not like pieseries which ignore axis transformation). I tried some tests with 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   chart1.Canvas.Clear;  chart1.Canvas.Create;  chart1.Canvas.Ellipse(0,0,5,5);  chart1.Canvas.FillRect(0,0,5,5);but no result yet. I must also have zposition in order to be behind the lines. Can someone help me how to draw a circle e.g starting from 0,0 with radius 2. Thank you, in advance ---------------------------------------------------------------------- wp · 2016-04-20 16:28 You question would be clearer if you would write what this circle is for. Must it be a circle in any case, i.e. even if different units are drawn along the x and y axes? When you talk about transformations: are you aware that non-linear transformations (log axis) distort the circle? There are several solutions and I don't want to list all of them just for fun. ---------------------------------------------------------------------- donnie · 2016-04-21 06:49 Sorry for the misunderstanding. I want to do the same as I did with the area series. But at this time instead of area series I want to draw a circle(or more) behind the lines. For eg let's say that I have the diagram as you can see at the first image(diagram example). If the lines have a zposition 1000 I want a circle with zposition eg.100 and when I zoom to the diagram I want the circle to be zoomed as well as the lines and the axis do. In the second picture(diagram example with circles) I tried to show you how it should be. I don't mind if the circles will be filled with color or just like the picture. I don't know if I was clear now. I hope I did! ---------------------------------------------------------------------- wp · 2016-04-21 09:06 Ah, some kind of circular coordinate system... You may use this procedure to paint a circle with a given radius, color and pen style: 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 uses  TAGeometry; procedure TForm1.DrawCircleToCanvas(ACanvas: TCanvas; ARadius: Double;  AColor: TColor; AStyle: TPenStyle);// assuming center at (0,0)var  p1, p2: TPoint;  x1, x2, y1, y2: double;  R: TRect;begin  // Prepare pen and brush  ACanvas.Pen.Color := AColor;  ACanvas.Pen.Style := AStyle;  ACanvas.Brush.Style := bsClear;   // Take care of clipping (otherwise circle will reach into axis labels)  R := ACanvas.ClipRect;  ACanvas.ClipRect := Chart1.ClipRect;  ACanvas.Clipping := true;   // Calculate "corner" points in pixels  x1 := Chart1.BottomAxis.GetTransform.AxisToGraph(-ARadius);  x2 := Chart1.BottomAxis.GetTransForm.AxisToGraph(+ARadius);  y1 := Chart1.LeftAxis.GetTransForm.AxisToGraph(-ARadius);  y2 := Chart1.LeftAxis.GetTransform.AxisToGraph(+ARadius);  p1 := Chart1.GraphToImage(DoublePoint(x1, y1));  p2 := Chart1.GraphToImage(DoublePoint(x2, y2));   // Draw "circle"  ACanvas.Ellipse(p1.x, p1.y, p2.x, p2.y);   // Restore clipping parameters  ACanvas.Clipping := false;  ACanvas.ClipRect := R;end; Call this in 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);begin  DrawCircleToCanvas(ACanvas, 1.0, clRed, psDot);  DrawCircleToCanvas(ACanvas, 2.0, clRed, psDot);end; The chart drawing events are explained in http://wiki.lazarus.freepasc al.org/TAChart_Tutorial:_Background_design. Two notes: Of course, the circle will be distorted to an ellipse if x and y axes have different units. Use Chart1.Proportional := true to enforce equal units.If you intend to paint the chart onto a bgrabitmap or an svg file this code will not be executed because is does not use the drawing-backend interface. You could use the OnAfterDraw method and replace the Canvas calls by IDrawer calls. But then the circle will be painted on top of the series. If you don't want this I'd have to modify TAChart to extend the OnAfterDraw event to accept an IDrawer parameter. ---------------------------------------------------------------------- donnie · 2016-04-21 11:20 Perfect as always wp!!! Can I also fill these circles with color somehow? Is there any documentation for these kind of procedures? Once again, thank you very much ---------------------------------------------------------------------- wp · 2016-04-21 11:29 Of course, just use the Brush of the Canvas. Note that the OnAfterDrawBackwall event comes before axes and series are drawn, this means that the axis grid will be painted over the filled circle. Maybe you won't like that... The OnAfterDraw event on the other hand is the last event, i.e. the filled circle will paint over the series which is certainly worse. Regarding documentation, there's the wiki tutorial which I mentioned, and there's the TAChart documentation. There's no explicit doc for the most important run-time functions - I want to write a tutorial, but don't have a good idea yet. ---------------------------------------------------------------------- donnie · 2016-04-21 12:10 Excellent!!! I have read those documentations but the world needs your tutorial ASAP in order not to spend your time with all these 'simple' questions!!! ---------------------------------------------------------------------- donnie · 2016-04-27 13:58 Hi again wp, I used the OnAfterDrawBackwall  to draw my circles but I can't print them. The axes and the lines can be printed very well. But the circles are missing. The code for printing is this : 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 else if (Memo[0] = 'ChartCircles') and (View is TfrPictureView) then  begin  pv := View as TfrPictureView;    bmp := TBitmap.Create;    try      bmp.Width := Round(pv.Width);      bmp.Height := Round(pv.Height);     bmp.Width := 200;       bmp.Height := 230;      ChartCircles.PaintOnCanvas(bmp.Canvas, Rect(0, 0, bmp.Width, bmp.Height));      pv.Picture.Bitmap.Assign(bmp);    finally      bmp.Free;    end;  end  The photo attached: the first one is the normal photo and the second is the print preview (and print result) photo. Any ideas? ---------------------------------------------------------------------- wp · 2016-04-27 15:12 What does your OnAfterDrawBackground code look like? Are you painting on the chart's canvas or on the canvas provided as a parameter? You must paint on the latter one; in the printpreview this is the canvas of the bitmap, and during printing it is the canvas of the printer, the chart's canvas is not used during print preview or during printing. ---------------------------------------------------------------------- donnie · 2016-04-28 06:28 Yes, I was printing on Chart.Canvas and not the sender Acanvas. I fixed it now. Thanks a lot again!!!