New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Programmatic Creation Of SeriesItems With DateTime

Updated over 6 months ago

This help article illustrates how to create programmatically numeric series items in the ASP.NET AJAX Chart (i.e., ScatterSeriesItem and BubbleSeriesItem) with DateTime for their X values.

Problem:

You cannot assign directly DateTime objects to numeric series item's X property.

Cause:

Since the purpose of the numeric series (i.e., ScatterSeries, ScatterLineSeries and BubbleSeries) is to display continuous data, the series items' X property is of decimal type that doesn't correspond to the DateTime type.

Solution:

You can do the following steps, in order to assign programmatically DateTime values to numeric series items.

  • Convert the .NET DateTime object to its JavaScript Date object representation. This conversion is necessary because JavaScript uses the Unix Epoch(i.e., the number of seconds that have elapsed since 1/1/1970 at 12:00:00 AM) as a base to track dates as the number of milliseconds from it to the actual date.

  • Cast the converted value to decimal and pass it to the series item's X property.

Example 1 illustrates how to convert .NET DateTime objects to JavaScript Date objects and add them to series items' X values.

Example 1: Programmatic assignment of DateTime objects to ScatterSeriesItem's X property.

ASP.NET
<telerik:RadHtmlChart runat="server" ID="RadHtmlChart1" Width="640px" Height="480px">
	<PlotArea>
		<Series>
			<telerik:ScatterLineSeries Name="Stock A">
				<LabelsAppearance>
					<ClientTemplate>
						#= kendo.format(\'{0:d/MM/yyyy}\', new Date(value.x)) #,  #=kendo.format(\'{0:C0}\',value.y)#
					</ClientTemplate>
				</LabelsAppearance>
				<TooltipsAppearance Color="White">
					<ClientTemplate>
						#= kendo.format(\'{0:d/MM/yyyy}\', new Date(value.x)) #,  #=kendo.format(\'{0:C0}\',value.y)#
					</ClientTemplate>
				</TooltipsAppearance>
			</telerik:ScatterLineSeries>
		</Series>
		<YAxis>
			<LabelsAppearance DataFormatString="C0"></LabelsAppearance>
			<TitleAppearance Text="Price"></TitleAppearance>
		</YAxis>
		<XAxis Type="date">
			<TitleAppearance Text="Closing Date">
			</TitleAppearance>
			<LabelsAppearance DataFormatString="d">
			</LabelsAppearance>
		</XAxis>
	</PlotArea>
	<ChartTitle Text="Closing Stock Prices">
	</ChartTitle>
</telerik:RadHtmlChart>

See Also

In this article
See Also
Not finding the help you need?
Contact Support