Detect when Legend Scrollbar is at maximum position

TeeChart VCL for Borland/CodeGear/Embarcadero RAD Studio, Delphi and C++ Builder.
Post Reply
MVBobj
Newbie
Newbie
Posts: 34
Joined: Fri Jul 17, 2015 12:00 am
Contact:

Detect when Legend Scrollbar is at maximum position

Post by MVBobj » Mon Sep 21, 2015 2:20 pm

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
.

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Detect when Legend Scrollbar is at maximum position

Post by Yeray » Wed Sep 23, 2015 2:55 pm

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;
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Yeray
Site Admin
Site Admin
Posts: 9514
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Detect when Legend Scrollbar is at maximum position

Post by Yeray » Tue Sep 29, 2015 2:13 pm

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 683 times
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply