Legend positioning lazarus / 55-TAChart ---------------------------------------------------------------------- mtanner · 2015-11-01 11:43 The legend Alignment parameter gives basic control over positioning. Also there is Sidebar, and MarginX/MarginY to refine positioning. laTopLeft, on a simple conventional X-Y chart result in the legend obliterating part of the Y axis and scale.  Similarly laBottomCenter will obliterate the X-axis and scale. Sidbar is too wasteful of screen space. What I really want to do is to have Alignment operate relative to the plot area (excluding space taken up with scales and actual axes). I know I can do this with MarginX or MarginY, but it's trial and error to know what MarhinX/Y values are needed to push the legend off the scales. Is there some parameter I have missed for doing the above? Alternatively is there a TAGraph function which will calculate the position of the X-axis (Y-axis) so that this value can be used to set MarginX/Y?  (There is such a function in TeeChart but I can't find it in TAGraph). ---------------------------------------------------------------------- wp · 2015-11-01 15:47 Hmm... Legend overlapping with axes if UseSideBar is false seems to be a bug. I uploaded a fix (r50201). But be aware: UseSidebar=false is not good as a general setting because the legend still may overlap with data points. The chart box surrounded by the axes can be accessed by means of the property ClipRect of the chart. Note, however, that all the positioning calculations are done during painting, i.e. ClipRect changes during the various painting stages. Only in the OnExtentChanging/OnAfterDraw/OnAfterPaint events the ClipRect does not change any more - but then, in the latter two, the legend is already drawn. And I am not sure, but I'd guess that repositioning the legend in one of these events would trigger another painting run which will fire these events again, i.e. you will end up with a stack overflow... So, better stick to the fix mentioned above. I would appreciate if you could test it because in my own charts I do not work with UseSidebar=false. If you do not use the trunk version of Lazarus you should open TAGraph.pas (it is in (lazarus)/components/tachart), scroll down to TChart.Draw. In the "try" block, after "PrepareAxis", add the two lines marked by "new"; then recompile the TAChart package: 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 TChart.Draw(ADrawer: IChartDrawer; const ARect: TRect);...  try    PrepareAxis(ADrawer);    if Legend.Visible and not Legend.UseSidebar then   // <--- new      Legend.Prepare(ldd, FClipRect);                // <--- new    if (FPrevLogicalExtent <> FLogicalExtent) and Assigned(OnExtentChanging) then      OnExtentChanging(Self);    ADrawer.DrawingBegin(ARect);         ... ---------------------------------------------------------------------- mtanner · 2015-11-01 18:47 Thanks, I will have ago with that. I generally prefer UseSidBar=false, because UseSideBar=true uses up space that could oterwise be used to display the chart bigger.  There is often blank space in the plotting area, so that if the user can easily control the legend position to the extent of Left/Center/Right and Top/Middle/bottom then the legend can usually be fitted in withoyt obscuring any data. I'm biased by using Latex/PgfPlots, where you can, if you wish, specify legend position in minute detail, but for routine use PgfPlots provides:-  [north west, north, north east, outer north east, west, east, south west, south, south east] All except "outer north east" puts the legend within the plotting area.  Outer north east being provided for those cases where the legen in the plot area would obscure that data.