2017-10-08 81 views
0

嘗試連接圖表的數據,但我沒有顯示except for the empty charts。如何獲得對javaScript視圖的正確綁定或此代碼中的錯誤?下面列出的代碼片段,我也跟着上link的instructionson:如何綁定OData for SAPUI5圖表(sap.viz.ui5.VizContainer)

sap.ui.jsview("zui5_flight.BookingGraph", { 

     getControllerName : function() { 
        return null; 
     }, 

     createContent : function(oController) { 
      var oModel = new sap.ui.model.json.JSONModel(); 
      oModel.loadData("/salesOrderService.xsjs"); 

     // A Dataset defines how the model data is mapped to the chart 
      var oDataset = new sap.viz.ui5.data.FlattenedDataset({ 
       // a Bar Chart requires exactly one dimension (x-axis) 
       dimensions : [ { 
        axis : 1, // must be one for the x-axis, 2 for y-axis 
        name : 'CONNID', 
        value : "{CONNID}" 
       } ], 
       // it can show multiple measures, each results in a new set of bars in a new color 
       measures : [ 
       // measure 1 
       { 
        name : 'PRICE_ECO', // 'name' is used as label in the Legend 
        value : '{PRICE_ECO}' // 'value' defines the binding for the displayed value 
       } ], 
       // 'data' is used to bind the whole data collection that is to be displayed in the chart 
       data : { 
        path : "/" 
       } 
      }); 

      // create a VizContainer 
      var oVizContainer = new sap.viz.ui5.VizContainer({ 
       'uiConfig' : { 
        'layout' : 'vertical', 
        'enableMorphing' : true 
       }, 
       'width': '100%', 
       'height': '100%' 
      }); 

      // attach the model to the chart and display it 
      oVizContainer.setVizData(oDataset) 
      oVizContainer.setModel(oModel); 

      // set feeds 
      var aobjCustomer = new sap.viz.ui5.controls.common.feeds.AnalysisObject({ 
      uid : "customer_id", 
       name : "CONNID", 
       type : "Dimension" 
      }); 
      var aobjNetSales = new sap.viz.ui5.controls.common.feeds.AnalysisObject({ 
      uid : "netsales_id", 
       name : "PRICE_ECO", 
       type : "Measure" 
      }); 
      var feedPrimaryValues = new sap.viz.ui5.controls.common.feeds.FeedItem({ 
     uid : "primaryValues", 
       type : "Measure", 
       values : [ aobjNetSales ] 
      }); 
      var feedAxisLabels = new sap.viz.ui5.controls.common.feeds.FeedItem({ 
      uid : "axisLabels", 
       type : "Dimension", 
       values : [ aobjCustomer ] 
      }); 

      oVizContainer.addFeed(feedPrimaryValues); 
      oVizContainer.addFeed(feedAxisLabels); 

      // attach event listener for feedschange 
      oVizContainer.attachEvent('feedsChanged', function(e) { 
       // You could add your own logic to handle feedsChanged to set new dataset to vizContainer. 
       // Reset current data for demo purpose. 
       oVizContainer.setVizData(new sap.viz.ui5.data.FlattenedDataset({ 
        dimensions : [ { 
         axis : 1, 
         name : 'CONNID', 
         value : "{CONNID}" 
        } ], measures : [ { 
         name : 'PRICE_ECO', 
         value : '{PRICE_ECO}' 
        } ], data : { 
         path : "/" 
        } 
       })); 
       oVizContainer.setModel(oModel); 
      }); 

      return oVizContainer; 
} 
}); 

回答

0

(第8步動態使用VizContainer可視化),如果你真的跟着那個例子中,你loadData請求將有服務/在xsjs文件之前使用。也就是說,你的問題可以是你的數據請求或數據綁定。

檢查數據對象中的括號值(如{CONNID}和{PRICE_VALUE})是否是相同的常量,以及如果您的路徑(/)確實是數據對象的根目錄(對於OData服務,通常爲/ d /結果)。

在JSFiddle中提供您的數據的示例或應用程序的完整示例,我們可以在其中看到完整的代碼。

請問候, 恩裏克馬託斯

0

我已經改變了路徑JSON文件,它有now changed。但數據尚未顯示。爲什麼我不明白?這項服務的名字我沒有在我的道路斜線前,因爲沒有包在我的結構名稱 這裏是我當前的代碼:

