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

How to return a method value as list for RadHtmlChart ?

1 Answer 53 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Nikola
Top achievements
Rank 2
Nikola asked on 26 Feb 2013, 01:46 PM

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)
                {
                    counter++;
                }
            }
        }
    }
    return counter;
}

Thanks for help and fast answer.

1 Answer, 1 is accepted

Sort by
0
Accepted
Danail Vasilev
Telerik team
answered on 27 Feb 2013, 03:14 PM
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.

Regards,
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.
Tags
Chart (HTML5)
Asked by
Nikola
Top achievements
Rank 2
Answers by
Danail Vasilev
Telerik team
Share this question
or