Page 1 of 1

Detect when Legend Scrollbar is at maximum position

Posted: Mon Sep 21, 2015 2:20 pm
by 16475083
Hi,

I have a chart with a scrollbar and the legend has a scrollbar. I have the scrollbars tracking along with each other using various events.

When there is a difference between the number of visible items on the chart and the items visible on the legend scrollbar, then when the one with the most items reaches it's scrollbar max, the other ISN'T at it's max. Usually it's the legend scrollbar that has more and when it reaches it's max, the chart isn't displaying it's maximum items. This could be confusing to end users.

My solution is: When the legend scrollbar hits bottom - set the chart's scrollbar to max position.

How can I detect when the legend scrollbar has reached it's maximum position? A standard scrollbar has max, min & position properties I can evaluate and adjust to accordingly - but the legend scrollbar does not.

Similarly - how would I set the legend scrollbar to max position if the chart scrollbar reaches max position first?

Two questions:

1. How can I detect when the legend scrollbar has reached it's maximum position?

2. How can I set the legend scrollbar to it's maximum position?

Thanks
.

Re: Detect when Legend Scrollbar is at maximum position

Posted: Wed Sep 23, 2015 2:55 pm
by yeray
Hello,

The TLegendScrollBar is designed to work automatically so that's why it's not customizable at this level.
You can access and change it's Position property, but you can't change min and max.
You can assign any number to Position but bear in mind the Legend will draw as many values as possible from the index at the given Position. Ie::
- If you set a if you set a Position:=Chart1[0].Count-1 it will only show the last value of the series.
- If you set Position:=Chart1[0].Count it will show nothing.
- If you set Position:=-1 it crashes.
MVBobj wrote:1. How can I detect when the legend scrollbar has reached it's maximum position?
I'm afraid there's no property or function giving that at this moment, so you could calculate the maximum number of rows that can be drawn for the given chart height.
MVBobj wrote:2. How can I set the legend scrollbar to it's maximum position?
Same as above. If you calculate the number of rows that can be drawn, then this is easy.

This is how the number of rows is internally calculated:

Code: Select all

  Function MaxLegendRows(const YLegend:Integer):Integer;
  begin
    if (YLegend<ParentChart.ChartRect.Bottom) and (ItemHeight>0) then
    Begin
      result:={$IFDEF FMX}Round{$ENDIF}(ParentChart.ChartHeight-FrameWidth-YLegend+ParentChart.ChartRect.Top) div ItemHeight;
      result:=Math.Min(result,TotalLegendItems);
    end
    else
      result:=0;
  end;

Re: Detect when Legend Scrollbar is at maximum position

Posted: Tue Sep 29, 2015 2:13 pm
by yeray
Hello,

As you have observed here, the code I posted is not complete enough.
I took the example you posted here and modified it to calculate and show the number of rows in the legend as similar as possible to how it is calculated internally.
Here it is the project modified:
TeeChartLegend.zip
(3.57 KiB) Downloaded 778 times