Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Filtering Data Feed for Viz Bar Chart

Hello Everyone,

I am having trouble getting data to display in a bar chart so that it can be filtered by country.  If I could figure out how to get the bar chart to show the data for one country at a time I should be able to create a way for users to select which country they want to see.

Here is a screen shot of how the bar chart looks now. Notice how there are 4 bars overlapping for each year. Is it possible to filter the data into the chart without changing the data format (json)?

Here is the json data

{

  "Annual_Growth_Rates" : [

   {"country" : "Europe", "year" : 2012, "percent" : 4.31},

   {"country" : "Europe", "year" : 2013, "percent" : 3.99},

   {"country" : "Europe", "year" : 2014, "percent" : 4.16},

   {"country" : "Europe", "year" : 2015, "percent" : 4.02},

   {"country" : "Europe", "year" : 2016, "percent" : 3.98},

   

   {"country" : "China", "year" : 2012, "percent" : 11.33},

   {"country" : "China", "year" : 2013, "percent" : 3.74},

   {"country" : "China", "year" : 2014, "percent" : 3.48},

   {"country" : "China", "year" : 2015, "percent" : 1.9},

   {"country" : "China", "year" : 2016, "percent" : 2.44},

   {"country" : "US", "year" : 2012, "percent" : 28.07},

   {"country" : "US", "year" : 2013, "percent" : 15.48},

   {"country" : "US", "year" : 2014, "percent" : 15.83},

   {"country" : "US", "year" : 2015, "percent" : 16.11},

   {"country" : "US", "year" : 2016, "percent" : 17.14},

  

   {"country" : "Other", "year" : 2012, "percent" : 12.42},

   {"country" : "Other", "year" : 2013, "percent" : 6.94},

   {"country" : "Other", "year" : 2014, "percent" : 6.95},

   {"country" : "Other", "year" : 2015, "percent" : 7.31},

   {"country" : "Other", "year" : 2016, "percent" : 7.24}

  

  ]

}

And here is my viz chart code.

vizFrame = this.getView().byId("vizFrame");

growthRatesDataSet = new sap.viz.ui5.data.FlattenedDataset({

  dimensions: [

     {name: 'year', value: "{year}"}

  ],

  measures: [

     {name: "percent", value: "{percent}"}

  ],

  data: {path: "/Annual_Growth_Rates"}

  });

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

  'uid' : "primaryValues",

  'type' : "Measure",

  'values' : ["percent"]

  });

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

  'uid' : "axisLabels",

  'type' : "Dimension",

  'values' : ["year"]

  });

//set vizFrame properties

  vizFrame.setVizProperties({

       plotArea : {

            dataLabel : {visible : true},

            isFixedDataPointSize : true

       },

       legend : {

            title: {visible : false}

       },

       title: {

            visible: true,

            text: 'Growth Rates'

       }

  });

vizFrame.setDataset(growthRatesDataSet);

vizFrame.setModel(growthRatesModel);

vizFrame.addFeed(growthRatesFeedPrimary);

vizFrame.addFeed(growthRatesFeedAxis);

Thanks in advance for any solutions proposed!

Tags:
Former Member
Not what you were looking for? Ask a question