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

Data Binding Overview

This help article describes the required data structure for the ASP.NET AJAX Chart. It explains how to use fields (columns) and rows.

A data bound series in RadHtmlChart expects a field (column) name and will take the data from all records (rows) in the provided data source. Table 1 shows a supported data source structure and Table 2 shows an unsuitable data source structure. You can see a sample implementation of a good data source in Example 1.

Table 1: Expected structure of the RadHtmlChart data source

X_Axis_LabelsFirst_Series_ValuesSecond_Series_Values
Label 115
Label 21015
Label 32025

If your data source looks like Table 2, review the Group RadHtmlChart Data Source code library article. Alternatively, you can traverse your data source and create series items programmatically.

Table 2: Unsupported data source structure for RadHtmlChart

X_Axis_Labelsseries_group_namevalue
Label 1first1
Label 2first10
Label 3first20
Label 1second5
Label 2second15
Label 3second25

Example 1: Sample implementation of the supported data source for RadHtmlChart from Table 1. You can see the result in Figure 1.

ASP.NET
<telerik:RadHtmlChart runat="server" ID="RadHtmlChart1" Width="300px" Height="300px">
	<PlotArea>
		<Series>
			<telerik:LineSeries DataFieldY="First_Series_Values" Name="first series"></telerik:LineSeries>
			<telerik:LineSeries DataFieldY="Second_Series_Values" Name="second series"></telerik:LineSeries>
		</Series>
		<XAxis DataLabelsField="X_Axis_Categories"></XAxis>
	</PlotArea>
</telerik:RadHtmlChart>
C#
protected DataTable GetChartData()
{
	DataTable tbl = new DataTable();
	tbl.Columns.Add(new DataColumn("X_Axis_Categories", typeof(string)));
	tbl.Columns.Add(new DataColumn("First_Series_Values", typeof(decimal)));
	tbl.Columns.Add(new DataColumn("Second_Series_Values", typeof(decimal)));
	tbl.Rows.Add(new object[] {"Label 1", 1, 5 });
	tbl.Rows.Add(new object[] {"Label 2", 10, 15 });
	tbl.Rows.Add(new object[] {"Label 3", 20, 25 });

	return tbl;
}

protected void Page_Load(object sender, EventArgs e)
{
	if (!Page.IsPostBack)
	{
		RadHtmlChart1.DataSource = GetChartData();
		RadHtmlChart1.DataBind();
	}
}

Figure 1: The result from Example 1 - correct series data binding.

expected results with proper data source

See Also

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