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

Accessing subreport datasoource

3 Answers 61 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Julien
Top achievements
Rank 1
Julien asked on 28 Feb 2020, 04:53 PM

Hi, 
I have the following problem. I have a report that contains a few graphs with X axis as DateTime and a subreport which is also a graph reused in many reports. It is not acceptable to me to set label, major and minor points units and ranges in designer since in one case I can have 7 days process, and in other case 5 minutes process. According to this I need to calculate total time and decide if I will set label, major and minor points in seconds, minutes or hours, and also to calculate range so that I have approximately 10 major points on the graphs X axes. To achieve this i am modifying values set in designer programmatically at runtime. I tried the following approaches, neither is working:

1. I used ItemDataBound event on report and subreport hoping that in the time it fires I will have report data source filled, so that I can use data source to get collection of data to calculate. This was not the case. Data source was still null at the time of firing. 

2.I tried to calculate explicitly by calling the public method in a report that will do the calculation. This was a successful approach for the graphs in the report since I call this method from outside the report after assigning data source, but still can't find a way to call public method in the subreport from the main report after the subreport bound the data source.

I would appreciate help.

3 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 04 Mar 2020, 11:16 AM

Hello Julien,

Generally, the Graph will calculate the Axis scale automatically based on the data. You may control this also manually - through the GraphAxis -> Scale properties - check 'GraphAxisScaleProperties' screenshot. These properties may be set also through Bindings, and this is what I recommend.

You need to use the CoordinateSystem -> Bindings property - see 'AxisScaleWithBindings' screenshot. I have attached a sample report demonstrating the approach. In the sample, the Graph is generated three times in the Report detail section with different DateTime scales. The 'XAxis.Scale.LabelUnit' is set based on a value from the main data source to:

= IIf(ReportItem.Parent.DataObject.Name = "Scale in Days", "Days",
  IIf(ReportItem.Parent.DataObject.Name = "Scale in Months", "Months",
  IIf(ReportItem.Parent.DataObject.Name = "Scale in Years", "Years","Auto")))

The 'XAxis.Scale.LabelStep' is set to:

= IIf(ReportItem.Parent.DataObject.Name = "Scale in Days", 2,
  IIf(ReportItem.Parent.DataObject.Name = "Scale in Months", 3,
  IIf(ReportItem.Parent.DataObject.Name = "Scale in Years", 4, 1)))

In the above Expressions, you may use Custom User Functions, Parameters, etc.

Note that the '...Step' property will be respected only when the corresponding '...Unit' property is not 'Auto'.

Concerning your approaches:

  • 1. Indeed the processing report DataObject is not filled with data upon the firing of Report events. The data is available there though and can be taken from the most parent group with a code like:

var data = ((Processing.Group)((Processing.ILayoutElementContainer)sender).Children.Last()).DataObject;

Note also that on this event, it may be too late to modify the report items. In the other report events, the data is not available yet.

  • 2. I suspect that the SubReport ReportSource is set through TypeReportSource. If so, the subreport type will be instantiated with System.Reflection and it will not be trivial to modify it with custom code.

As a workaround, you may instantiate the subreports, modify them as needed and assign them to the main report as new InstanceReportSources. Check How To Programmatically Create a Master-Detail Report Using SubReport Item KB for sample code.

Regards,
Todor
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Julien
Top achievements
Rank 1
answered on 04 Mar 2020, 03:03 PM

Todor, 

Thanks for directing me toward Binding collection in coordinating system properties. Seems that it could be the solution. I reached the following point: I managed to create bindings for LabelStep and MajorStep properties, like you suggested. Everything works well when I set those properties in binding and set fixed value in Expression field (5 for example). I have problems to bind this value to my data model. Here is the example of what I tried:
I have an object that is set as data source on the report by using bindings. That object contains following properties: "GraphSeries" which contains points data, "GraphLabelStep" and "GraphMajorStep". When I enter this expression to bind label step: = ReportItem.DataObject.GraphLabelStep  I get the following error: "Bindings error - Error occurred while invoking setter on property LabelStep on type System.Int32 with value Null"

Can you please instruct me to continue? So the next step is to find correct expression to bind this step to the data model.

P.S. I couldn't open your report example since I have older version of report designer.

0
Accepted
Todor
Telerik team
answered on 09 Mar 2020, 09:53 AM

Hello Julien,

Based on the exception message I suspect that the value assigned to the 'LabelStep' is Null, which is not a valid 'Int32' value. To handle this you may:

  •  provide a default value when 'ReportItem.DataObject.GraphLabelStep' is Null, e.g.
    = ReportItem.Parent.DataObject.GraphLabelStep ?? 1
  • check for the value of 'GraphLabelStep' in the Expression for the 'LabelUnit' and set the latter to 'Auto' when the step is null, e.g.
= IIf(ReportItem.Parent.DataObject.GraphLabelStep Is Null, "Auto",
  IIf(ReportItem.Parent.DataObject.Name = "Scale in Days", "Days",
  IIf(ReportItem.Parent.DataObject.Name = "Scale in Months", "Months",
  IIf(ReportItem.Parent.DataObject.Name = "Scale in Years", "Years","Auto"))))

And provide a valid number for the 'LabelStep' - it will not be respected when 'LabelUnit' is 'Auto':

= ReportItem.Parent.DataObject.GraphLabelStep ?? 1 

 

I am not sure which version you use and attached the modified sample in TRDX format with XML Schema '....2019/1.0' that is supported by the Standalone designers with version R1 2019+. If you use an older version you may need to modify the schema. You may find the necessary schema version in the Upgrade path under the corresponding year and version. If the schema is not available for the version, this means that it has not been changed with respect to the previous version and you should check the previous version. When you find the correct version open the TRDX file with a text editor and change the schema in the second line of the file:

<Report DataSourceName="jsonDataSource1" Width="6.5in" Name="Report1" xmlns="http://schemas.telerik.com/reporting/2019/1.0">

Regards,
Todor
Progress Telerik

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Julien
Top achievements
Rank 1
Answers by
Todor
Telerik team
Julien
Top achievements
Rank 1
Share this question
or