This is a migrated thread and some comments may be shown as answers.

[Solved] reverse the order of legend items in charts control

5 Answers 242 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Geoff Davis
Top achievements
Rank 1
Geoff Davis asked on 17 Aug 2010, 02:37 PM
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\

5 Answers, 1 is accepted

Sort by
0
Geoff Davis
Top achievements
Rank 1
answered on 18 Aug 2010, 04:47 PM
We are facing same issue trying to set custom legend item style property "markerThickness". Any help?
0
Accepted
Yavor
Telerik team
answered on 19 Aug 2010, 09:03 AM
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
0
Geoff Davis
Top achievements
Rank 1
answered on 23 Aug 2010, 03:48 PM
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.
0
Accepted
Yavor
Telerik team
answered on 25 Aug 2010, 06:54 PM
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
0
Geoff Davis
Top achievements
Rank 1
answered on 01 Nov 2010, 05:24 PM
thanks for helping out.
Tags
Chart
Asked by
Geoff Davis
Top achievements
Rank 1
Answers by
Geoff Davis
Top achievements
Rank 1
Yavor
Telerik team
Share this question
or