Dynamically define NumericalScale in Subreport

4 posts, 0 answers
  1. Roland Klug
    Roland Klug avatar
    26 posts
    Member since:
    Dec 2002

    Posted 11 Dec 2014 Link to this post

    Hello,

    I want to define the scale of the y-axis dynamically based on my data source. My current implementation uses the ItemDataBound event from the graph-object. It is the earliest moment, when the data are bound to the subreport. At this moment the scale is not properly set.

    var dataItem = (Telerik.Reporting.Processing.DataItem)sender;
    var list = dataItem.DataSource as IList<InclinationProfileItemModel>;
     
    if (list == null) return;
     
    list = new List<InclinationProfileItemModel>(list.OrderBy(l => l.InclinationInDistanceUnitToStart));
    var minY = list.First().InclinationInDistanceUnitToStart;
    var maxY = list.Last().InclinationInDistanceUnitToStart;
    var inclMax = Math.Abs(maxY - minY);
     
    if (inclMax < 1)
        this.UnitToStartLineSeriesGraphAxisY.Scale = new NumericalScale
        {
            MajorStep = 0.25,
            MinorStep = 0.25,
            Minimum = Math.Min(0, Math.Floor(minY)),
            Maximum = Math.Max(1, Math.Ceiling(maxY))
        };
    else if (inclMax < 5)
        this.UnitToStartLineSeriesGraphAxisY.Scale = new NumericalScale
        {
            MajorStep = 1,
            MinorStep = 1,
            Minimum = Math.Min(0, Math.Floor(minY)),
            Maximum = Math.Max(1, Math.Ceiling(maxY))
        };
    else if (inclMax < 20)
        this.UnitToStartLineSeriesGraphAxisY.Scale = new NumericalScale
        {
            MajorStep = 5,
            MinorStep = 5,
            Minimum = Math.Min(0, Math.Floor(minY)),
            Maximum = Math.Max(1, Math.Ceiling(maxY))
        };
    else
        this.UnitToStartLineSeriesGraphAxisY.Scale = new NumericalScale
        {
            MajorStep = 10,
            MinorStep = 10,
            Minimum = Math.Min(0, Math.Floor(minY)),
            Maximum = Math.Max(1, Math.Ceiling(maxY))
        };

    How can I solve my problem? Is there a way to set the properties of NumericalScale to an earlier moment? Any other solution for dynamically define a NumericalScale? Binding?

    Best regards,
    Roland
  2. Nasko
    Admin
    Nasko avatar
    909 posts

    Posted 15 Dec 2014 Link to this post

    Hello Roland,

    It is not possible to modify the graph scale inside an event, since there is no access to the Graph Members during report processing.
    In addition, Telerik Reporting provides different declarative means that replace the need for events and provide the needed flexibility to handle most tasks: Using Expressions, Conditional Formatting, Bindings and User Functions. These tools are typically the most productive way to build declarative reports and should be favored over using events. Additionally events can't be used with XML (trdx) report definitions on which the Standalone Report Designer depends.

    Currently, the only option to define the NumericalScale of a Graph item inside a sub-report is to modify the sub-report's report definition inside your application, before the report is displayed in a report viewer:
    var subReport = new MySubReport();
    var graph = subReport.Items.Find("graph1", true)[0] as Telerik.Reporting.Graph;
    //Assuming you have a single Cartesian coordinate system in your graph.
    var cartesianCoordinateSystem = (Telerik.Reporting.CartesianCoordinateSystem)graph.CoordinateSystems[0];
    //Assuming your X axis has a numerical scale.
    var numericalScale = (Telerik.Reporting.NumericalScale)cartesianCoordinateSystem.XAxis.Scale;
    numericalScale.Minimum = GetMinValue(); //custom method
    numericalScale.Maximum = GetMaxValue(); //custom method
    ...

    Then you need to assign the modified sub-report to the SubReport item in the main report:
    var mainReport = new MyMainReport();
    var subReportItem = (mainReport.Items.Find("subReport1", true)[0]) as Telerik.Reporting.SubReport;
     
    var irs = new Telerik.Reporting.InstanceReportSource();
    irs.ReportDocument = subReport;
     
    subReportItem.ReportSource = irs;

    We also have plans to expose some of the NumericalScale members, so they can be set using Bindings, in a future version of the product.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. DevCraft banner
  4. Roland Klug
    Roland Klug avatar
    26 posts
    Member since:
    Dec 2002

    Posted 16 Jan 2015 in reply to Nasko Link to this post

    Hi Nasko,

    we have a list of diagrams with different scaling. It would be great if binding will be supported as soon as possible. In the meantime I try to workaround about this problem.

    Best regards,
    Roland
  5. Nasko
    Admin
    Nasko avatar
    909 posts

    Posted 20 Jan 2015 Link to this post

    Hello Roland,

    Exposing some of the Graph Scale members in bindings is planned for the next official release. You can find out when it is available by following the Release History page.

    Regards,
    Nasko
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top