cancel
Showing results for 
Search instead for 
Did you mean: 

How to create Bar Chart in XMLview?

Former Member
0 Kudos

Dear Experts,

Currently I intend to create the bar chart by using the mock data in the second IconTabFilter in the detail.view.xml. I copied the code directly from SAPUI5 Demo Kit there but i am not sure whether there are errors, what should be add in the index.html, detail.controller.xml (in onInit: function()) or detail.view.xml in order to display data in the bar chart. Please correct me if any part i did wrong.

Thanks.

Here is the onInit Function:

onInit: function() {

        this.oInitialLoadFinishedDeferred = jQuery.Deferred();

        var oVizFrame = sap.ui.getCore().byId("idVizFrameBar");

        var oPopOver = sap.ui.getCore().byId("idPopOver");

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

            SOItems: [

                {

                    ITEM: "Tablet",

                    QUANTITY: 2067.45,

                    VALUE: 7373.99,

                    COLOR: "red"

                },

                {

                    ITEM: "Desktop",

                    QUANTITY: 3110.93,

                    VALUE: 9920.91,

                    COLOR: "green"

                },

                {

                    ITEM: "Mouse",

                    QUANTITY: 3003.97,

                    VALUE: 2058.64,

                    COLOR: "blue"

                },

                {

                    ITEM: "Modem",

                    QUANTITY: 6721.61,

                    VALUE: 9149.65,

                    COLOR: "purple"

                },

                {

                    ITEM: "Printer",

                    QUANTITY: 9636.25,

                    VALUE: 3752.46,

                    COLOR: "orange"

                },

                {

                    ITEM: "Ink",

                    QUANTITY: 9169.62,

                    VALUE: 9221.43,

                    COLOR: "yellow"

                }

        ]

        });

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

            dimensions: [{

                axis: 1,

                name: "Item",

                value: "{ITEM}"

            }],

            measures: [{

                    name: "Quantity",

                    value: "{QUANTITY}"

            },

                {

                    name: "Value",

                    value: "{VALUE}"

            }],

            data: {

                path: "/SOItems"

            }

        });

        oVizFrame.setModel(oModel);

        oVizFrame.setDataset(oDataset);

        // set feeds

        var feedPrimaryValues = new sap.viz.ui5.controls.common.feeds.FeedItem({

                uid: "primaryValues",

                type: "Measure",

                values: "{QUANTITY}"

            }),

            feedAxisLabels = new sap.viz.ui5.controls.common.feeds.FeedItem({

                uid: "axisLabels",

                type: "Dimension",

                values: [new sap.viz.ui5.controls.common.feeds.AnalysisObject({

                    uid: "Item",

                    type: "Dimension",

                    name: "Item"

                })]

            }),

            feedColor = new sap.viz.ui5.controls.common.feeds.FeedItem({

                uid: "color",

                type: "Measure",

                values: "{VALUE}"

            });

        oVizFrame.setVizProperties({

            valueAxis: {

                label: {

                    formatString: "u"

                }

            },

            plotArea: {

                dataLabel: {

                    visible: true

                    //colorPalette:"{#00FF00,#FFC200,#FF0000,,#FFC200,#FF0000, #00FF00}"

                }

            },

            legend: {

                title: {

                    visible: false

                }

            },

            title: {

                visible: true,

                text: "Value by Quantity and Item"

            }

        });

        oVizFrame.addFeed(feedPrimaryValues);

        oVizFrame.addFeed(feedAxisLabels);

        oVizFrame.addFeed(feedColor);

        oPopOver.connect(oVizFrame.getVizUid());

Regards,

Loh

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

you said you copied everything from sample

so why dont copy rest of it?

SAPUI5 Explored

detail.view.xml

<mvc:View height="100%" width="100%"
  controllerName="YOUR_NAMESPACE.detail" xmlns:viz="sap.viz.ui5.controls" xmlns:mvc="sap.ui.core.mvc" xmlns="sap.m"
  xmlns:html="http://www.w3.org/1999/xhtml">
  <ScrollContainer height="100%" width="100%" horizontal="false" vertical="true" focusable="true">
  <viz:Popover id="idPopOver"></viz:Popover>
  <viz:VizFrame id="idVizFrameBar" uiConfig="{applicationSet:'fiori'}" vizType="bar" width="100%" height="700px"></viz:VizFrame>
  </ScrollContainer>
