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.