Progress® Telerik® Reporting R3 2021

New to Telerik Reporting? Download free 30-day trial

Data Binding Chart to a Database Object

This article is obsolete. The Chart item is now superseded by the more advanced Graph item. The Graph item is most often used for building powerful OLAP/Pivot charts.

Chart bound to a SqlDataSource"

The figure above shows a running example that starts with a default Chart with a single Series. The example code:

  • Displays data for a database column by assigning the series ChartSeries.DataYColumn or ChartSeries.DataXColumn properties. In the example the "TotalSales" column is assigned to the ChartSeries.DataYColumn property.

  • Displays database column data in the X axis labels by assigning the column name to the ChartXAxis.DataLabelsColumn. The example assigns "CategoryName" to the ChartXAxis.DataLabelsColumn property.

Also note how the example sets the ChartMarginsPlotArea.Bottom to 30% and the StyleLabel.RotationAngle to 300 in order to provide room for the axis labels.

using System;
using Telerik.Reporting.Chart;

public partial class Report1 : Report
    public Report1()
        /// <summary>
        /// Required for telerik Reporting designer support
        /// </summary>

    private void chart1_NeedDataSource(object sender, EventArgs e)
        Telerik.Reporting.Processing.Chart procChart = (Telerik.Reporting.Processing.Chart)sender;
        string sql = @"SELECT CategoryName, SUM(ProductSales) AS TotalSales FROM [Product Sales for 1997] GROUP BY CategoryName";
        string connectionString = "Data Source=(local);Initial Catalog=NorthWind;Integrated Security=True";
        SqlDataAdapter adapter = new SqlDataAdapter(sql, connectionString);
        DataSet dataSet = new DataSet();
        procChart.DataSource = dataSet;
        // Set the column for data and data labels:
        // Each bar will show "TotalSales", each label along
        // X-axis will show "CategoryName.
        chart1.Series[0].DataYColumn = "TotalSales";
        chart1.PlotArea.XAxis.DataLabelsColumn = "CategoryName";
        // assign appearance related properties
        chart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 300;
        chart1.PlotArea.XAxis.Appearance.TextAppearance.TextProperties.Color = System.Drawing.Color.BlueViolet;
        chart1.PlotArea.Appearance.Dimensions.Margins.Bottom =

See Also

In this article
Not finding the help you need?