</mvc:View>

Former Member
0 Kudos

Hi Maksim, i am using the trial version cloud web ide (XML view) and i have used the code that you provided me in detail.view.xml before but it still cant work. I don not where is going wrong, hope you able to help me.I cant send the project zip file to you, if you need it i can you the project zip file through email for you to refer.

Thanks

In index.html :

<!DOCTYPE HTML>

<html>

  <head>

  <meta http-equiv="X-UA-Compatible" content="IE=edge" />

  <meta charset="UTF-8">

  <title>MockSales</title>

  <script id="sap-ui-bootstrap"

  src="resources/sap-ui-core.js"

  data-sap-ui-libs="sap.m,sap.ui.commons,sap.viz"

  data-sap-ui-theme="sap_bluecrystal"

  data-sap-ui-xx-bindingSyntax="complex"

  data-sap-ui-resourceroots='{"SO": "./"}'>

  </script>

  <link rel="stylesheet" type="text/css" href="css/style.css">

  <script>

  sap.ui.getCore().attachInit(function() {

  new sap.m.Shell({

  app: new sap.ui.core.ComponentContainer({

  height : "100%",

  name : "SO"

  })

  }).placeAt("content");

  });

  </script>

   </head>

  <body class="sapUiBody" >

  </body>

</html>

In detail.vew.xml :

<IconTabFilter icon="sap-icon://enter-more" id="iconTabFilter2" key="SOItems">

  <content>

  <ScrollContainer focusable="true" height="100%" horizontal="false" vertical="true" width="100%">

  <viz:Popover id="idPopOver"></viz:Popover>

  <viz:VizFrame height="700px" id="idVizFrameBar" uiConfig="{applicationSet:'fiori'}" vizType="bar" width="100%"></viz:VizFrame>

  </ScrollContainer>

  </content>

  </IconTabFilter>

In detail.controller.xml

onInit: function() {

  this.oInitialLoadFinishedDeferred = jQuery.Deferred();

  var oVizFrame = sap.ui.getCore().byId("idVizFrameBar");

  //varoPopOver = sap.ui.getCore().byId("idPopOver");

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

  SOItems: [

  {

  ITEM: "Tablet",

  QUANTITY: 2067.45,

  VALUE: 7373.99,

  COLOR: "red"

  },

  {

  ITEM: "Desktop",

  QUANTITY: 3110.93,

  VALUE: 9920.91,

  COLOR: "green"

  },

  {

  ITEM: "Mouse",

  QUANTITY: 3003.97,

  VALUE: 2058.64,

  COLOR: "blue"

  },

  {

  ITEM: "Modem",

  QUANTITY: 6721.61,

  VALUE: 9149.65,

  COLOR: "purple"

  },

  {

  ITEM: "Printer",

  QUANTITY: 9636.25,

  VALUE: 3752.46,

  COLOR: "orange"

  },

  {

  ITEM: "Ink",

  QUANTITY: 9169.62,

  VALUE: 9221.43,

  COLOR: "yellow"

  }

  ]

  });

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

  dimensions: [{

  axis: 1,

  name: "Item",

  value: "{ITEM}"

            }],

  measures: [{

  name: "Quantity",

  value: "{QUANTITY}"

            }],

  data: {

  path: "/SOItems"

  }

  });

  oVizFrame.setDataset(oDataset);

  oVizFrame.setVizData(oModel);

  // set feeds

  var feedPrimaryValues = new sap.viz.ui5.controls.common.feeds.FeedItem({

  uid: "primaryValues",

  type: "Measure",

  values: [new sap.viz.ui5.controls.common.feeds.AnalysisObject({

  uid: "Quantity_id",

  type: "Measure",

  name: "Quantity"

  })]

  }),

  feedAxisLabels = new sap.viz.ui5.controls.common.feeds.FeedItem({

  uid: "axisLabels",

  type: "Dimension",

  values: [new sap.viz.ui5.controls.common.feeds.AnalysisObject({

  uid: "Item_id",

  type: "Dimension",

  name: "Item"

  })]

  });

  //feedColor = new sap.viz.ui5.controls.common.feeds.FeedItem({

  //uid: "color",

  //type: "Measure",

  //values: "{VALUE}"

  //});

  oVizFrame.setVizProperties({

  valueAxis: {

  label: {

  formatString: "u"

  }

  },

  plotArea: {

  dataLabel: {

  visible: true

  //colorPalette:"{#00FF00,#FFC200,#FF0000,,#FFC200,#FF0000, #00FF00}"

  }

  },

  legend: {

  title: {

  visible: false

  }

  },

  title: {

  visible: true,

  text: "Value by Quantity and Item"

  }

  });

  oVizFrame.addFeed(feedPrimaryValues);

  oVizFrame.addFeed(feedAxisLabels);

  //oVizFrame.addFeed(feedColor);

  //oPopOver.connect(oVizFrame.getVizUid());

  if (sap.ui.Device.system.phone) {

  //Do not wait for the master when in mobile phone resolution

  this.oInitialLoadFinishedDeferred.resolve();

  } else {

  this.getView().setBusy(true);

  var oEventBus = this.getEventBus();

  oEventBus.subscribe("Component", "MetadataFailed", this.onMetadataFailed, this);

  oEventBus.subscribe("Master", "InitialLoadFinished", this.onMasterLoaded, this);

  }

  this.getRouter().attachRouteMatched(this.onRouteMatched, this);

  },

