using linq to dynamic create chartview series

2 posts, 0 answers
  1. FJ
    FJ avatar
    12 posts
    Member since:
    May 2007

    Posted 18 Dec 2012 Link to this post

    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:
    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
                barSeries.CombineMode = Telerik.Charting.ChartSeriesCombineMode.Stack
                barSeries.DataSource = g.ProductGroup.CopyToDataTable
  2. Stefan
    Stefan avatar
    2891 posts

    Posted 21 Dec 2012 Link to this post

    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,
    the Telerik team
    Q3’12 of RadControls for WinForms is available for download (see what's new). Get it today.
  3. DevCraft R3 2016 release webinar banner
Back to Top