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

Chart Legend

2 Answers 69 Views
This is a migrated thread and some comments may be shown as answers.
Joe Bohen
Top achievements
Rank 1
Joe Bohen asked on 13 Nov 2009, 11:50 AM


 I am totally new to WPF and would appreciate some pointers. I have a window with a chart and a button the buttons click event has the code shown below, I want to display the Depot Name in the legend but this code is not working the chart loads the data and displays the chart but without the legend is it possible to bind the chart to a data table and use the field names as the legend also is this good practice or should I consider a different approach?

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click


            Dim seriesMapping As New SeriesMapping()


            Dim Table1 As DataTable

            Table1 = New DataTable("DepotSales")


            Dim Row1, Row2, Row3, Row4 As DataRow



            Dim Name As DataColumn = New DataColumn("DepotName")


            Name.DataType = System.Type.GetType("System.String")




            Dim Turnover As DataColumn = New DataColumn("Turnover")

            Turnover.DataType = System.Type.GetType("System.Int32")



            Dim DepotID As DataColumn = New DataColumn("DepotID")

            DepotID.DataType = System.Type.GetType("System.Int16")



            Row1 = Table1.NewRow()


            Row1.Item("Depot") = "North"

            Row1.Item("Turnover") = 69000

            Row1.Item("DepotID") = 1



            Row2 = Table1.NewRow()


            Row2.Item("Depot") = "South"

            Row2.Item("Turnover") = 35000

            Row2.Item("DepotID") = 2



            Row3 = Table1.NewRow()


            Row3.Item("Depot") = "East"

            Row3.Item("Turnover") = 28000

            Row1.Item("DepotID") = 3



            Row4 = Table1.NewRow()


            Row4.Item("Depot") = "West"

            Row4.Item("Turnover") = 41000

            Row4.Item("DepotID") = 4



            seriesMapping.LegendLabel = "Turnover"

            seriesMapping.SeriesDefinition = New Bar3DSeriesDefinition


            seriesMapping.ItemMappings.Add(New ItemMapping("DepotID", DataPointMember.XValue))

            seriesMapping.ItemMappings.Add(New ItemMapping("DepotName", DataPointMember.XCategory))

            seriesMapping.ItemMappings.Add(New ItemMapping("Turnover", DataPointMember.YValue))



            Me.Radchart.ItemsSource = Table1


        Catch ex As Exception


        End Try


















2 Answers, 1 is accepted

Sort by
Joe Bohen
Top achievements
Rank 1
answered on 13 Nov 2009, 05:25 PM

Hi the code supplied works with a standard bar chart but not a 3d chart!

Telerik team
answered on 18 Nov 2009, 09:55 AM
Hello Joe,

You can find attached a small example based on your code. Note, that ItemMappings for XValue and XCategory could not exist at the same time. You can either use XValue or XCategory as both define the item's position along the X axis, so I removed the XValue item mapping. I also added an ItemMapping for the LegendLabel property - again, bound to DepotName. Finally, I set the seriesMapping.SeriesDefinition.LegendDisplayMode property to LegendDisplayMode.DataPointLabel, so that every DataPoint has a corresponding item in the legend.

the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Asked by
Joe Bohen
Top achievements
Rank 1
Answers by
Joe Bohen
Top achievements
Rank 1
Telerik team
Share this question