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

using linq to dynamic create chartview series

1 Answer 99 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
FJ
Top achievements
Rank 1
FJ asked on 18 Dec 2012, 10:15 PM

For those who might want to use this, I have created a quick sample on how to use linq to create dynamic series for chartview:

Example is created in VS2010 / VB.NET 

Make sure you import:
System.Data.DataSetExtensions.dll
to use linq.

Me.RadChartView1.ShowLegend = True
Me.RadChartView1.ShowTitle = True
Me.RadChartView1.Title = "Sold products per country"
 
        Dim graphSeries As New DataTable()
 
        graphSeries.Columns.Add("Category", GetType(String))
        graphSeries.Columns.Add("Value", GetType(Integer))
        graphSeries.Columns.Add("XValue", GetType(String))
 
 
        graphSeries.Rows.Add("Netherlands", 10, "2011")
        graphSeries.Rows.Add("USA", 12, "2011")
        graphSeries.Rows.Add("Germany", 7, "2011")
        graphSeries.Rows.Add("Netherlands", 25, "2012")
        graphSeries.Rows.Add("USA", 40, "2012")
        graphSeries.Rows.Add("Germany", 25, "2012")
 
       Dim productGroups = From p In graphSeries _
       Group p By Category = p.Field(Of String)("Category") Into Group _
                        Select Category, ProductGroup = Group
 
        For Each g In productGroups
            Dim barSeries As New Telerik.WinControls.UI.BarSeries("Value", "Category")
            barSeries.Name = g.Category
            barSeries.ValueMember = "Value"
            barSeries.CategoryMember = "XValue"
            barSeries.ShowLabels = True
            barSeries.LegendTitle = g.Category
            Me.RadChartView1.Series.Add(barSeries)
            barSeries.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack
            barSeries.DataSource = g.ProductGroup.CopyToDataTable
 
        Next

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 21 Dec 2012, 02:28 PM
Hi Fokko,

Thank you for sharing your code with the community. I am sure that someone will benefit from it.

Your Telerik Points have been updated for your time and efforts.

All the best,
Stefan
the Telerik team
Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
Tags
ChartView
Asked by
FJ
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or