sap.ui.jsview("zui5_flight.BookingGraph", { 

     getControllerName : function() { 
        return "zui5_flight.BookingGraph"; 
     }, 

     createContent : function(oController) { 
      var oModel = new sap.ui.model.json.JSONModel(); 
      oModel.loadData("/gbi-student-009/Backup/WebContent/salesOrderService.xsjs/"); 

     // A Dataset defines how the model data is mapped to the chart 
      var oDataset = new sap.viz.ui5.data.FlattenedDataset({ 
       // a Bar Chart requires exactly one dimension (x-axis) 
       dimensions : [ { 
        axis : 1, // must be one for the x-axis, 2 for y-axis 
        name : 'CONNID', 
        value : "{CONNID}" 
       } ], 
       // it can show multiple measures, each results in a new set of bars in a new color 
       measures : [ 
       // measure 1 
       { 
        name : 'PRICE_ECO', // 'name' is used as label in the Legend 
        value : '{PRICE_ECO}' // 'value' defines the binding for the displayed value 
       } ], 
       // 'data' is used to bind the whole data collection that is to be displayed in the chart 
       data : { 
        path : "/" 
       } 
      }); 

      // create a VizContainer 
      var oVizContainer = new sap.viz.ui5.VizContainer({ 
       'uiConfig' : { 
        'layout' : 'vertical', 
        'enableMorphing' : true 
       }, 
       'width': '100%', 
       'height': '100%' 
      }); 

      // attach the model to the chart and display it 
      oVizContainer.setVizData(oDataset) 
      oVizContainer.setModel(oModel); 

      // set feeds 
      var aobjCustomer = new sap.viz.ui5.controls.common.feeds.AnalysisObject({ 
      uid : "customer_id", 
       name : "CONNID", 
       type : "Dimension" 
      }); 
      var aobjNetSales = new sap.viz.ui5.controls.common.feeds.AnalysisObject({ 
      uid : "netsales_id", 
       name : "PRICE_ECO", 
       type : "Measure" 
      }); 
      var feedPrimaryValues = new sap.viz.ui5.controls.common.feeds.FeedItem({ 
     uid : "primaryValues", 
       type : "Measure", 
       values : [ aobjNetSales ] 
      }); 
      var feedAxisLabels = new sap.viz.ui5.controls.common.feeds.FeedItem({ 
      uid : "axisLabels", 
       type : "Dimension", 
       values : [ aobjCustomer ] 
      }); 

      oVizContainer.addFeed(feedPrimaryValues); 
      oVizContainer.addFeed(feedAxisLabels); 

      // attach event listener for feedschange 
      oVizContainer.attachEvent('feedsChanged', function(e) { 
       // You could add your own logic to handle feedsChanged to set new dataset to vizContainer. 
       // Reset current data for demo purpose. 
       oVizContainer.setVizData(new sap.viz.ui5.data.FlattenedDataset({ 
        dimensions : [ { 
         axis : 1, 
         name : 'CONNID', 
         value : "{CONNID}" 
        } ], measures : [ { 
         name : 'PRICE_ECO', 
         value : '{PRICE_ECO}' 
        } ], data : { 
         path : "/" 
        } 
       })); 
       oVizContainer.setModel(oModel); 
       oVizContainer 
      }); 

      return oVizContainer; 
} 
}); 

**這裏是在同一個包我的JSON文件:

var select_all_sales_orders_query = 
        "SELECT TOP 100 CONNID, SUM(PRICE_ECO) AS PRICE_ECO, SUM(PRICE_BUS) AS PRICE_BUS " + 
        "FROM \"_SYS_BIC\".\"gbi-student-009.UI5App.View/CV_Sales\" "+ 
        "GROUP BY CONNID"; 
