Skip to Content
author's profile photo Former Member
Former Member

How to skip null values in sap.viz.ui5.data.FlattenedDataset

Hi Experts,

I need to skip null values from Viz Charts in SapUI5. Please post solution for this.

my code is ,

var oModel = new sap.ui.model.json.JSONModel({

businessData : [

{Country :null,revenue : 0,profit: 0, population:0},

{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}

]

});

// A Dataset defines how the model data is mapped to the chart

var oDataset = new sap.viz.ui5.data.FlattenedDataset({

dimensions : [

{

axis : 1,

name : 'Country',

value : "{Country}"

}

],

measures : [

{

name : 'Profit',

value : '{profit}'

},

{

name : 'Revenue',

value : '{revenue}'

}

],

data : {

path : "/businessData"

}

});

var oBarChart = new sap.viz.ui5.Bar({

width : "80%",

height : "400px",

plotArea : {

},

title : {

visible : true,

text : 'Profit and Revenue By Country'

},

dataset : oDataset

});

oBarChart.setModel(oModel);

return(oBarChart);

In output page i am getting a value as NO VALUE . I need to skip this from my output vizchart.

Thanks,

Sandeep

Capture.JPG (42.4 kB)
Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 03, 2015 at 08:23 PM

    Hi Sandeep You can use SAPUI5 Filter For Solve your problem.

    Please refer the following modified code.

    var oModel = new sap.ui.model.json.JSONModel({ businessData : [ {Country :null,revenue : 0,profit: 0, population:0}, {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} ] }); var filter = new sap.ui.model.Filter("Country", function(oValue){ return oValue!==null; }); // A Dataset defines how the model data is mapped to the chart var oDataset = new sap.viz.ui5.data.FlattenedDataset({ dimensions : [ { axis : 1, name : 'Country', value : "{Country}" } ], measures : [ { name : 'Profit', value : '{profit}' }, { name : 'Revenue', value : '{revenue}' } ], /* data : { path : "/businessData" }*/ }).bindData("/businessData",null,null,[filter]); var oBarChart = new sap.viz.ui5.Bar({ width : "80%", height : "400px", plotArea : { }, title : { visible : true, text : 'Profit and Revenue By Country' }, dataset : oDataset }); oBarChart.setModel(oModel); return(oBarChart);

    Please Check Once.And if you face any problem.Ask Me....

    Always Happy To Help You... 😎


    SAPUI5 Graph.PNG (28.0 kB)
    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Hi tried your code .But it doesn't works properly as per my condition.

      I have 6 countries . In which 3 countries have profit less than 0 and 3 greater than 0.

      I have made condition like if profit is greater than 0 then color is "green" orelse "red".

      But my code applies red color to all countries irrespective of profit.

      I need color to be assigned based on the value of profit, can you please suggest some solution for this ???

      var oModel = new sap.ui.model.json.JSONModel({

      businessData: [{

      Country: null,

      profit: 0,

      population: 0

      }, {

      Country: "Canada",

      profit: -141.25,

      population: 34789000

      }, {

      Country: "China",

      profit: 133.82,

      population: 1339724852

      }, {

      Country: "France",

      profit: 148.76,

      population: 65350000

      }, {

      Country: "Germany",

      profit: -117.29,

      population: 81799600

      }, {

      Country: "India",

      profit: 117.00,

      population: 1210193422

      }, {

      Country: "United States",

      profit: -109.16,

      population: 313490000

      }]

      });

      var filter = new sap.ui.model.Filter("Country", function(oValue) {

      return oValue !== null;

      });

      // A Dataset defines how the model data is mapped to the chart

      var oDataset = new sap.viz.ui5.data.FlattenedDataset({

      dimensions: [{

      axis: 1,

      name: 'Country',

      value: "{Country}"

      }],

      measures: [{

      name: 'Profit',

      //value : '{profit}'

      value: {

      path: "profit",

      formatter: function(oVal) {

      if (oVal > 0) {

      oBarChart.getAggregation('plotArea').setColorPalette(['#00B050']);

      } else {

      oBarChart.getAggregation('plotArea').setColorPalette(['#FF0000']);

      }

      return oVal;

      }

      }

      }]

      }).bindData("/businessData", null, null, [filter]);

      var oBarChart = new sap.viz.ui5.Bar({

      width: "80%",

      height: "400px",

      plotArea: {

      },

      title: {

      visible: true,

      text: 'Profit By Country'

      },

      dataset: oDataset

      });

      oBarChart.setModel(oModel);

      return (oBarChart);

      Capture2.JPG (45.9 kB)

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.