Progress® Telerik® Reporting R3 2021

New to Telerik Reporting? Download free 30-day trial

Creating Chart Programmatically

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.

The steps below show how to create a minimal chart definition (i.e. Chart)  programmatically. See Creating Chart Programmatically - more complex example topic for more info how to create multiple series and how appearance can be tailored at run-time.

Once the chart definition is created, you need to create ChartSeries and ChartSeriesItem collections.

The example below is an alternative to using the Report Designer for creating a chart. The approach of hardcoding data in the series is for the sake of the example and would produce a static chart. This code should not be used for programmatic creation of dynamic charts based on data, for such scenario, see How to Programmatically Data Binding Chart to a Generic List of Objects.

  1. First add the namespaces that support the objects to be referenced. The Telerik.Reporting.Charting namespace supports the Chart  declaration.
    using Telerik.Reporting.Charting;
  2. Next construct the Chart  item itself.
    Telerik.Reporting.Chart progchart = new Telerik.Reporting.Chart();
    progchart.BitmapResolution = 96F;
    progchart.ImageFormat = System.Drawing.Imaging.ImageFormat.Emf;
    progchart.Location = new Telerik.Reporting.Drawing.PointU(Telerik.Reporting.Drawing.Unit.Cm(0.3), Telerik.Reporting.Drawing.Unit.Cm(1.8));
    progchart.Name = "progchart1";
    progchart.PlotArea.EmptySeriesMessage.Appearance.Visible = true;
    progchart.PlotArea.EmptySeriesMessage.Visible = true;
    progchart.Size = new Telerik.Reporting.Drawing.SizeU(Telerik.Reporting.Drawing.Unit.Cm(9.6), Telerik.Reporting.Drawing.Unit.Cm(6.1));
  3. Construct a new ChartSeries object and assign a name to it. Set the ChartSeriesType to be Bar. Using the ChartSeries.AddItem(Double, String) method, add a series of ChartSeriesItem objects to the series Items ChartSeriesItemsCollection collection. The latter method takes as parameters a double "Value" and a string "Label".

    // Create a ChartSeries and assign its name and chart type
    ChartSeries chartSeries = new ChartSeries();
    chartSeries.Name = "Sales";
    chartSeries.Type = ChartSeriesType.Bar;
    // add new items to the series,
    // passing a value and a label string
    chartSeries.AddItem(120, "Internet");
    chartSeries.AddItem(140, "Retail");
    chartSeries.AddItem(35, "Wholesale");
  4. Finally, add the ChartSeries to the chart series collection and add the chart to a report section (detail section in the example).

    // add the series to the Chart Series collection
    progchart.Series.Add(chartSeries);
    // add the Chart to the page.
    this.detail.Items.Add(progchart);
  5. The finished chart should look like this example:
    Programmatically Created Chart at Runtime

See Also

In this article
Not finding the help you need?