former_member182372
Active Contributor
0 Kudos

just attach it here. no need to send

Former Member
0 Kudos

Makim, do you any idea how to solve it by using XML view?

former_member182372
Active Contributor
0 Kudos

yes, i do

first of all I think you have to go through

SAPUI5 SDK - Demo Kit

second - in order to get help you need to provide at least symptoms and browser's dev tools log

Former Member
0 Kudos

Hi Maksim, i have went through the SAPUI5 SDK and may i know the screenshots that i attached are you needed?

former_member182372
Active Contributor
0 Kudos

In index.html :


<body id="content" class="sapUiBody" >

  </body>

Private_Member_15166
Active Contributor
0 Kudos

Hi Loh,

I was trying to work with SAP WebIde locally and XML.

I tried with your application.

First i created an app like this.

File->New->Project From Template

Then i selected this.

After that, i wrote this code in my view.

************** This was created by default****************

<core:View xmlns:core="sap.ui.core"

  xmlns:mvc="sap.ui.core.mvc"

  xmlns="sap.m"

******************************

xmlns:viz="sap.viz.ui5"// I Included this

************** This was created by default****************

controllerName="view.View1"

  xmlns:html="http://www.w3.org/1999/xhtml">

  <Page title="Bar Diagram">

  <content>

******************************

// I wrote this in my code

    <ScrollContainer height="100%" width="100%" horizontal="false" vertical="true" focusable="true">

        <viz:Bar id="idVizFrameBar" uiConfig="{applicationSet:'fiori'}" vizType="bar" width="100%" height="700px"></viz:Bar>

    </ScrollContainer>

// till here

  </content>

  </Page>

</core:View>

Then i wrote this code in my controller.

onInit: function() {

        var oVizFrame = this.getView().byId("idVizFrameBar");

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

            SOItems: [

                {

                    ITEM: "Tablet",

                    QUANTITY: 2067.45,

                    VALUE: 7373.99,

                    COLOR: "red"

                },

                {

                    ITEM: "Desktop",

                    QUANTITY: 3110.93,

                    VALUE: 9920.91,

                    COLOR: "green"

                },

                {

                    ITEM: "Mouse",

                    QUANTITY: 3003.97,

                    VALUE: 2058.64,

                    COLOR: "blue"

                },

                {

                    ITEM: "Modem",

                    QUANTITY: 6721.61,

                    VALUE: 9149.65,

                    COLOR: "purple"

                },

                {

                    ITEM: "Printer",

                    QUANTITY: 9636.25,

                    VALUE: 3752.46,

                    COLOR: "orange"

                },

                {

                    ITEM: "Ink",

                    QUANTITY: 9169.62,

                    VALUE: 9221.43,

                    COLOR: "yellow"

                }

        ]

        });

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

            dimensions: [{

                axis: 1,

                name: "Item",

                value: "{ITEM}"

            }],

            measures: [{

                    name: "Quantity",

                    value: "{QUANTITY}"

            },

                {

                    name: "Value",

                    value: "{VALUE}"

            }],

            data: {

                path: "/SOItems"

            }

        });

        oDataset.setModel(oModel);

        oVizFrame.setDataset(oDataset);

}

I kept index'html as as usual.

After this i got the  output.

