Javascript 在sapui5中的图表中设置json对象计数

Javascript 在sapui5中的图表中设置json对象计数,javascript,json,sapui5,Javascript,Json,Sapui5,我试图显示vizframe中json对象的计数,但是 我无法在VIZ帧中设置计数。 请帮助设置框架中的数据。我使用下面的代码来实现这一点 sapui5视图: createContent : function (oController) { // some business data var oModel = new sap.ui.model.json.JSONModel({ businessData: [ {Country: "Canad

我试图显示vizframe中json对象的计数,但是 我无法在VIZ帧中设置计数。 请帮助设置框架中的数据。我使用下面的代码来实现这一点

sapui5视图:

createContent : function (oController) {

    // some business data
    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}
        ]
    });

    count = oModel.getProperty("/businessData/length");
    /* sap.ui.getCore().byId("chart1");*/
    console.log(count);

    // A Dataset defines how the model data is mapped to the chart
    var oDataset = new sap.viz.ui5.data.FlattenedDataset("chart1", {

        // a Bar Chart requires exactly one dimension (x-axis)
        dimensions: [
            {
                axis: 1, // must be one for the x-axis, 2 for y-axis
                name: 'Country',
                value: "{Country}"
            }
        ],

        // it can show multiple measures, each results in a new set of bars in a new color
        measures: [
            // measure 1
            {
                name: 'Profit', // 'name' is used as label in the Legend
                value: '{count}' // '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


    });

    // create a Bar chart
    // you also might use Combination, Line, StackedColumn100, StackedColumn or Column
    // for Donut and Pie please remove one of the two measures in the above Dataset.
    var oBarChart = new sap.viz.ui5.Bar({
        width: "80%",
        height: "400px",
        plotArea: {
            //'colorPalette' : d3.scale.category20().range()
        },
        title: {
            visible: true,
            text: 'Profit and Revenue By Country'
        },
        dataset: oDataset
    });

    // attach the model to the chart and display it

    oBarChart.setModel(oModel);

    return new sap.m.Page({
        title: "Title",
        content: [oBarChart]
    });
}
如果您想获得我绘制的图形,您需要更改some_name.view.xml中的代码,如下所示:

<viz:VizFrame id="vizFrame" uiConfig="{applicationSet:'fiori'}"></viz:VizFrame>
<viz:VizFrame id="vizFrame" uiConfig="{applicationSet:'fiori'}"></viz:VizFrame>
generateChart : function(){

     var oChart = this.getView().byId("vizFrame");
     var oDataset = new sap.viz.ui5.data.FlattenedDataset({
        dimensions : [
        {
            name : "Country name",
            value : "{Country}"
        }],
        measures : [{
            name : "Profit values",
            value : "{profit}"
        },
        {
            name : "Revenue values",
            value : "{revenue}"
        }],
      });

    oChart.setDataset(oDataset)       

    var feedValueAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
        'uid' : "valueAxis",
        'type' : "Measure",
        'values' : ["Profit values", "Revenue values"]
    }), feedCategoryAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
        'uid' : "categoryAxis",
        'type' : "Dimension",                   
        'values' : ["Country name"] 
    });

    oChart.removeAllFeeds();
    oChart.addFeed(feedValueAxis);
    oChart.addFeed(feedCategoryAxis);
    oChart.setVizType('bar');    
}