One of RadChart’s most powerful features is its support for DataBinding. This means that as long as you correctly format your data source, you shouldn’t have to write any backend code to support the generation of the chart. Using a data source with a control as powerful and complex as the RadChart can unfortunately be somewhat confusing. In this post, I’ll shed some light on one of the scenarios you are sure to come across, displaying incremental DateTime values from a data source in the X-Axis of RadChart.
RadChart does not work directly with DateTime values. Instead, it supports something called the OLE Automation Date. According to the MSDN, an OLE Automation Date is implemented as a floating-point number. In using this type of value, RadChart can more efficiently manage date time information behind the scenes. The following SQL query shows how a DateTime value can be converted to the OLE Automation Date as part of the query.
SELECT
CAST
([OrderDate]
AS
FLOAT
) + 2
as
OADate,
SUM
(SubTotal)
AS
SubTotal
FROM
Purchasing.PurchaseOrderHeader
WHERE
OrderDate >=
'1/1/2003'
and
OrderDate <
'7/1/2003'
GROUP
BY
OrderDate
ORDER
BY
OrderDate
After setting up the data source, telling RadChart to display incremental DateTime values is as easy as setting the following properties.
Once all of these properties have been set, the generated chart looks as follows.
Figure 1. RadChart with DateTimes in X-Axis
Click here to download the source code used in this post.
Note: The engine of RadChart for ASP.NET AJAX has been used in both RadChart for Windows Forms and in the Telerik Reporting chart item, so the provided solution applies for them as well.