We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Bar chart data labels and gap width not working in Java

Hi
Even though I set gap width and data labels position its not working.
The below is the code I have, I have added some extra format like fill color etc while trying to make it work but its still not working.

private void getEIBarChart(Object... arguments) {
        ISlide chartSlide = (ISlide)arguments[0];
        IChart clusterdBar = chartSlide.getShapes().addChart(ChartType.ClusteredBar, (Integer)arguments[1], (Integer)arguments[2], (Integer)arguments[3], (Integer)arguments[4]);
        IChartData clusteredBarChartData = clusterdBar.getChartData();
        clusteredBarChartData.getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);
        IChartDataWorkbook fact = clusteredBarChartData.getChartDataWorkbook();

        IAxesManager clusteredBarAxes = clusterdBar.getChart().getAxes();
        clusteredBarAxes.getVerticalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
        clusteredBarAxes.getHorizontalAxis().getMajorGridLinesFormat().getLine().getFillFormat().setFillType(FillType.NoFill);
        clusteredBarAxes.getHorizontalAxis().setVisible(false);
        //clusteredBarAxes.getVerticalAxis().setVisible(false);
        clusterdBar.getChart().setLegend(false);
        

        clusteredBarChartData.getSeries().clear();
        clusteredBarChartData.getCategories().clear();

        //basically a powerpoint chart format is so
        /*
            0,0     "Series1"     "Series2"
            Cat1    Series1D1   Series2D1
            Cat2    Series1D2   Series2D2

            Eg:
              0/0      "Series1"   "Series2"
            MenCount    10          20
            WomenCount  5           15
         */

        //appears getCell(x, y, z, q) refers to x - worksheet, y - row, z - column, q - value to set there.
        clusteredBarChartData.getSeries().add(fact.getCell(0, 0, 1, "EI"), clusterdBar.getType());

        clusteredBarChartData.getCategories().add(fact.getCell(0, 1, 0, "E"));
        clusteredBarChartData.getCategories().add(fact.getCell(0, 2, 0, "NE"));
        clusteredBarChartData.getCategories().add(fact.getCell(0, 3, 0, "AD"));

        IChartSeries eiSeries = clusteredBarChartData.getSeries().get_Item(0);
        IChartDataPointCollection eiSeriesDataPoints = eiSeries.getDataPoints();
        eiSeriesDataPoints.addDataPointForBarSeries(fact.getCell(0, 1, 1, arguments[5]));
        eiSeriesDataPoints.addDataPointForBarSeries(fact.getCell(0, 2, 1, arguments[6]));
        eiSeriesDataPoints.addDataPointForBarSeries(fact.getCell(0, 3, 1, arguments[7]));

        clusteredBarChartData.getSeriesGroups().get_Item(0).setOverlap((byte)100);
        clusterdBar.getChart().getChartData().getSeriesGroups().get_Item(0).setGapWidth(50);
            
 clusterdBar.getChart().getChartData().getSeries().get_Item(0).getParentSeriesGroup().setGapWidth(50);
                //clusteredBarChartData.getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true);
                clusteredBarChartData.getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setPosition(LegendDataLabelPosition.OutsideEnd);
                clusteredBarChartData.getSeries().get_Item(0).getParentSeriesGroup().get_Item(0).getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().setFontHeight(50);
                clusteredBarChartData.getSeries().get_Item(0).getParentSeriesGroup().get_Item(0).getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().setFillType(FillType.Solid);
                clusteredBarChartData.getSeries().get_Item(0).getParentSeriesGroup().get_Item(0).getLabels().getDefaultDataLabelFormat().getTextFormat().getPortionFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);
    }

Not sure how but it got fixed, will recheck and update on which exact statement fixed it.

@wishy.em,

We are glad to know that things are working fine on your end. Please share your feedback with us if there is still an issue.

Best Regards,

Adnan Ahmad