Technology Blogs by SAP
Learn how to extend and personalize SAP applications. Follow the SAP technology blog for insights into SAP BTP, ABAP, SAP Analytics Cloud, SAP HANA, and more.
cancel
Showing results for 
Search instead for 
Did you mean: 
317
Recently a person asked me if they could change the x-axis date resolution depending on what level of the date hierarchy that they were using.

 

For example, if month is the hierarchy level, then they want to see days on the axis:


If quarter is the hierarchy level, then they want to see months on the axis:


In this example, we are using Order_Date as the time dimension.

 

The first thing to do is to define a hierarchy on the Order_Date dimension. This Order_Date has All-Year-Quarter-Month-Day.

Month

Then in code to set the chart to show a month with day resolution, we use the following code:
// Month View with Day Resolution
var range = TimeRange.createMonthRange(2016, 1, 2016, 1);
chrtTest.getDataSource().setHierarchy("Order_Date",Alias.FlatHierarchy);
chrtTest.getDataSource().setDimensionFilter("Order_Date",range);

This code flattens the hierarchy to show the lowest resolution, which is day. It then filters the chart to the month of January 2016.

Quarter

Below is the code for the quarter view:
// Quarter View with Month Resolution
var range = TimeRange.createMonthRange(2016, 1, 2016, 3);
chrtTest.getDataSource().setHierarchy("Order_Date", "YQM");
chrtTest.getDataSource().setHierarchyLevel("Order_Date", 4);
chrtTest.getDataSource().setDimensionFilter("Order_Date",range);

This code collapses hierarchy and then sets it to level 4, which is Month. It then filters the chart to the first three months of 2016.

By using hierarchies and dimension filters, we are able to show the time ranges of interest at the desired hierarchy and axis resolution.