首页 > 解决方案 > 崩溃的 Stimulsoft 报告查看器

问题描述

我在 Angular 5 项目中使用 Stimulsoft,首先我创建了一个按钮(在 bootstrap tabs 内),然后单击它会触发一个生成报告的函数在此处输入图像描述

和按钮html代码:

 <ngb-tab>
   <ng-template ngbTabTitle ><b>Report</b></ng-template>
    <ng-template ngbTabContent>

        <button (click)="generateReport()"  class="btn m-btn btn-danger" 
           id="generateReport">
            <span>
               <i class="la la-eye"></i>
            <span> Generate Report</span>
          </span>
        </button>   
        <div id="Report"></div>

    </ng-template>
 </ngb-tab>

以及点击(生成报告)触发的功能:

generateReport() {

    this.ExportImageForReport();
    let sol = this.solution;

    setTimeout(() => {
            let HS = this.body.hotStreams.map(a => { let obj = { Name: a.name, 
                   Supply: a.Supply, Target: a.Target, Duty: Math.round((a.Duty 
                 / 1000000) * 10) / 10 }; return obj });
            let CS = this.body.coldStreams.map(a => { let obj = { Name: a.name, 
                   Supply: a.Supply, Target: a.Target, Duty: Math.round((a.Duty 
                / 1000000) * 10) / 10 }; return obj });


            let Solution = {
                Results: {
                    IntervalTemp: sol.IntervalTemp,
                    HotInterval: sol.HotIntervalTemp,
                    ColdInterval: sol.ColdIntervalTemp,
                    HotDuty: Math.round((sol.Qhot / 1000000) * 10) / 10,
                    ColdDuty: Math.round((sol.Qcold / 1000000) * 10) / 10,
                },
                Units: {
                    temperature: this.Units.temperature,
                    duty: this.Units.duty
                },
                HotStreams: HS,
                ColdStreams: CS,
                Diagrams: {
                    HT_Diagram: this.HT_img,
                    GCC_Diagram: this.GCC_img,
                    Grid_Diagram: this.Grid_img,
                },
                UserData: {
                    username:this.username,
                    email:this.email
                }
            }

            fileName = "ByStreamReport"
            let report = new Stimulsoft.Report.StiReport();
            report.loadFile("./assets/stimulsoft/name.mrt");

            let dataSet = new Stimulsoft.System.Data.DataSet("Solution");
            dataSet.readJson(Solution);
            report.regData("Solution", "Solution", dataSet);

            let options = new Stimulsoft.Viewer.StiViewerOptions;
            let viewer = new Stimulsoft.Viewer.StiViewer(options);
            viewer.report = report;
            viewer.renderHtml("Report");

    },6000)
 }

之后,报表查看器在一个新的浏览器选项卡中打开,而不是像它应该的那样在引导选项卡内,并且浏览器崩溃,如下图所示,两个菜单出现在顶部和按钮上,当我将报告导出为 pdf,一切都很好,所有数据都在原位,

在此处输入图像描述 我想要的是在(生成报告)下方加载报告查看器,就像它在 html 代码中的位置一样。

如果您看到我的帖子缺少信息,请告诉我,我会立即对其进行编辑。

标签: javascriptangularreportreportingstimulsoft

解决方案


我在单击按钮后创建报告和选项实例并导致查看器崩溃的唯一问题,

只需将报告和查看器的实例创建为类中的属性即可解决

  export class SolutionComponent implements OnInit {

         viewer: any = new Stimulsoft.Viewer.StiViewer(null, 'StiViewer', false);
         report: any = new Stimulsoft.Report.StiReport();

         generateReport() { 
           // the rest of the code 
         }

现在它在页面和选项卡内工作正常

在此处输入图像描述


推荐阅读