reverse the order of legend items in charts control

6 posts, 2 answers
  1. Geoff Davis
    Geoff Davis avatar
    13 posts
    Member since:
    Dec 2009

    Posted 17 Aug 2010 Link to this post

    I am not able to access the collection items of the ChartLegend controller. In fact, I can see it enumerated in debugging mode but whenever I try to access those items individually, it throws me "system.typeloadexception".

    Here are the control names and properties I am talking about -
    Public Property Items() As Telerik.Windows.Controls.Charting.ChartLegendItemCollection
    Member of Telerik.Windows.Controls.Charting.ChartLegend

    I have following event
    Public Event DataBound(ByVal sender As Object, ByVal e As Telerik.Windows.Controls.Charting.ChartDataBoundEventArgs) (Member of Telerik.Windows.Controls.RadChart)

    Here is some more information about what's happening. I see 4 items listed within my CharLegend controller but Count property shows - "System.TypeLoadException" -
    -       directcast(sender,ChartLegend).ItemsSource   Count = {System.TypeLoadException}   System.Collections.IEnumerable
    +       (0)   {Telerik.Windows.Controls.Charting.ChartLegendItem}   Telerik.Windows.Controls.Charting.ChartLegendItem
    +       (1)   {Telerik.Windows.Controls.Charting.ChartLegendItem}   Telerik.Windows.Controls.Charting.ChartLegendItem
    +       (2)   {Telerik.Windows.Controls.Charting.ChartLegendItem}   Telerik.Windows.Controls.Charting.ChartLegendItem
    +       (3)   {Telerik.Windows.Controls.Charting.ChartLegendItem}   Telerik.Windows.Controls.Charting.ChartLegendItem

    so I tried to enumerate through the collection using GetEnumerator method and then when I used current property it threw me back InvalidOperation exception.

    I want to do something like this on my event handler -
    Dim graph As RadChart = DirectCast(sender, RadChart)
      
    Dim abc As ChartLegendItemCollection = graph.DefaultView.ChartLegend.Items()
      
    Dim newabc As New ChartLegendItemCollection
      
    For i As Integer = 0 To abc.count - 1
      newabc.Add(abc(0))
      abc.RemoveAt(0)
    Next
      
    abc = New ChartLegendItemCollection(newabc)
      
    'then something to rebind the control back or refresh the silverlight control\
  2. Geoff Davis
    Geoff Davis avatar
    13 posts
    Member since:
    Dec 2009

    Posted 18 Aug 2010 Link to this post

    We are facing same issue trying to set custom legend item style property "markerThickness". Any help?
  3. Answer
    Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 19 Aug 2010 Link to this post

    Hi Geoff Davis,

     Thank you for contacting Telerik support.

    You can access the ChartLegendItems from the ItemsSource property. Items holds user-defined legend items. To reverse the legend items you can use ItemsSource like so:

    Dim items As New List(Of ChartLegendItem)(RadChart1.DefaultView.ChartLegend.ItemsSource.Cast(Of ChartLegendItem)())
     
    items.Reverse()
     
    RadChart1.DefaultView.ChartLegend.ItemsSource = items

    I hope this information helps. Please, let me know if I can assist you any further with this service request. Thank you in advance.

    Best regards,
    Yavor Ivanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Geoff Davis
    Geoff Davis avatar
    13 posts
    Member since:
    Dec 2009

    Posted 23 Aug 2010 Link to this post

    Thanks a lot for the resolution provided. I have one more question. When I change the order of the legend items or rather modify the Itemssource property for the ChartLegend control, it doesn't regenerate itself when the data is fetched again. Is there any reason why? I have ensured that the UseAutogenerateItems is set to true, still it doesn't regenerate the itemssource.
  5. Answer
    Yavor
    Admin
    Yavor avatar
    401 posts

    Posted 25 Aug 2010 Link to this post

    Hello Geoff,

    Indeed I was able to reproduce the reported behavior on rebind. Note, however, that the proposed solution was a workaround and it has its limitations -- specifically modifying the ChartLegend.ItemsSource property brakes the internal mechanism for automatic legend item generation (as the legend does not work directly with what is set as ItemsSource but with its internal items collection).

    Unfortunately I cannot suggest you a workaround that would work on rebind at the moment but I have discussed your request with our devteam and have raised the feature priority. You can track its progress in our public issue tracking system here.


    Kind regards,
    Yavor Ivanov
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Geoff Davis
    Geoff Davis avatar
    13 posts
    Member since:
    Dec 2009

    Posted 01 Nov 2010 Link to this post

    thanks for helping out.
Back to Top