sapui5 - Pie chart not showing data correctly -
sapui5 - Pie chart not showing data correctly -
my info model:
{ "userdata": { "firstname": "pieter" "history": [ { "clientid": 2, "distance": "130" }, { "client": 3, "distance": "300" } , { "client": 4, "distance": "430" } ] } }
view
<content> <viz:ui5.pie> <viz:dataset> <viz:ui5.data.flatteneddataset data="{/userdata/clockhistory}"> <viz:dimensions> <viz:ui5.data.dimensiondefinition axis="1" name="client" value="{clientid}"> </viz:ui5.data.dimensiondefinition> </viz:dimensions> <viz:measures> <viz:ui5.data.measuredefinition name="distance" value="{distance}"> </viz:ui5.data.measuredefinition> </viz:measures> </viz:ui5.data.flatteneddataset> </viz:dataset> </viz:ui5.pie> </content>
i expecting 3 pieces in pie size depending on distance values. different result:
if have multiple items in array of same client id, pie chart automatically grouping clients , add together distances?
first, json format somehow not consistent, client should clientid, , binding path flatteneddataset should {/userdata/history}
instead of {/userdata/clockhistory}
{ "userdata": { "firstname": "pieter" "history": [ { "clientid": 2, "distance": "130" }, { "clientid": 3, "distance": "300" } , { "clientid": 4, "distance": "430" } ] } }
second, pie chart not automatically grouping clients , add together distances same clientid.
please run , check code snippet details.
class="snippet-code-html lang-html prettyprint-override"><script src="https://sapui5.hana.ondemand.com/resources/sap-ui-core.js" id="sap-ui-bootstrap" data-sap-ui-theme="sap_bluecrystal" data-sap-ui-libs="sap.m,sap.ui.commons,sap.viz"></script> <script id="view1" type="sapui5/xmlview"> <mvc:view xmlns:core="sap.ui.core" xmlns:layout="sap.ui.commons.layout" xmlns:mvc="sap.ui.core.mvc" xmlns:viz="sap.viz" xmlns="sap.ui.commons" controllername="my.own.controller" xmlns:html="http://www.w3.org/1999/xhtml"> <layout:verticallayout id="vl"> <layout:content> <viz:ui5.pie id="samplepie"> <viz:dataset> <viz:ui5.data.flatteneddataset data="{/userdata/history}"> <viz:dimensions> <viz:ui5.data.dimensiondefinition axis="1" name="client" value="{clientid}"> </viz:ui5.data.dimensiondefinition> </viz:dimensions> <viz:measures> <viz:ui5.data.measuredefinition name="distance" value="{distance}"> </viz:ui5.data.measuredefinition> </viz:measures> </viz:ui5.data.flatteneddataset> </viz:dataset> </viz:ui5.pie> </layout:content> </layout:verticallayout> </mvc:view> </script> <script> sap.ui.controller("my.own.controller", { oninit: function() { var info = { "userdata": { "firstname": "pieter", "history": [{ "clientid": 2, "distance": "130" }, { "clientid": 3, "distance": "300" }, { "clientid": 4, "distance": "430" } ] } }; var omodel = new sap.ui.model.json.jsonmodel(); omodel.setdata(data); this.getview().byid("samplepie").setmodel(omodel); } }); var myview = sap.ui.xmlview("myview", { viewcontent: jquery('#view1').html() }); // myview.placeat('content'); </script> <body class='sapuibody'> <div id='content'></div> </body>
sapui5
Comments
Post a Comment