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
Number of rows in a Legend with LegendScrollbar?
Re: Number of rows in a Legend with LegendScrollbar?
Hello BobG,
Thanks,
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?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.
Thanks,
Best Regards,
Sandra Pazos / Development & Support Steema Software Avinguda Montilivi 33, 17003 Girona, Catalonia Tel: 34 972 218 797 http://www.steema.com |
Instructions - How to post in this forum |
Re: Number of rows in a Legend with LegendScrollbar?
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
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
- Attachments
-
- SteemaLegendResizeIssue.zip
- (134.89 KiB) Downloaded 366 times
Re: Number of rows in a Legend with LegendScrollbar?
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:
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);
Best Regards,
Yeray Alonso Development & Support Steema Software Av. Montilivi 33, 17003 Girona, Catalonia (SP) | |
Please read our Bug Fixing Policy |
Re: Number of rows in a Legend with LegendScrollbar?
Thank you, Yeray. I'll give that a try!