4
votes

I have a problem with the VizFrame control of the SAPUI5 Framework. I want to display some data in an complex chart with two Y-axes. My data model looks like this:

{
      "d" : {
        "results" : [
          {
            "DataA" : "2",
            "DataB" : "4",
            "Id" : "1",
          },
          {
            "DataA" : "3",
            "DataB" : "2",
            "Id" : "2",
          }
       ]
   }
}

I tried to display DataA on the left Y-Axis and DataB on the right one, while using the Id for the X-Axis. This works without problems with the VizFrame types: dual_line and dual_column.

I havent found a way to display the data as a bar (DataA on Y1) and line (DataB on Y2). My current coding looks like this:

var oModel = new sap.ui.model.json.JSONModel();
        
        oModel.loadData("data.json");

        var oDataset = new sap.viz.ui5.data.FlattenedDataset({              
            dimensions: [{
                axis : 2,
                name : oLocText.getText('Id'),
                value : "{Id}"
            }],         
            measures : [{
                    group : 1,
                    name : DataA,
                    value : '{DataA}'
                },{
                    group : 2,
                    name: DataB,
                    value: '{DataB}'
                }],
            data : {
                path : "/d/results"
            }
        }); 
    
        oVizFrame.setDataset(oDataset);
        oVizFrame.setModel(oModel); 
        oVizFrame.setVizType('combination');

        oVizFrame.setVizProperties({
            title: {
                  visible: true,
                  text: "Combined"
              },            
            plotArea: {
                colorPalette : d3.scale.category20().range(),
            }});
        
        var feedValueAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
              'uid': "primaryValues",
              'type': "Measure",
              'values': [ DataA , DataB]
            }),
            feedCategoryAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({
              'uid': "axisLabels",
              'type': "Dimension",
              'values': [ Id]
            });
            
        oVizFrame.addFeed(feedValueAxis);
        oVizFrame.addFeed(feedCategoryAxis); 

Thank you very much for your help!

2

2 Answers

0
votes

Please try:

var feedValueAxis1 = new sap.viz.ui5.controls.common.feeds.FeedItem({
              'uid': "valueAxis",
              'type': "Measure",
              'values': [ DataA ]
            }), feedValueAxis2 = new sap.viz.ui5.controls.common.feeds.FeedItem({
              'uid': "valueAxis2",
              'type': "Measure",
              'values': [DataB]
            }),

it will automatically plot DataA against left axis as bar and DataB against right axis as line.

Please be noticed that dual combination was available starting from SAPUI5 1.40.

0
votes

I don´t know if your question is still relevant. If I got your question right it´s about displaying measures as bar / line. I had a similar problem and I solved it by setting the dataShape property of plotArea:

oVizFrame.setVizProperties({
    plotArea: { dataShape : {primaryAxis : ['bar','bar','bar'],
                            secondaryAxis : ['line', 'line', 'line']}}
});

In this example a maximum of 3 measures on each axis would be drawn as bar on axis 1 and as line on axis 2. I guess once you see this coding you know what to do when you would like to change bar vs. line. One remark: only 'bar' and 'line' are allowed here (I checked the docu and also source code). Best regards, Sebastian