How to create a dynamic number of series in a graph

2 posts, 0 answers
  1. Spencer
    Spencer avatar
    5 posts
    Member since:
    Aug 2017

    Posted 22 Jan Link to this post

    Hello,
    I'm creating a report using something similar to the following classes:

    public class Point
    {
        public double X { get; set; }
        public double Y { get; set; }
    }
     
    public class Series
    {
        public List<Point> Points { get; set; }
    }
     
    public class MultipleSeries
    {
        public string Header { get; set; }
     
        //There could be any number of these
        public List<Series> Series { get; set; }
    }
     
    public class ManyMultipleSeries
    {
        public List<MultipleSeries> ManySeries { get; set; }
    }

     

    Basically, the main report will bind to 'ManyMultipleSeries'. This class will have a list of 'MultipleSeries', which are bound to a sub report that contains the chart. The 'MultipleSeries' class could contain any number of 'Series' that need to be displayed in the chart. I could not find any way of creating a dynamic number of series like this in the docs. Thanks for any help.

  2. Todor
    Admin
    Todor avatar
    299 posts

    Posted 25 Jan Link to this post

    Hi Spencer,

    I noticed that you have opened a Support ticket on the same topic.
    We have answered your questions and provided examples in the support thread. For the benefit of our community I will summarize our answers also here.

    By setting the DataSource of nested data items through their parent DataSource, i.e. main Report->subreport->Graph you may assign the Fields.Series from MultipleSeries as DataSource of the Graph data item. However, the type of the items stored in Series collection should *not* be a collection to be resolved properly.
    Generally, all simple type properties from the data source can be used directly in the report to show their values using expressions such as "= Fields.MyProperty". Complex objects can also be used by accessing their nested properties using the dot notation i.e. "= Fields.MyProperty.NestedProperty", etc.
    Collection properties cannot be used directly and you need to bind them to a nested data item.
    The solution in the specific case is MultipleSeries property Series to be a collection of type that is not collection itself, i.e. List<Point>.

    To be able to display multiple series within the Graph you may introduce a grouping property in the Point model (i.e. property Group) and group the corresponding Graph SeriesGroup by this property. This will result in separate Series for each distinct value of Point.Group.

    Regards,
    Todor
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top