Author Topic: [Solved] TAChart OnDrawLegend: legend size depends on Serie.Title  (Read 2718 times)


  • Full Member
  • ***
  • Posts: 173
I am using OnDrawLegend to draw a custom colorbar legend. I noticed that the legend position depends on the Serie Title property.
You can check it using the legenddemo.lpi.
Changing GradientLineSeries.Title affect the position (not the size) of the Legend. Try removing the title and/or using a long title, you will see the legend changing position.
The GradientLineSeries.Title is not shown anywhere in the legend, why changing the title the legend position changes?
« Last Edit: March 30, 2015, 09:25:29 am by apeoperaio »


  • Hero Member
  • *****
  • Posts: 7218
Re: TAChart OnDrawLegend: legend size depends on Serie.Title
« Reply #1 on: March 27, 2015, 04:35:07 pm »
The owner-drawn legend means: you draw the legend by yourself. The event OnDrawlegend just gets a rectangle where the chart would draw the regular legend. With "regular legend" I mean the standard, non-owner-drawn legend. You can respect this rectangle, or you can ignore it and paint the legend anywhere else within the chart boundaries. The size of the regular legend depends on various properties:
  • The width of the legend symbol of the series (Chart.Legend.SymbolWidth)
  • The length of the legend items of each series - this in turn depends on what is selected in the Legend property of the series:
  • Series.Legend.Multiplicity:
    - lmSingle --> use series title.
    - lmPoint --> use longest series data point label
    - lmStyle --> consider ChartStyles as needed for stacked series
The position where this rectangle is reserved depends on Chart.Legend.Alignment and Chart.Legend.UseSidebar. The latter property, in particular, is important because it (if set to true) forces the chart to reduces its size such that the regular legend does not reach into the plot.

In the legend demo (tachart/demo/legend folder), the Chart.Legend.Alignment is taTopRight and UseSideBar is true, i.e. space is reserved as a band at the right of the chart. It is natural to paint the owner-drawn legend there. The width of the band is determined by the Series.Legend.Multiplicity=lmSingle and the dummy series title ("1.0"), and the LegendSymbolWidth -> this is enough for the gradient bar (approximate width = LegendSymbolWidth) and data labels (width like width of "1.0")). There is no direct parameter to specify the width reserved for the legend, but as I explained there are enough other parameters which can be "mis-used" to control the space.

The series title does not appear because it is not drawn - look at the event handler of OnDrawLegend in the demo.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10


  • Full Member
  • ***
  • Posts: 173
Re: TAChart OnDrawLegend: legend size depends on Serie.Title
« Reply #2 on: March 30, 2015, 09:25:13 am »
Ok. Now it is clear. Thanks.


TinyPortal © 2005-2018