cancel
Showing results for 
Search instead for 
Did you mean: 

Supplying data to the bar graph using JSON Model

Former Member
0 Kudos

Hi All,

We have a bar graph in SAPUI5; We have a xsjs service which provides the data in json format.

I am trying to populate the model using code snippet as below:

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

businessData :[// "http://172.22.0.168:8000/osmosis/Sales_json.xsjs?sorg='INSO'&div='02'&dchan='IN'"]

});          

Bar graph does not show up. Is there a way to make the Bar Graph consume the data from this xsjs service?

Regards,

Ganga

Accepted Solutions (1)

Accepted Solutions (1)

GrahamRobbo
Active Contributor
0 Kudos

Hi Ganga,

It's a bit hard to be certain from your question, but try..

var oModel = new sap.ui.model.json.JSONModel("http://172.22.0.168:8000/osmosis/Sales_json.xsjs?sorg='INSO'&div='02'&dchan='IN'");

Cheers

Graham Robbo

Former Member
0 Kudos

Hi,

Thanks for the reply.  The code we are trying is:

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

    {

                    businessData : ["http://172.22.0.168:8000/osmosis/Sales_json.xsjs?sorg='INSO'&div='04'&dchan='IN'"]

          });

   

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

                    dimensions : [

                              {

                                        axis : 1, // must be one for the x-axis, 2 for y-axis

                                        name : 'material',

                                        value : "{material}"

                              }

                              , {

                axis : 1,

                name : 'year',

                value : "{year}"

      }, {

                axis : 2,

                name : 'quantity',

                value : "{quantity}"

      }

                    ],

                    measures : [

                              {

                                        name : 'quantity', // 'name' is used as label in the Legend

                                        value : '{v}' // 'value' defines the binding for the displayed value  

                              }

                    ],

 

                    data : {

                              path : "/businessData"

                    }

 

          });

          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

          });

          oBarChart.setModel(oModel);

          oBarChart.placeAt("content","first");

GrahamRobbo
Active Contributor
0 Kudos

Did you try my previous suggestion?

Former Member
0 Kudos

Hi Graham,

Thanks for your reply.

We tried your suggestion, but it did not work.

Thanks ,

Shreepad

konstantin_anikeev
Active Contributor
0 Kudos

Hi Graham,

I suppose, usage of direct will not word, because URL delivers not a valid JSON object.

Best Regards

Konstantin

GrahamRobbo
Active Contributor
0 Kudos

That's a bit of surprise as it works for me.

All I did was change your JSON payload to make it valid and changed the definition of the model to be like this...

var oModel = new sap.ui.model.json.JSONModel('mytest.json');

The mytest.json payload looks like this...

{

  "businessData" : [

                    {

                      "material" : "Material 1",

                      "year" : 2010,

                      "quantity" : 12600

                    }, {

                      "material" : "Material 2",

                      "year" : 2010,

                      "quantity" : 1500

                    }, {

                      "material" : "Material 1",

                      "year" : 2011,

                      "quantity" : 13600

                    }, {

                      "material" : "Material 2",

                      "year" : 2011,

                      "quantity" : 18600

                    }, {

                      "material" : "Material 1",

                      "year" : 2012,

                      "quantity" : 12600

                    }, {

                      "material" : "Material 2",

                      "year" : 2012,

                      "quantity" : 12600

                    }

  ]

}

Cheers

Graham Robbo

Former Member
0 Kudos

Hi Graham,

we are using

var oModel = new sap.ui.model.json.JSONModel("http://<host>:<port>/osmosis/Sales_json.xsjs?sorg='INSO'&div='02'&dchan='IN'");


oModel is not giving the data available in the url. The values shows as below.

oModel as EventProvider sap.ui.model.json.JSONModel

And oModel.getData() as [object Object]

Thanks,

Srinivas

GrahamRobbo
Active Contributor
0 Kudos

Hi Srinivas,

perhaps the JSON payload is invalid? I use http://json.parser.online.fr/ to validate my JSON.

Cheers

Graham

Former Member
0 Kudos

how to operate on a model ? delete,add.....

Answers (2)

Answers (2)

Former Member
0 Kudos

This message was moderated.

konstantin_anikeev
Active Contributor
0 Kudos

Hi Ganga,

how the json responce looks like?

Best Regards

Konstantin

Former Member
0 Kudos

Hi,

Thanks for reply.

Data format looks as following:

konstantin_anikeev
Active Contributor
0 Kudos

Hi Ganga,

have you tried to set the responce direct in code instead of http url. Will it work for you?

Also you use {v}, but there is no v in your model.

Waiting for your answer.

Best Regards

Konstantin