Former Member
0 Kudos

Hi Maksim, i have added into it. The output is shown as below

Former Member
0 Kudos

Hi Dhananjay, sorry for late reply because i am suffering from the internet connection. Do you tried in the master detail application as i tried out at there. I will follow your way use the Application project and tried it out. I may wonder what is difference between the Application project and master detail application as you able to do it at there while i am not able to do it.

Former Member
0 Kudos

Hi Dhananjay, don't you add the code as below after function var oDataset = new sap.viz.ui5.data.FlattenedDataset?

var feedPrimaryValues = new sap.viz.ui5.controls.common.feeds.FeedItem({

  uid: "primaryValues",

  type: "Measure",

  values: [new sap.viz.ui5.controls.common.feeds.AnalysisObject({

  uid: "Quantity_id",

  type: "Measure",

  name: "Quantity"

  })]

  }),

  feedAxisLabels = new sap.viz.ui5.controls.common.feeds.FeedItem({

  uid: "axisLabels",

  type: "Dimension",

  values: [new sap.viz.ui5.controls.common.feeds.AnalysisObject({

  uid: "Item_id",

  type: "Dimension",

  name: "Item"

  })]

  }),

  feedColor = new sap.viz.ui5.controls.common.feeds.FeedItem({

  uid: "color",

  type: "Measure",

  values: "{VALUE}"

  });

  oVizFrame.setVizProperties({

  valueAxis: {

  label: {

  formatString: "u"

  }

  },

  plotArea: {

  dataLabel: {

  visible: true

  //colorPalette:"{#00FF00,#FFC200,#FF0000,,#FFC200,#FF0000, #00FF00}"

  }

  },

  legend: {

  title: {

  visible: false

  }

  },

  title: {

  visible: true,

  text: "Value by Quantity and Item"

  }

  });

  oVizFrame.addFeed(feedPrimaryValues);

  oVizFrame.addFeed(feedAxisLabels);

  oVizFrame.addFeed(feedColor);

  oPopOver.connect(oVizFrame.getVizUid());

Private_Member_15166
Active Contributor
0 Kudos

Hi Loh,

I Just created, what you want.

Create an SAPUI5 application project as i suggested earlier.

Don't do anything with index.html file which is auto generated.

This is code of view.

Code in Controller.

        var oVizFrame = this.getView().byId("idVizFrameBar");

        var oPopOver = this.getView().byId("idPopOver");

        var oModel = new sap.ui.model.json.JSONModel("https://sapui5.hana.ondemand.com/sdk/test-resources/sap/viz/demokit/dataset/bookstore_fiori/ByItemCi...");

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

            dimensions: [{

                name: "Item Category",

                value: "{Item Category}"

            }, {

                name: 'City',

                value: '{City}'

            }],

            measures: [{

                name: 'Revenue',

                value: '{Revenue}'

            }],

            data: {

                path: "/book"

            }

        });

        oVizFrame.setDataset(oDataset);

        oVizFrame.setModel(oModel);

        var feedValueAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({

                'uid': "valueAxis",

                'type': "Measure",

                'values': ["Revenue"]

            }),

            feedCategoryAxis = new sap.viz.ui5.controls.common.feeds.FeedItem({

                'uid': "categoryAxis",

                'type': "Dimension",

                'values': ["Item Category"]

            }),

            feedColor = new sap.viz.ui5.controls.common.feeds.FeedItem({

                'uid': "color",

                'type': "Dimension",

                'values': ["City"]

            });

        oVizFrame.setVizProperties({

            valueAxis: {

                label: {

                    formatString: 'u'

                }

            },

            plotArea: {

                dataLabel: {

                    visible: true,

                    formatString: "#,##0"

                }

            },

            legend: {

                title: {

                    visible: false

                }

            },

            title: {

                visible: true,

                text: 'Revenue by City and Item Category'

            }

        });

        oVizFrame.addFeed(feedValueAxis);

        oVizFrame.addFeed(feedCategoryAxis);

        oVizFrame.addFeed(feedColor);

        oPopOver.connect(oVizFrame.getVizUid());

This has been written in onInit method and it's working.

First check if this is working in your application and then change the data.

Your Model data is also incomplete for such types of Bar diagram.

Refer this link https://sapui5.hana.ondemand.com/sdk/test-resources/sap/viz/demokit/dataset/bookstore_fiori/ByItemCi...  for your better understanding and see how this has been used in SAPUI5 Explored.

