How to adjust the chart's plot area height to fully occupy the chart's chart area height

Hi Team,

I’m creating a Bar chart in a single column but multiple rows.
In the output could see that the plot area is not completely occupied till the chart’s height.

image.png (1.4 KB)
In this image if we see there is some gap between the chart area and the plot are.

This happened when the below property is set :
chart.getPlotArea().setAutomaticSize(true);

But when the property is changed to false then the plot area started at the left and top of the chart area and there is some space in the bottom and right.

image.png (1.2 KB)

How to adjust the plot area height dynamically to occupy the complete height of chart area height ?

Attaching the input excel, sample code and the generated outputs for (plot area automatic size false and true).

Note : Tested this with aspose cells : 21.5 version

Thanks in advance,
Sanjeev

Chart_PlotArea_Height_Adjustment.zip (19.2 KB)

@sanjeevkumarambti,

Please try the following lines of code (in bold) to be added (to your code segment) to accomplish your task. I have tested and it works as expected. Please note, total (maximum) area is 4000 units, so you got to extend its height and width to it.
e.g.
Sample code:


chart.getCategoryAxis().getAxisLine().setWeightPx(2);
chart.getCategoryAxis().getAxisLine().setColor(com.aspose.cells.Color.getBlack());
chart.getCategoryAxis().setMajorTickMark(TickMarkType.NONE);
chart.getCategoryAxis().setTickLabelPosition(TickLabelPositionType.NONE);

chart.setShowLegend(false);

chart.getPlotArea().setX(0);
chart.getPlotArea().setY(0);
chart.getPlotArea().setWidth(4000);
chart.getPlotArea().setHeight(4000);

Hope, this helps a bit.

Thanks Amjad,

The fix suggested is working fine.

Have one more question : sometimes the data labels are getting overlapped with the bar.
DataLabels position is : Outside End

image.png (725 Bytes)

Is there any property we can use to avoid data label overlap with bar ?

Thanks in advance,
Sanjeev

@sanjeevkumarambti,

I am not sure if there is some option/way to cope with it in MS Excel. Could you share your template Excel file containing two sheets, one with your output chart (having overlapped data labels) by Aspose.Cells and other with your desired chart having data labels in order. Also give details on option(s) with screenshot(s) and steps on how to accomplish the task in MS Excel, we can check it soon.