[英]SAPUI5 attach chart to dialog
I've defined a line chart in SAPUI5. 我已经在SAPUI5中定义了一个折线图。 It works properly when I place it at an DIV in my HTML.
当我将其放在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");
My Goal is to place it in an popup/dialog/messagebox whatever pops up and is able to contain the graph. 我的目标是将其放置在弹出窗口/对话框/消息框中,无论出现什么弹出窗口并能够包含图形。 I tried to define an dialog and place this graph on it, didnt work (propably wrong sytanx).
我试图定义一个对话框并将其放置在该图上,但没有起作用(可能是错误的sytanx)。 then I tried to define an view and place it at the dialog, also didnt work.
然后我尝试定义一个视图并将其放置在对话框中,也没有用。 Can somebody help me how to place the chart in a dialog/popup with a little code snippet, it seems that I am not able to do it.
有人可以帮我如何将图表放置在带有一些代码段的对话框/弹出窗口中,看来我做不到。 Thanks!
谢谢!
ANSWERED : invalidate() is the key (due to the fact, that jsbin code does not rest forever, I want to share the answer) 回答 :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');
});
We have some similar experience too. 我们也有类似的经验。 It appears that the chart does not render itself.
图表似乎没有呈现自身。 Here is an example http://jsbin.com/gaveq/1/edit
这是一个示例http://jsbin.com/gaveq/1/edit
you can see that I need to call invalidate function to get the chart to render. 您会看到我需要调用invalidate函数来获取要呈现的图表。
-D -D
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.