Page 1 of 1

Number of rows in a Legend with LegendScrollbar?

Posted: Fri Jul 10, 2009 3:29 pm
by 15653872
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

Re: Number of rows in a Legend with LegendScrollbar?

Posted: Mon Jul 13, 2009 10:43 am
by 10050769
Hello BobG,
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.
I couldn't reproduce your problem here with last version of TeeChartFor .Net. Please, could you send us a simple example project we can run "as-is" to reproduce the problem here? .Now, you can attach your project directly in forums post. Also, you could said with version of TeeChartFor.Net you are using?

Thanks,

Re: Number of rows in a Legend with LegendScrollbar?

Posted: Mon Jul 13, 2009 2:23 pm
by 15653872
I'm using TeeChart 2009 for .NET (Pro V4?) on Visual Studio 2005.

To clarify my original post, the tChart is anchored to all four sides of the parent form so it resizes along with the form. So the "problem" I'm trying to solve is determining the number of legend items that can be displayed at a given form/legend height.

I've uploaded a short project. When the form opens at its default size, only 20 of the 50 items are displayed. When maximized, all 50 show up. Rather than just setting the FirstValue to my clicked series index so the clicked series legend item is always at the top of the legend box, I want to be sure to be able to display the clicked series between its neighbors in the legend, even if the user shrinks the window so small that only 5 legend items show up.

Thank you very much,

Bob

Re: Number of rows in a Legend with LegendScrollbar?

Posted: Tue Jul 14, 2009 10:23 am
by yeray
Hi Bob,

There is no property to do that but you can calculate your MaxItemsInLegend knowing the chart height and how many pixels in height take for every item:

Code: Select all

int MaxItemsInLegend = (tChart1.Height / 17);

Re: Number of rows in a Legend with LegendScrollbar?

Posted: Tue Jul 14, 2009 5:23 pm
by 15653872
Thank you, Yeray. I'll give that a try!