Beginner Needs Help with RadChart

2 posts, 0 answers
  1. Ted
    Ted avatar
    2 posts
    Member since:
    Mar 2012

    Posted 21 Mar 2012 Link to this post

    Below is code to add four identical charts to a wrappanel.

    What code should be added to the function 'CreateCommodityCharts' to:

    1. Change the charts to Pie charts.
    2. Add Legends for the Companies.

    Thank you.


    Namespace Views
        Public Class CommodityChartViewModel
            Private _data As IEnumerable(Of Company)
            Private _wrappanel As WrapPanel
            Public ReadOnly Property ChartWrapPanel As WrapPanel
                    If Me._wrappanel Is Nothing Then
                        Me._wrappanel = CreateCommodityCharts
                    End If
                    Return Me._wrappanel
                End Get
            End Property
            Private Function CreateCommodityCharts() As WrapPanel
                ' Instantiate a new WrapPanel and set properties
                Dim myWrapPanel As New WrapPanel()
                myWrapPanel.Orientation = Orientation.Horizontal
                myWrapPanel.Width = 900
                myWrapPanel.HorizontalAlignment = Windows.HorizontalAlignment.Left
                myWrapPanel.VerticalAlignment = Windows.VerticalAlignment.Top
                ' Add the Telerik charts to the parent WrapPanel using the Children.Add method.
                For cntr = 1 To 4
                    Dim pc As New Telerik.Windows.Controls.RadChart
                    pc.Height = 300
                    pc.Width = 300
                    pc.ItemsSource = Data
                    pc.DefaultView.ChartTitle.Content = "RAD Pie Chart " & cntr.ToString
                ' Add the WrapPanel to the Page as Content
                Return myWrapPanel
            End Function
            Private ReadOnly Property Data() As IEnumerable(Of Company)
                    If Me._data Is Nothing Then
                        Me._data = CreateCompanyData()
                    End If
                    Return Me._data
                End Get
            End Property
            Function CreateCompanyData() As IEnumerable(Of Company)
                Dim companyData As New List(Of Company)(2)
                companyData.Add(New Company("Nokia", 90))
                companyData.Add(New Company("RIM", 10))
                'companyData.Add(New Company("Other", 14))
                'companyData.Add(New Company("Apple", 13))
                'companyData.Add(New Company("HTC", 6))
                'companyData.Add(New Company("Fujitsu", 3))
                Return companyData
            End Function
            Public Class Company
                Public Sub New(name As String, share As Double)
                    Me._name = name
                    Me._share = share
                End Sub
                Private _name As String
                Private _share As Double
                Public Property Name() As String
                        Return Me._name
                    End Get
                    Set(value As String)
                        If Me._name <> value Then
                            Me._name = value
                        End If
                    End Set
                End Property
                Public Property Share() As Double
                        Return Me._share
                    End Get
                    Set(value As Double)
                        If Me._share <> value Then
                            Me._share = value
                        End If
                    End Set
                End Property
            End Class
        End Class
    End Namespace
  2. Peshito
    Peshito avatar
    493 posts

    Posted 22 Mar 2012 Link to this post

    Hi Ted,

    In order to be able to change a chart to a Pie chart type you need to simply set its series type. You can achieve that by using series mappings like this for example:
    Dim seriesMapping As New SeriesMapping()
    seriesMapping.SeriesDefinition = New PieSeriesDefinition()
    Using series mappings you can control how the data is bound to the chart. Setting the ItemMappings then will give you the possibility to bind each property that takes part in the chart:
    Dim itemMapping As New ItemMapping()
    itemMapping.DataPointMember = DataPointMember.YValue
    itemMapping.FieldName = "Share"
    itemMapping = New ItemMapping()
    itemMapping.DataPointMember = DataPointMember.LegendLabel
    itemMapping.FieldName = "Name"
    and then add this series mapping to your chart's SeriesMappings collection:
    Using LegentLabel as DataPointMember will fill the legend with your Name field value.

    You can find more information about legend items and series mappings here:

    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
  3. DevCraft banner
Back to Top