RadChart Item Selection via binding

6 posts, 0 answers
  1. Richard
    Richard avatar
    7 posts
    Member since:
    Oct 2010

    Posted 17 Jan 2011 Link to this post

    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....
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 20 Jan 2011 Link to this post

    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>>
  3. DevCraft banner
  4. Eirik H
    Eirik H avatar
    36 posts
    Member since:
    Mar 2010

    Posted 06 Sep 2011 Link to this post

    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?
  5. Eirik H
    Eirik H avatar
    36 posts
    Member since:
    Mar 2010

    Posted 08 Sep 2011 Link to this post

    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


  6. Jolly
    Jolly avatar
    1 posts
    Member since:
    Dec 2012

    Posted 09 Jan 2013 Link to this post


    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!
  7. Yezdi
    Yezdi avatar
    14 posts
    Member since:
    Feb 2011

    Posted 21 Mar 2013 Link to this post

    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.
Back to Top
DevCraft banner