SAPUI5-将数据绑定到视图转发器控件内的图表
需要有关SAPUI5的帮助,我正在尝试创建一个如下所述的视图。 我使用的是View repeater控件,在View repeater控件内部使用的是VIZ图表控件。 我面临的问题是无法将数据绑定到图表,尽管我可以将数据绑定到repeater控件 下面是我使用的JSONSAPUI5-将数据绑定到视图转发器控件内的图表,sapui5,Sapui5,需要有关SAPUI5的帮助,我正在尝试创建一个如下所述的视图。 我使用的是View repeater控件,在View repeater控件内部使用的是VIZ图表控件。 我面临的问题是无法将数据绑定到图表,尽管我可以将数据绑定到repeater控件 下面是我使用的JSON "plants":[ { "plant":"Plant1", "cCode":"**
"plants":[
{
"plant":"Plant1",
"cCode":"***",
"Function":[
{"FunName":"fun1","Count":10},
{"FunName":" fun2","Count":10},
{"FunName":" fun3","Count":10},
{"FunName":"fun4","Count":0},
{"FunName":"fun5","Count":11},
{"FunName":" fun6","Count":10},
{"FunName":"fun7","Count":10}
]
},
{
"plant":"Plant2",
"cCode":"***",
"Function":[
{"FunName":"fun1","Count":10},
{"FunName":" fun2","Count":10},
{"FunName":" fun3","Count":10},
{"FunName":"fun4","Count":0},
{"FunName":"fun5","Count":11},
{"FunName":" fun6","Count":10},
{"FunName":"fun7","Count":10}
]
}
]
}
我的看法是:
createContent : function(oController) {
// var oModel = new sap.ui.model.json.JSONModel();
// oModel.loadData("model/plantreport.json");
var oModel = new sap.ui.model.json.JSONModel({
"plants":[
{
"plant":"Plant1",
"cCode":"10",
"Function":[
{"FunName":"fun1","Count":10},
{"FunName":" fun2","Count":10},
{"FunName":" fun3","Count":10},
{"FunName":"fun4","Count":0},
{"FunName":"fun5","Count":11},
{"FunName":" fun6","Count":10},
{"FunName":"fun7","Count":10}
]
},
{
"plant":"Plant2",
"cCode":"20",
"Function":[
{"FunName":"fun1","Count":10},
{"FunName":" fun2","Count":10},
{"FunName":" fun3","Count":10},
{"FunName":"fun4","Count":0},
{"FunName":"fun5","Count":11},
{"FunName":" fun6","Count":10},
{"FunName":"fun7","Count":10}
]
}
]
});
//////// CONTROL SECTION ///////////////////////////////////////////////////////////////////
//
//create view repeater title (optional)
var oTitle_NoViews = new sap.ui.commons.Title({
text:"Testing Please",
level: sap.ui.commons.TitleLevel.H1
});
var oLayout = new sap.ui.layout.VerticalLayout();
// create the row repeater control
var oViewRepeater_NoViews = new sap.suite.ui.commons.ViewRepeater("vr_noViews",
{
showViews: false,
noData: new sap.ui.commons.TextView({text: "Sorry, no data available!"}),
showSearchField: false,
showMoreSteps: 10, // you can use 'Show More' feature instead of paging
//set view properties directly to the repeater
responsive: false,
itemMinWidth: 210,
numberOfRows: 12
});
oViewRepeater_NoViews.bindAggregation("rows", {
path : "/plants",
factory : function(sId, oContext) {
var sPath = oContext.sPath;
//Text
control = new sap.ui.commons.TextView();
control.bindProperty("text",oContext.sPath+"/plant");
oLayout.addContent(control);
//add content to cell, cell to row
var oTemplate = new sap.viz.ui5.data.DimensionDefinition({
axis: 1,
name : "Plant Name"
});
oTemplate.bindProperty("value", "FunName", function(value) {
if (value) {
return value;
}
});
var oTemplate2 = new sap.viz.ui5.data.MeasureDefinition({
name : "Count"
});
oTemplate2.bindProperty("value", "Count", function(value) {
if (value) {
return value;
}
return 0;
});
var oDataset = new sap.viz.ui5.data.FlattenedDataset({
dimensions : [ oTemplate ],
measures : [ oTemplate2 ]
});
oDataset.bindAggregation("data", sPath + "/Function");
var oBarChart = new sap.viz.ui5.Bar({
width : "300px",
height : "250px",
plotArea : {
xAxis : {
}
},
title : {
visible : true,
text : 'MY Graph'
},
dataset : oDataset
});
oLayout.addContent(oBarChart);
return oLayout;
}
});
oViewRepeater_NoViews.setModel(oModel);
return new sap.m.Page({
title: "Plant Report",
showNavButton: "{device>/isPhone}",
navButtonPress: [oController.doNavBack, oController],
content: [oViewRepeater_NoViews],
headerContent: [],
footer: new sap.m.Bar({})
});
}
您对VIZCharts的绑定不正确。它可能是复制粘贴的,因为它还使用命名模型
oModel
。此外,您从绝对根/plants
开始,然后是/Function
,而您可能希望从当前plants
元素的相对路径Function
开始
如果将绑定更改为相对路径:data:{path:“Function”}
它应该可以工作(您可能需要调整图表的大小以适合视图中继器块。)
通过将其更改为相对路径
函数
,它将从当前的/plants
元素中获取数据。您还可以分享如何创建带有图表的视图转发器,以及如何设置绑定吗?没有这些,就不可能知道哪里出了问题;-)不,这不起作用,现在我使用了factory功能(参见上面更新的视图),页面加载时不显示图表,但在单击“显示更多”按钮后,请帮助,这应该是不必要的。只是装订错误,图表的大小也不对(它们太大了,无法显示)。请参阅此要点以了解一个工作示例:这是可行的,但我仍然有一个问题,我使用拆分控件,左侧有两个链接,只有一个页面加载图表,另一个页面不加载图表。不确定出了什么问题。我很快就会发布我的代码。