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

Creating series from list datasource

1 Answer 37 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 20 Nov 2014, 03:33 PM
Hello,

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"
               chrtPerformanceNew.PlotArea.Series.Add(x)
 
               lemp = tmp.Employee
           End If
       Next
 
       ' 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
                   ca.Items.Add(si)
               End If
           Next
       Next

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!

1 Answer, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 21 Nov 2014, 09:21 AM
Hello David,

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

Regards,
Danail Vasilev
Telerik
 

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.

 
Tags
Chart (HTML5)
Asked by
David
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
Share this question
or