0
votes

Need a help on SAPUI5, I am trying to create a View as described below. I am using the View repeater control and inside the View repeater control using the VIZ chart control . The problem I am facing is not able to bind data to the chart though I am able to bind data to the repeater control.

Below is the JSON I use.

    "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}
                            ]


            }
            ]

}

My View:

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({})
        });
}
1
Can you also share how you created the view repeater with charts, and how you set up the bindings? Without these, it's impossible to tell where it goes wrong ;-)Qualiture

1 Answers

0
votes

Your binding for the VIZCharts is incorrect. It's probably copy-pasted since it also uses a named model oModel. Furthermore, you're starting from the absolute root /plants and then /Function, whereas you probably want to start from the relative path Function for the current plants element.

If you change the binding to a relative path: data:{path:"Function"} it should work (you may need to adapt the size of the chart to fit the view repeater block.)

By changing it to the relative path Function, it will take the data from the current /plants element.