How to return a method value as list for RadHtmlChart ?

2 posts, 1 answers
  1. Nikola
    Nikola avatar
    65 posts
    Member since:
    Sep 2012

    Posted 26 Feb 2013 Link to this post

    I'm using a RadHtmlChart based on HTML5 from telerik. I'm using a Pie Chart, and I want to display the method's values. How should I save the values -- maybe as a list? It shouldn't have a big impact on the method itself, because I need this method for some report stuff.

    public double GetBookedVacation(int year)
        int counter = 0;
        if (this.AnnualVacations.Any())
            foreach (HtVacationDay vacationDay in HtVacationDays)
                foreach (DateTime vacationDayDate in vacationDay.GetDates())
                    if (vacationDayDate.Year == year)
        return counter;

    Thanks for help and fast answer.

  2. Answer
    Danail Vasilev
    Danail Vasilev avatar
    1476 posts

    Posted 27 Feb 2013 Link to this post

    Hello Nikola,

    You can databind the HtmlChart and the PieSeries respectively to a various types of datasources - SqlDataSource, LinqDataSource, EntityDataSource, ObjectDataSource, XmlDataSource, Generic List of Custom Objects, DataSet or Array. Choosing an appropriate datasource is a decision depending on your actual scenario and without enough information about it we cannot give you an advice.

    Selecting a List of Custom Object as a datasource type is a viable solution. You can have a look at this online demo showing how to do that or look at other datasource types as well.

    If, however, the elements of your chart are dynamic (depending on external methods/parameters) you can create your chart programmatically, following the approach in this online demo.

    Regarding your current method GetBookedVacation, note that it returns just a double number. Could you give more information about your scenario:
    • Where in your HtmlChart do you want to put that double value? Is it supposed to be the datasource itself - in that case your chart will have one Series with one SeriesItem.
    • OR maybe it is supposed to be included somewhere else in the chart - for example in the chart Title?
    If you need this method to pass the resulting data directly to the chart it should return the corresponding type instead of an integer (e.g. List<myObjects>). If the method has to return this value but populating the chart is a side effect you should build the datasource in the method and assign it there before the return statement.

    Danail Vasilev
    the Telerik team
    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 their blog feed now.
  3. DevCraft R3 2016 release webinar banner
Back to Top