Skip to Content
Author's profile photo Gopal Anand

Filtering oData in Viz-Chart

Hello guys,

I was working with  line-chart. While creating the chart i wanted to use filters. I tried lot of techniques and found this way to solve the Filtering issue.

Point to be noted is that you need to bind the Dataset of VizFrame by its ID and then apply the filtering on the FlattenedDataset

Here is the code how I used it

In controller:

	
// defining the Filter
var	oFilter = new sap.ui.model.Filter("Data1",sap.ui.model.FilterOperator.GT,10);
//Setting oModel
			var oModel = new sap.ui.model.odata.ODataModel("/destinations/v4/abc/http/app.svc", oConfig);
			 this.getView().setModel(oModel);
//Binding the filtered data to the chart by callind it from its ID and binding the data there 
			this.getView().byId("idVizFrame").getDataset().getBinding("data").filter([oFilter]);
	    			

The XML part Will be Like this:

	<viz:VizFrame id="idVizFrame" uiConfig="{applicationSet:'fiori'}" height='100%' width="100%" vizType='line' >	
		<viz:dataset>    
			<viz.data:FlattenedDataset data="{/YOUR_ENTITY_SET}">
				<viz.data:dimensions>
					<viz.data:DimensionDefinition name="TimeStamp" value="{TimeStamp}"
					/>
				</viz.data:dimensions>
				<viz.data:measures>
					<viz.data:MeasureDefinition name="SENSOR1" value="{SENSOR1}"/>
				</viz.data:measures>
			</viz.data:FlattenedDataset>
		</viz:dataset>
		<viz:feeds>
			<viz.feeds:FeedItem id='valueAxisFeed' uid="valueAxis" type="Measure" values="Data_SENSOR1"/>
			<viz.feeds:FeedItem id='categoryAxisFeed' uid="categoryAxis" type="Dimension" values="TimeStamp"/>
		</viz:feeds>
	</viz:VizFrame>

Hope you can solve any filtering issue in viz-charts using this .

Thanks
Gopal Anand

Assigned tags

      3 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo B. van de Kamp
      B. van de Kamp

      Thanks Gopal for sharing your knowledge, just wanted to inform you that it helped me! Greetings from Netherlands.

      Author's profile photo Former Member
      Former Member

      Thanks Gopal for this cute example. Helped me a lot!

      Greetings from Switzerland 😉

      Author's profile photo Chirag Poddar
      Chirag Poddar

      Hi Gopal,

      Thanks for the example. However, you can simply add the filter in the xml like below as well.

       

      <viz:VizFrame id="idVizFrame" uiConfig="{applicationSet:'fiori'}" height='100%' width="100%" vizType='line' >	
      		<viz:dataset>    
      			<viz.data:FlattenedDataset data="{ path: /YOUR_ENTITY_SET, 
                                                                 filters: [{
      		                                                       path: 'Data1',				            
                                                                             operator: 'GT',								          
                                                                             value1: 10											        	 
                                                                          }]
                                                               }">
      				<viz.data:dimensions>
      					<viz.data:DimensionDefinition name="TimeStamp" value="{TimeStamp}"
      					/>
      				</viz.data:dimensions>
      				<viz.data:measures>
      					<viz.data:MeasureDefinition name="SENSOR1" value="{SENSOR1}"/>
      				</viz.data:measures>
      			</viz.data:FlattenedDataset>
      		</viz:dataset>
      		<viz:feeds>
      			<viz.feeds:FeedItem id='valueAxisFeed' uid="valueAxis" type="Measure" values="Data_SENSOR1"/>
      			<viz.feeds:FeedItem id='categoryAxisFeed' uid="categoryAxis" type="Dimension" values="TimeStamp"/>
      		</viz:feeds>
      	</viz:VizFrame>