function close(closables) { 
      var closable; 
      var i; 
      for (i = 0; i < closables.length; i++) { 
        closable = closables[i]; 
        if(closable) { 
           closable.close(); 
        } 
      } 
} 
function getSalesOrders(){ 
      var salesOrdersList = []; 
      var connection = $.db.getConnection(); 
      var statement = null; 
      var resultSet = null; 
      try{ 
        statement = connection.prepareStatement(select_all_sales_orders_query); 
        resultSet = statement.executeQuery(); 
        var salesOrder; 

        while (resultSet.next()) { 
           salesOrder = {}; 
           salesOrder.seats_eco = resultSet.getString(1); 
           salesOrder.seats_bus = resultSet.getString(1); 
           salesOrder.price_eco = resultSet.getDouble(2); 
           salesOrder.price_bus = resultSet.getDouble(3); 
           salesOrdersList.push(salesOrder); 
        } 
      } finally { 
        close([resultSet, statement, connection]); 
      } 
      return salesOrdersList; 
} 
function doGet() { 
      try{ 
        $.response.contentType = "application/json"; 
        $.response.setBody(JSON.stringify(getSalesOrders())); 
      } 
      catch(err){ 
        $.response.contentType = "text/plain"; 
        $.response.setBody("Error while executing query: [" + err.message + "]"); 
        $.response.returnCode = 200; 
      } 
} 
doGet(); 

其實我想的ODataModel連接到此表(而不是JSON),但也不起作用。顯示錶格輸出的相同數據的位置。

[1]: httsap.ui.jsview("zui5_flight.TestG", { 

     getControllerName : function() { 
        return "zui5_flight.TestG"; 
     }, 

     createContent : function(oController) { 
      var oModel = new sap.ui.model.odata.ODataModel("/gbi-student-009/UI5App/WebContent/OData/ODataService.xsodata/CV_Sales", true); 



     // A Dataset defines how the model data is mapped to the chart 
      var oDataset = new sap.viz.ui5.data.FlattenedDataset({ 
       // a Bar Chart requires exactly one dimension (x-axis) 
       dimensions : [ { 
        axis : 1, // must be one for the x-axis, 2 for y-axis 
        name : 'Customer', 
        value : "{CONNID}" 
       } ], 
       // it can show multiple measures, each results in a new set of bars in a new color 
       measures : [ 
       // measure 1 
       { 
        name : 'NetSales', // 'name' is used as label in the Legend 
        value : '{PRICE_ECO}' // 'value' defines the binding for the displayed value 
       } ], 
       // 'data' is used to bind the whole data collection that is to be displayed in the chart 
       data : { 
        path : "/" 
       } 
      }); 

      // create a VizContainer 
      var oVizContainer = new sap.viz.ui5.VizContainer({ 
       'uiConfig' : { 
        'layout' : 'vertical', 
        'enableMorphing' : true 
       }, 
       'width': '100%', 
       'height': '100%' 
      }); 

      // attach the model to the chart and display it 
      oVizContainer.setVizData(oDataset) 
      oVizContainer.setModel(oModel); 

      // set feeds 
      var aobjCustomer = new sap.viz.ui5.controls.common.feeds.AnalysisObject({ 
      uid : "customer_id", 
       name : "Customer", 
       type : "Dimension" 
      }); 
      var aobjNetSales = new sap.viz.ui5.controls.common.feeds.AnalysisObject({ 
      uid : "netsales_id", 
       name : "NetSales", 
       type : "Measure" 
      }); 
      var feedPrimaryValues = new sap.viz.ui5.controls.common.feeds.FeedItem({ 
     uid : "primaryValues", 
       type : "Measure", 
       values : [ aobjNetSales ] 
      }); 
      var feedAxisLabels = new sap.viz.ui5.controls.common.feeds.FeedItem({ 
      uid : "axisLabels", 
       type : "Dimension", 
       values : [ aobjCustomer ] 
      }); 

      oVizContainer.addFeed(feedPrimaryValues); 
      oVizContainer.addFeed(feedAxisLabels); 

      // attach event listener for feedschange 
      oVizContainer.attachEvent('feedsChanged', function(e) { 
       // You could add your own logic to handle feedsChanged to set new dataset to vizContainer. 
       // Reset current data for demo purpose. 
       oVizContainer.setVizData(new sap.viz.ui5.data.FlattenedDataset({ 
        dimensions : [ { 
         axis : 1, 
         name : 'Customer', 
         value : "{CONNID}" 
        } ], measures : [ { 
         name : 'NetSales', 
         value : '{PRICE_ECO}' 
        } ], data : { 
         path : "/" 
        } 
       })); 
       oVizContainer.setModel(oModel); 
      }); 

      return oVizContainer; 
} 
});