This is a migrated thread and some comments may be shown as answers.

Programmatically create databindable report

1 Answer 247 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Linus
Top achievements
Rank 2
Linus asked on 25 Aug 2008, 03:02 PM
Hi!

We have a complex scenario where it's necessary to programmatically create the reports. This is the typical scenario of building the report:

1. The report layout and properties are set.
2. Report items are added to the report, e.g. a Chart.
3. The properties of the Chart is set and since we are binding to a dataset of unknown contents we register to the NeedDataSource event.
4. The NeedDataSource event is triggered and the datasource is set.
5. The Report is displayed in the ReportViewer.

Here's my question: We need to specifiy properties for the series created after the report items have been databound, e.g. DefaulLabelValue/DataLabelsColumn etc.. We've tried setting these values by looping through the ChartSeries collection in the ItemDataBound event but without any success.

How do you suggest this is done?

Regards
Linus

1 Answer, 1 is accepted

Sort by
0
Chavdar
Telerik team
answered on 26 Aug 2008, 01:43 PM
Hello Linus Karlsson,

Currently the chart image is created during the report processing for performance reasons. The latest moment which is available to modify the chart's definition or appearance is the NeedDataSource event. If you want to change any of the chart settings you can do this, for example, in the following way:

DataTable GetDataSource() 
        { 
            DataTable table = new DataTable(); 
            table.Columns.Add("Value"); 
            table.Columns.Add("LabelA"); 
            table.Columns.Add("LabelB"); 
            table.Rows.Add(new object[] { 5, "Item 1""A" }); 
            table.Rows.Add(new object[] { 4, "Item 2""B" }); 
            table.Rows.Add(new object[] { 3, "Item 3""C" }); 
            table.Rows.Add(new object[] { 2, "Item 4""D" }); 
            table.Rows.Add(new object[] { 1, "Item 5""E" }); 
            return table; 
        } 
 
        private void chart1_NeedDataSource(object sender, System.EventArgs e) 
        { 
            Telerik.Reporting.Processing.Chart chart = (Telerik.Reporting.Processing.Chart) sender; 
            Telerik.Reporting.Chart chartDef = (Telerik.Reporting.Chart) chart.ItemDefinition; 
            chartDef.Series[0].DataLabelsColumn = "LabelB"
            chartDef.Series[0].DataYColumn = "Value"
            chart.DataSource = this.GetDataSource(); 
        } 

Hope this helps.

Best wishes,
Chavdar
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
General Discussions
Asked by
Linus
Top achievements
Rank 2
Answers by
Chavdar
Telerik team
Share this question
or