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

Beginner Needs Help with RadChart

1 Answer 30 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ted
Top achievements
Rank 1
Ted asked on 21 Mar 2012, 06:06 PM
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
            Get
                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
                myWrapPanel.Children.Add(pc)
            Next
 
 
            ' Add the WrapPanel to the Page as Content
            Return myWrapPanel
        End Function
 
        Private ReadOnly Property Data() As IEnumerable(Of Company)
            Get
                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
                Get
                    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
                Get
                    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

1 Answer, 1 is accepted

Sort by
0
Peshito
Telerik team
answered on 22 Mar 2012, 10:17 AM
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"
seriesMapping.ItemMappings.Add(itemMapping)
itemMapping = New ItemMapping()
itemMapping.DataPointMember = DataPointMember.LegendLabel
itemMapping.FieldName = "Name"
seriesMapping.ItemMappings.Add(itemMapping)
and then add this series mapping to your chart's SeriesMappings collection:
Me.radChart.SeriesMappings.Add(seriesMapping)
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:
http://www.telerik.com/help/silverlight/radchart-features-chart-legend.html
http://www.telerik.com/help/silverlight/radchart-populating-with-data-data-binding-with-manual-series-mapping.html

Regards,
Peshito
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Chart
Asked by
Ted
Top achievements
Rank 1
Answers by
Peshito
Telerik team
Share this question
or