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

RadChart Item Selection via binding

5 Answers 196 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 17 Jan 2011, 04:33 PM
Hi All,

Is it possible to have a pie segement selected using binding?  I have a class that has an IsSelected property that I want to reflect on various views.  One of these views is a pie chart which hosts multiple items based on this class and I want 1 or more segements to be shown selected based on this property.  I can set the IsSelected property in the SelectionChanged event of chart, but I want to reflect the change when the instance is selected in another view.  Would perfer to do this using binding, but will put in any suggestion in the code behind. 

I know I could manually wire up the IsSelected property change event, but this seems a bit of a hack tho.

Regards

Richard....

5 Answers, 1 is accepted

Sort by
0
Giuseppe
Telerik team
answered on 20 Jan 2011, 03:46 PM
Hi Richard,

Currently it is not possible to apply selection through bindings -- you can either select the slice through user interaction with the mouse, or you can use the selection API to apply selection from code-behind (ChartArea.SelectItem(...) method overloads).


Kind regards,
Freddie
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Eirik H
Top achievements
Rank 2
answered on 06 Sep 2011, 09:53 AM
I want to have the item with the largest value selected by default and I'm populating the pie chart from code behind:

Me.PieChart.DefaultView.ChartArea.DataSeries.Clear()
Dim
series As DataSeries = New DataSeries
series.Definition = Me.PieChart.DefaultSeriesDefinition
 
 Dim i As Integer = 0
 Dim _highestIdx As Integer = -1
 
For Each curVal As Double In curValues
 If (_highestIdx < 0) Then
 _highestIdx = i
 Else
  If (curVal > curValues(i - 1)) Then
   _highestIdx = i
  End If
 End If
 series.Add(New DataPoint(curVal) With {.Label = "Level " & (i + 1).ToString})
 i += 1
Next
 
Me.PieChart.DefaultView.ChartArea.DataSeries.Add(series)
Me.PieChart.DefaultView.ChartArea.SelectItem(_highestIdx)

However, using ChartArea.SelectItem right after adding the new DataSeries doesn't work. If I (for testing purposes) try to do Me.PieChart.DefaultView.ChartArea.SelectItem(_highestIdx)
in the PieChart.MouseEnter event, the item gets selected properly.

It looks like you can't set an item as selected while RadChart is busy with rendering the new dataseries?
Is there an event I can subscribe to which triggers when this operation is finished?
0
Eirik H
Top achievements
Rank 2
answered on 08 Sep 2011, 06:47 AM
I submitted a support request for this and the solution for me was to hook on to the LayoutUpdated event.

Public Sub HighlightHighestItem()
    If (_highestIdx >= 0) Then
        Me.PieChart.DefaultView.ChartArea.SelectItem(_highestIdx)
    End If
End Sub
 
Private Sub PieChart_LayoutUpdated(ByVal sender As Object, ByVal e As System.EventArgs) Handles PieChart.LayoutUpdated
    If (Me.PieChart.DefaultView.ChartArea.DataSeries.Count > 0) Then
        Me.HighlightHighestItem()
    End If
End Sub


0
Jolly
Top achievements
Rank 1
answered on 10 Jan 2013, 04:33 AM

Eirik H, thank you very much for your last post!

I encountered this problem too, and solved it with this LayoutUpdated event you provided here. Thanks again!
0
Yezdi
Top achievements
Rank 1
answered on 21 Mar 2013, 06:42 PM
I need a similar feature where each individual pie chart item can be bound to a ViewModel IsSelected boolean property. Please let me know the best solution for this.
Tags
Chart
Asked by
Richard
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Eirik H
Top achievements
Rank 2
Jolly
Top achievements
Rank 1
Yezdi
Top achievements
Rank 1
Share this question
or