Creating series from list datasource

2 posts, 0 answers
  1. David
    David avatar
    19 posts
    Member since:
    Feb 2013

    Posted 20 Nov 2014 Link to this post


    I have a list of objects (a linq2sql query I convert to a list) that I want to use as a datasource for a RadHTMLChart. The data look like this:

    Employee    WorkDay       Performance
    Jane            2014-01-01    300
    Jane            2014-01-02    287
    John            2014-01-02    324
    Jane            2014-01-03    151
    John            2014-01-03    139

    I want performance to be the Y Axis, WorkDay to be the X Axis and for the data to be grouped into series using the Employee name. I have read the help information and viewed all of the demos but I can't seem to get it right. If I pre-define the series in the aspx it works, but I can't seem to make it render correctly from just providing a data source.

    Here is one of the attempts, where I am close, but the different series don't align to the x-axis.
    Dim q = emp.BenchmarkForTask(50, 3, "12/1/13") ' This gets my data
           Dim lemp As String = ""
           lemp = ""
           chrtPerformanceNew.PlotArea.XAxis.Name = "Employee"
           chrtPerformanceNew.PlotArea.XAxis.DataLabelsField = "Employee"
           ' Load each series from the data:
           For Each tmp In q.OrderBy(Function(x) x.Employee)
               If lemp <> tmp.Employee Then
                   Dim x As New Telerik.Web.UI.LineSeries
                   x.Name = tmp.Employee
                   x.DataFieldY = "Performance"
                   x.LabelsAppearance.Visible = False
                   x.TooltipsAppearance.DataFormatString = "{WorkDay} - YO!"
                   x.LabelsAppearance.DataField = "WorkDay"
                   lemp = tmp.Employee
               End If
           ' Load data into series. How to I set it to the correct X axis?
           For Each tmp In q.OrderBy(Function(x) x.WorkDay)
               Dim i As Integer = 0
               For i = 0 To chrtPerformanceNew.PlotArea.Series.Count - 1
                   If chrtPerformanceNew.PlotArea.Series(i).Name = tmp.Employee Then
                       Dim ca As Telerik.Web.UI.LineSeries = chrtPerformanceNew.PlotArea.Series(i)
                       Dim si As New Telerik.Web.UI.SeriesItem
                       si.Name = tmp.WorkDay
                       si.TooltipValue = tmp.WorkDay & " -> " & tmp.Employee
                       si.YValue = tmp.Performance
                   End If

    The result looks like the attached chart. It's close but I don't see the x labels (Should show the date) and the data is therefore not aligned to the proper x axis.

    Thanks for any help!
  2. Danail Vasilev
    Danail Vasilev avatar
    1502 posts

    Posted 21 Nov 2014 Link to this post

    Hello David,

    You can find an example of a data source grouping in the Group RadHtmlChart Data Source code library.

    Danail Vasilev

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top