Lazarus

Programming => Graphics and Multimedia => TAChart => Topic started by: apeoperaio on March 27, 2015, 01:53:52 pm

Title: [Solved] TAChart OnDrawLegend: legend size depends on Serie.Title
Post by: apeoperaio on March 27, 2015, 01:53:52 pm
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.
Why?
The GradientLineSeries.Title is not shown anywhere in the legend, why changing the title the legend position changes?
Title: Re: TAChart OnDrawLegend: legend size depends on Serie.Title
Post by: wp 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 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.
Title: Re: TAChart OnDrawLegend: legend size depends on Serie.Title
Post by: apeoperaio on March 30, 2015, 09:25:13 am
Ok. Now it is clear. Thanks.