Regards

Dhananjay

former_member182372
Active Contributor
0 Kudos

really, it is getting ridiculous, just zip that damn project and attach to thread

and again, you have to get back to school, you missing basic concepts

Former Member
0 Kudos

Hi Dhananjay, really thanks for helping, glad to have you help to solve the problems. I feel very excited after managed to display the bar chart. I got 2 simple questions wish to ask you after i am managed to display the bar:

1st : How to change the bar color? Is it we have to insert

//colorPalette:"{#00FF00,#FFC200,#FF0000,,#FFC200,#FF0000, #00FF00}" in the plotArea there?

if yes, where can i find all the color code so that i can put the c.olor code that i wish to display?

2nd: In the code below i found that when i changed the "u" to another alphabet (let say alphabet a), the x-axis will "a" instead of value. I feel wonder why it is like that

oVizFrame.setVizProperties({

  valueAxis: {

  label: {

  formatString: "u"

  }

  },

I attached the screenshot for you to refer

if 'u' replaced by zero

if 'u' replaced by 'a'

3) How to set the value on x-axis?

Dhananjay, thanks so much and welcomed shared with me in case you know it.

Regards,

Loh

Private_Member_15166
Active Contributor
0 Kudos

Hi Loh,

This is answer for your first question.

From this link you may get the color hexadecimal codes.

HTML Color Picker

We have three bars so we need 3 different colors.

Now in your onInit method write this line. oVizFrame.addFeed(feedValueAxis);

This is the code you need to insert.

var scales = [{

     'feed': 'color',

     'palette': ['#004C4C', '#99003D','#33801A']

}];

        oVizFrame.setVizScales(scales);

You may also set conditional colors.

Refer this link.

SAPUI5 Explored

Regards

Dhananjay

Private_Member_15166
Active Contributor
0 Kudos

For formatString refer this and try to collect info from google. JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.viz.ui5.types.Datalabel

Private_Member_15166
Active Contributor
0 Kudos

This is for your third question.

Former Member
0 Kudos

Hi Dhananjay, according graph i shown , the value on x-axis is 0, 100K, 200K and so on ,which means the interval value is 100K. Is it possible we make it such as 0, 200K, 400K and so on on x-axis?

Private_Member_15166
Active Contributor
0 Kudos

Hi Loh,

Use like this.

        oVizFrame.setVizProperties({

            valueAxis: {

                label: {

                    formatString: 'u'

                }

            },

            plotArea: {

                dataLabel: {

                    visible: true,

                    formatString: "#,##0"

                }

            },

            legend: {

                title: {

                    visible: false

                }

            },

            title: {

                visible: true,

                text: 'Revenue by City and Item Category'

            },

                yAxis : {

                        scale: {

                                  fixedRange : true,

                                  minValue : 0,

                                  maxValue : 1400000

                        }

                }

              

        });

Add the code written in bold if this is of type column bar chart.

Regards

Dhananjay

Former Member
0 Kudos

Thanks Dhananjay, you are so great and solved all my problems. Just one question for you again, sorry for annoying, if we do not set the color and set the range of scale, that meant it set the default range of scale and color for the bar chart?

Private_Member_15166
Active Contributor
0 Kudos

Yes, Exactly Loh.

On SCN we just need appreciation, we annoy only when not appreciated.

Former Member
0 Kudos

Dear Dhananjay,

i feel wonder why you chose the application project when you created new project? In other template such as full-screen and master-detail screen also can be do it in the same way as in application project, right?

I am super appreciated and grateful to your help. You have guided me from A to Z, and this post definitely very helpful to all new beginners. Once again, sincerely thanks to you for spending so much time with my questions. I will post a new question in forum soon regarding how to dynamically change the graph by pressing different buttons as here seems not suitable to continue ask the my question which is not related to the this question title, hope you will join too in my next new question.

Private_Member_15166
Active Contributor
0 Kudos

Hi Loh,

It can be also used in Master/Detail Fiori App. Basically this Master/Detail is also being created by the same as i suggested.

I will give a try for the same.

Regards

Dhananjay

Former Member
0 Kudos

Hi Dhananjay,

Okay, thanks so much

I have created new discussion on that i faced, if you have any idea welcome to suggests solutions to me.

Regards,

Loh

Answers (0)