Set filtered items for series

2 posts, 0 answers
  1. Ion
    Ion avatar
    1 posts
    Member since:
    Nov 2013

    Posted 12 Nov 2013 Link to this post

    Hello,

    I have a Q3 2012 HtmlRadChart, trying to bind it with List<> values. A list item object has properties CreatedDate, Name and Value. I want to display CreatedDate on XAxis, Name as legend and Value as series. Code:

    var source = (from r in readData join sen in equipments on r.EquipmentId equals sen.Id
                              select new
                                {
                                    Id = r.Id,
                                    CreatedDate = r.CreatedDate,
                                    Value = r.Value,
                                    Name = sen.Name,
                                    EquipmentId = sen.Id
                                }) 
                .ToList();
                chart.PlotArea.Series.Clear();
                foreach (var equipment in source.Select(src => src.Name).Distinct())
                {
                    var equipmentLineSeries = new LineSeries
                                           {
                                               DataField = "Value",
                                               Name = equipment,
                                           };
                    chart.PlotArea.Series.Add(equipmentLineSeries);
                }
                chart.DataSource = source;
                chart.DataBind();

    The problem is that chart does not "filter" values, and displays all values for every Name in the names list, overriding the other series displayed.
    As you can see in attachment, I have 13 values for all 3 Names (PT206, PT208, PT205) and all of them are displayed for every Name, thus, lines are overriten by each other.
    How can I filter data source by names, to display the series correctly?

    Thanks, 
    Ion
  2. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1492 posts

    Posted 14 Nov 2013 Link to this post

    Hello Ion,

    It seems that DataField property (this property is called DataFieldY now) for each LineSeries refers to the same data source "Value" column. I can suggest that you create different columns in the data source, for example "Value1", "Value2" and "Value3 "and refer them by each series.

    Note also that in older versions of RadHtmlChart date axis is not supported and therefore custom manipulations with the XAxis items are required in order to display dates there. More information on the matter is available in this help article.

    You may also find useful the HtmlChart - Date Axis and HtmlChart - List Of Custom Objects online demos that sheds more light on configuring date axis and databinding.

    Regards,
    Danail Vasilev
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top