堆叠柱与线结合

时间:2015-04-08 14:22:00

标签: sapui5

我们需要显示一个叠加的柱形图和折线图,并希望坚持UI5提供的VizFrame控件。有没有办法实现这个目标?它没有在样本中列出(https://sapui5.netweaver.ondemand.com/sdk/explored.html#/entity/sap.viz.ui5.controls.VizFrame/samples),但也许还有办法可以做到。

修改

我们需要显示的数据采用以下格式:

var data = [
    {week: 1, stacked1: 10, stacked2: 20, stacked3: 30, line: 100},
    {week: 2, stacked1: 12, stacked2: 13, stacked3: 14, line: 40},
    {week: 3, stacked1: 14, stacked2: 25, stacked3: 26, line: 20},
    {week: 4, stacked1: 15, stacked2: 24, stacked3: 33, line: 52}
];

因此,我们的想法是在x轴上有数周,堆叠的条形图为堆叠1,堆叠2和堆叠3以及该线的值点。

1 个答案:

答案 0 :(得分:3)

我想你想在VizFrame上使用setVizType(" stacked_combination")[或vizType:" stacked_combination"]。您可以在getVizType()VizFrame doumentation上看到所有类型。这是一个简单的例子,我扩展了VizFrame并添加了两个函数来显示Line Stacked Column Chart:

sap.viz.ui5.controls.VizFrame.extend("jonova.ui5.chart.JuVizFrame", {
  renderer: { },

  setLineStackedBar: function() {
    var oModel = new sap.ui.model.json.JSONModel(
            [{Product:"Total",  Date: 2000, Available: 100},
             {Product:"Total",  Date: 2001, Available: 100},
             {Product:"P1",         Date: 2000, Utilized:  30},
             {Product:"P1",         Date: 2001, Utilized:  20},
             {Product:"P2",         Date: 2000, Utilized:  40},
             {Product:"P2",         Date: 2001, Utilized:  60}]);
    var oDataset = new sap.viz.ui5.data.FlattenedDataset({
        dimensions: [{name: 'Date',      value: '{Date}'},
                     {name: 'Product',   value: '{Product}'}],
        measures:   [{name: 'Available', value: '{Available}'},
                     {name: 'Utilized',  value: '{Utilized}' }],
        data:        {path: "/"}});
    var oFeeds = [new sap.viz.ui5.controls.common.feeds.FeedItem({uid: "valueAxis",    type: "Measure",   values: ["Utilized", "Available"]}),
                  new sap.viz.ui5.controls.common.feeds.FeedItem({uid: "categoryAxis", type: "Dimension", values: ["Date"]}),
                  new sap.viz.ui5.controls.common.feeds.FeedItem({uid: "color",        type: "Dimension", values: ["Product"]})];
    this.setChart("stacked_combination", oDataset, oModel, oFeeds);
  },

  setChart: function(aVizType, aDataset, aModel, aFeeds) {
    this.setVizType(aVizType);
    this.setDataset(aDataset);
    this.setModel(aModel);
    for( var i=0, len=aFeeds.length; i<len; i++) this.addFeed(aFeeds[i]);
  },
});