Charts 4.1.0: X-Axis Categories Do Adjust According To Drilldown Level

I have a 3-level drilldown bar chart that has already been implemented, but currently facing a stumbling block on the x-axis categories not adjusting according to the category values that were defined in code.

These are the categories defined for the following levels:

  • Level 1 - “Combo / Set”, “Ala Carte” (only 2 categories, objective is to show the entire collective total)
  • Level 2 - “Combo 1”, “Combo 2”, “Combo n”… (depending on the number of set items, drilldown upon clicking “Combo / Set” at Level 1)
  • Level 3 - “Outlet 1”, “Outlet 2” to “Outlet N” (depending on the number of outlets found in dataset, drilldown upon clikcing “Combo #x”)

Level 1’s object has only two attributes / properties, while Level 2 and 3 objects have about five attributes / properties each.
My code was also partially based on the sample code that was shown in the demo (refer [here]
(https://demo.vaadin.com/charts/#ColumnWithMultiLevelDrilldown)) and I am using Charts 4.1.0 for this work.

What happened was:

  • a) If I use setXCategories, only Level 1 category values are shown at all levels.
  • b) Not using setXCategories would result in numerical values starting with 0 to n being used as category on X-Axis

Currently, the code to display the breakdown is as:


           DataSeriesItem totalSetItem = new DataSeriesItem("Combo Set",comboCount);
           DataSeriesItem individualItem = new DataSeriesItem("Ala Carte",individualCount);
           //chart.getConfiguration().getxAxis().setCategories("Combo Set","Ala Carte");
           
           DataSeries breakSeries = new DataSeries("Breakdown");
           breakSeries.setId("Breakdown");
           breakSeries.setPlotOptions(plotOptionsColumn);
           
		   -- Series is Level 1 DataSeries
           series.setPlotOptions(plotOptionsColumn);
           series.addItemWithDrilldown(totalSetItem,breakSeries);
           series.add(individualItem);
           
           //BEGIN - for Level 2 data
           Map<String, ComboTotalDetailMetric> metricMap = new HashMap<>();
           collectiveSalesList.forEach((comboMetric) -> {
               ComboTotalDetailMetric currentMetric = metricMap.get(comboMetric.getParentItem());
               if(currentMetric == null){
                   metricMap.put(comboMetric.getParentItem(), comboMetric);
               }else{
                   currentMetric.setItemQuantity(currentMetric.getItemQuantity() + comboMetric.getItemQuantity());
               }
            });
           -- breakSeries is dataSeries for Level 2 
           Collection<ComboTotalDetailMetric> newList = metricMap.values();
           newList.forEach((derivedNew) -> {
               DataSeriesItem setSeriesItem = new DataSeriesItem(derivedNew.getParentItem(),derivedNew.getItemQuantity());
               setSeriesItem.setId(derivedNew.getParentItem());
               //chart.getConfiguration().getxAxis().addCategory(derivedNew.getParentItem());
               if(derivedNew.getParentItemFlag().equalsIgnoreCase("N")){
                   breakSeries.add(setSeriesItem); 
              }else{
                   //This is for level 3
                   DataSeries outletSeries = new DataSeries("Outlet");
                   for(ComboTotalDetailMetric outletMetric : collectiveSalesList){ 
                       if(outletMetric.getParentItemFlag().equalsIgnoreCase("Y") 
                                && outletMetric.getParentItem().equals(derivedNew.getParentItem()) 
                                    && outletMetric.getItemQuantity() > 0){
                                        outletSeries.setId(outletMetric.getOutletName());
                                        DataSeriesItem outletSeriesItem = new DataSeriesItem(outletMetric.getOutletName(),outletMetric.getItemQuantity());
                                        //chart.getConfiguration().getxAxis().addCategory(outletMetric.getOutletName());
                                        outletSeries.add(outletSeriesItem);
                       }
                    }
                    breakSeries.addItemWithDrilldown(setSeriesItem,outletSeries);
                    
               }
            }); //END - for Level 2 data
           
           
           chart.getConfiguration().addSeries(series);

According to an earlier forum question, to have that work, I should not be explicitly specifying this line x.setType(AxisType.CATEGORY) as it was said I will need a consistent number of categories across all levels. I am not sure this is still correct or not as that was in Charts 2 / 3. If still remains true:

  • a) Do I have to use setCategories for each level?
  • b) If setCategories is not appropriate, how can I dynamically change the x-axis categories information when drilldown to lower levels?