【问题标题】:SAPUI5 attach chart to dialogSAPUI5 将图表附加到对话框
【发布时间】:2014-08-26 15:52:14
【问题描述】:

我在 SAPUI5 中定义了一个折线图。 当我将它放在我的 HTML 中的 DIV 时,它可以正常工作。

    var oChart = new sap.viz.ui5.Line({
        dataset : oDataset,
        yAxis : yAxis,
        title : {
            visible : true,
            text : 'Trend Chart'
        },
        legend : {
            visible : true,
        },

    });

oChart.setModel(oModel2);
oChart.placeAt("visual");

我的目标是将其放置在弹出/对话框/消息框中,无论弹出什么并且能够包含图表。我试图定义一个对话框并将此图放在上面,但没有用(可能是错误的 sytanx)。然后我尝试定义一个视图并将其放在对话框中,也没有工作。有人可以帮助我如何使用一点代码 sn-p 将图表放置在对话框/弹出窗口中,看来我做不到。 谢谢!

回答:invalidate() 是关键 (由于jsbin代码不会永远休息,我想分享答案)

$(function() {
  var oDataset = new sap.viz.ui5.data.FlattenedDataset({    
    dimensions : [     
      {axis : 1,name : 'Country',value : "{Country}"}     
    ],    
    measures : [     
      {name : 'Profit',value : '{profit}'},    
      {name : 'Revenue',value : '{revenue}'}     
    ],    
    data : {path : "/businessData"}    
  });  

  var legendPosition = new sap.viz.ui5.types.Legend({layout: {  
    position: "left"  
  }});   

  var stackedColumnVizChart = new sap.viz.ui5.StackedColumn("chartStackedColumn", {  
    width : "800px",  
    height : "500px",  
    title : {  },  
    dataset : oDataset,  
    legendGroup: legendPosition  
  });  
  stackedColumnVizChart.setModel(sap.ui.getCore().getModel());  

  var oModel = new sap.ui.model.json.JSONModel({    
    businessData : [    
      {Country :"Canada",revenue:410.87,profit:-141.25, population:34789000},    
      {Country :"China",revenue:338.29,profit:133.82, population:1339724852},    
      {Country :"France",revenue:487.66,profit:348.76, population:65350000},    
      {Country :"Germany",revenue:470.23,profit:217.29, population:81799600},    
      {Country :"India",revenue:170.93,profit:117.00, population:1210193422},    
      {Country :"United States",revenue:905.08,profit:609.16, population:313490000}    
    ]                
  });    

  stackedColumnVizChart.setModel(oModel);


  var dlg = new sap.m.Dialog({
    title: 'Text',
    width : "800px",  
    height : "600px",  
    content : [stackedColumnVizChart]
  });

  (new sap.m.Button({
    text: 'open',
    press: function() {
      dlg.open();
      stackedColumnVizChart.invalidate();
    }
  })).placeAt('content');
});

【问题讨论】:

  • 你能贴出你试过的代码吗?

标签: javascript dialog modal-dialog linechart sapui5


【解决方案1】:

我们也有类似的经历。图表似乎没有呈现自己。这是一个例子 http://jsbin.com/gaveq/1/edit

你可以看到我需要调用invalidate函数来渲染图表。

-D

【讨论】:

  • 不幸的是我没有让你的代码运行:(它仍然是空的。我用 ui.commons 按钮替换了移动对话框和按钮,但对话框仍然是空的。我把它放在主视图中,你在哪里打电话给你的代码?到目前为止谢谢!
  • 嗨 zyrex,请参阅 jsbin.com/seyoyaxitibe/1/edit。您需要在打开对话框时调用图表的无效。
  • 嗯,张艾伦只是做了我所做的,显然他认为解决方案是可以的。并在 diff jsbin 中提供了相同的代码。哦,好吧...
  • 您好 user3808826,我赞成您的回答。你的例子没有运行。我只是将您的代码从 src='sapui5.netweaver.ondemand.com/resources/sap-ui-core.js' 编辑为 src='sapui5.hana.ondemand.com/resources/sap-ui-core.js',因为 sapui5.netweaver.ondemand.com 有 https 问题来获取 js 文件。
  • 谢谢大家,你们都提供了有用的提示!它现在工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-07
  • 1970-01-01
  • 1970-01-01
  • 2018-01-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多