Number of rows in a Legend with LegendScrollbar?
Posted: Fri Jul 10, 2009 3:29 pm
Hello,
I was wondering if there is a way to determine at run time the number of LegendItems that are currently being displayed within a Legend. I'm generating a tChart with a variable number of FastLine series, featuring a Legend on the right side and a LegendScrollbar using DrawStyle WhenNeeded. I'm allowing the form window to be resizable, so the number of LegendItems that are displayed changes with the form size.
Since I may have many FastLines in the chart, I'm trying to use the ClickSeries event to help the user identify which series was clicked. Right now the event temporarily increases the LinePen.Width of the selected line (and restores it with MouseUp), and the short line segment attached to the corresponding LegendItem thickens too. I like that. However, if for example I have N = 50 series in the chart but only M = 10 visible LegendItems (at one specific window size), there's a possibility that the clicked series might not be one of the 10 in the Legend, so I've been having the event adjust the Legend.FirstValue to automatically scroll the legend to make sure the clicked series name is always displayed.
However, if I simply set FirstValue to the clicked series index, when I select the last series in the collection (seriesIndex [N-1]) the legend shrinks to only 1 LegendItem high. What I'd really like to be able to do is set things up so that I can inquire what the displayed LegentItem count M is, and then adjust FirstValue as necessary to keep the number of LegendItems fixed for that window size.
So for
clicked seriesIndex in the range [0,M-1], set FirstValue to 0 (scroll to show the top M items)
clicked seriesIndex in [M,N-M-1], set FirstValue to seriesIndex-M/2 (scroll to show M items centered around seriesIndex) or
clicked seriesIndex in [N-M,N-1], set FirstValue to N-M (scroll to show the bottom M items)
Any recommendations greatly appreciated!
Thank you,
Bob
I was wondering if there is a way to determine at run time the number of LegendItems that are currently being displayed within a Legend. I'm generating a tChart with a variable number of FastLine series, featuring a Legend on the right side and a LegendScrollbar using DrawStyle WhenNeeded. I'm allowing the form window to be resizable, so the number of LegendItems that are displayed changes with the form size.
Since I may have many FastLines in the chart, I'm trying to use the ClickSeries event to help the user identify which series was clicked. Right now the event temporarily increases the LinePen.Width of the selected line (and restores it with MouseUp), and the short line segment attached to the corresponding LegendItem thickens too. I like that. However, if for example I have N = 50 series in the chart but only M = 10 visible LegendItems (at one specific window size), there's a possibility that the clicked series might not be one of the 10 in the Legend, so I've been having the event adjust the Legend.FirstValue to automatically scroll the legend to make sure the clicked series name is always displayed.
However, if I simply set FirstValue to the clicked series index, when I select the last series in the collection (seriesIndex [N-1]) the legend shrinks to only 1 LegendItem high. What I'd really like to be able to do is set things up so that I can inquire what the displayed LegentItem count M is, and then adjust FirstValue as necessary to keep the number of LegendItems fixed for that window size.
So for
clicked seriesIndex in the range [0,M-1], set FirstValue to 0 (scroll to show the top M items)
clicked seriesIndex in [M,N-M-1], set FirstValue to seriesIndex-M/2 (scroll to show M items centered around seriesIndex) or
clicked seriesIndex in [N-M,N-1], set FirstValue to N-M (scroll to show the bottom M items)
Any recommendations greatly appreciated!
Thank you,
Bob