Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 3316

How to use a CustomDataset for a PieChart inside a VizFrame?

$
0
0

Does anyone know how to use a CustomDataset for a PieChart inside a VizFrame?

I have some weird findings after some research, for details see below...

 

I know how to create a PieChart using a sap.viz.ui5.controls.VizFrame in combination with a sap.viz.ui.data.FlattenedDataset. The Explored app has a simple example using a sap.viz.ui.data.FlattenedDataset and I can reproduce it. However, I have an OData backend that gives me the data in a specific format which does not allow me to use the FlattenedDataset. Currently we have a workaround that executes an OData read and takes the response data in order to create a specific view model that is referenced in our XMLView using data binding expressions in the XMLView. That works perfectly, but I feel there must be a better way to do this...

 

Now I found the dataset aggregation of the VizFrame has the abstract typesap.viz.ui5.data.Dataset, and this abstract type has two implementations:

  1. sap.viz.ui.data.FlattenedDataset
  2. sap.viz.ui5.data.CustomDataset

 

The sap.viz.ui5.data.CustomDataset sounds exactly like what I want. So I started searching on the web. Guess what: there is not even a single example using the CustomDataset! Not even in the SDK, testsuite, and nowhere else. But maybe I'm just too stupid too google. I agree with Michael Klopf (see here)! The documentation of anything related to the VizFrame (including the CustomDataset and the FlattenedDataset) has always been horrible.


So the big question is: how do I use the CustomDataset to draw a PieChart using the VizFrame?

 

In the CustomDataset api for getData there is one interesting hint: "Data containing dimensions and measures. The format and structure of this data is depends on the chart."

 

That hint is very interesting, but is does not help at all as it does not tell me how or where to find the relevant information. I have checked the VizDocs aka CVON Visualization docs , but there is absolutely no relevant information to find.

 

Of course, I have tried out a few more things. I have also debugged the VizFrame itself to find out how to use the CustomDataset. Unfortunately, there is no hint in the code related to the CustomDatset. So I had to go with "trial and error":

 

 

<viz:VizFrame     id="myVizFrame"     uiConfig="{applicationSet:'fiori'}"     vizType="pie"     height="100%"     width="100%">         <viz:dataset>          <viz.data:CustomDataset               data="{                    path : '/MyEntity(...)',                    formatter : '.formatData'               }" />     </viz:dataset>                                            <viz:feeds>          <viz.feeds:FeedItem               uid="size"               type="Measure"               values="Revenue" />          <viz.feeds:FeedItem               uid="color"               type="Dimension"               values="Categories" />      </viz:feeds></viz:VizFrame>

 

The formatter in the controller should actually return the data in the correct format so that it can be visualized by the VizFrame as a PieChart (well, I don't know the right format, see above...). Interestingly, this code helped me to find something that looks like a bug in the VizFrame implementation:

 

VizFrame-in-debugger.png

 

As you can see in the screenshot, the dataset is a sap.viz.ui5.data.CustomDataset. However, in the VizFrame code there is an explicit call to the function ds.getVIZFlatDataSet(). This (by the way undocumented/private API) only works for sap.viz.ui5.data.FlattenedDataset, but not for sap.viz.ui5.data.CustomDataset! That's why I always get an error here... On the other side, according to the VizFrame API the dataset aggregation must be anything extending sap.viz.ui5.data.Dataset, so it must also work with an sap.viz.ui5.data.CustomDataset - but it does not as you can see in the screenshot above!

 

Any idea? Doesn't this look like a bug? And how can I use the CustomDataset?

 

 

Thanks, Nabi


Viewing all articles
Browse latest Browse all 3316

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>