Bubble Сhart: Vertical and Horizontal Axis Auto Unit and Bounds

Hi Team,

I am trying to create bubble chart for the below values

Series X-Values Y-Values Size
Product A -8.88 0 100
Product B -6.884 0.916 42.719
Product C -2.184 0.117 1.702
Product D -8.309 0.003 0.423
Product E -15.216 -0.023 0.309
Product F -74.517 -0.002 0

So I am expecting bubble chart with 6 series with auto min/max bounds and auto major and minor units.

If I do it manually in ppt, I am getting the ppt with axisOptions as below

image.png (93.4 KB)

But if I try to acheive the same via Aspose simple program, I am seeing different units and bounds.

image.png (133.1 KB)

Also I am trying to provide a percent format for horizontal axis and Number format for vertical axis with 1 decimal place, but percent and number format is getting mixed up between vertical and horizontal axes and 1 decimal place is not coming up.

Could you please help me with the change in lines of code which would give the ppt which I have manually created?

Note : Please ignore the color of bubbles.

I am attacing the code snippet along with ppt files generated manually and programmatically for your reference →
BubbleChartIssue.zip (72.4 KB)

Please check and let me know if you need any further info.

Thanks,
Thilak Babu

@Thilakbabu,
Thank you for describing the issue.

We have opened the following new ticket(s) in our internal issue tracking system and will consider your request according to the terms mentioned in Free Support Policies.

Issue ID(s): SLIDESJAVA-39622

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi @andrey.potapov ,

Please keep me posted once you have some update on this issue.

@Thilakbabu,
Please try using the following code example:

Presentation presentation = new Presentation();

presentation.getSlideSize().setSize(SlideSizeType.Widescreen, SlideSizeScaleType.DoNotScale);

// Create a slide to add the chart
ISlide slide = presentation.getSlides().get_Item(0);

// Add a Bubble chart to the slide
IChart chart = slide.getShapes().addChart(ChartType.Bubble, 150, 70, 650, 400);

chart.setTitle(false);

chart.getLineFormat().getFillFormat().setFillType(FillType.Solid);
chart.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

chart.getPlotArea().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
chart.getPlotArea().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(12);
chart.getLegend().getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));

// Get the chart's data sheet
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();

// Clear the default data
chart.getChartData().getSeries().clear();

// Create the first (and only) series for the chart
//    Series  X-Values    Y-Values    Size
//    Product A   -8.88   0   100
//    Product B   -6.884  0.916   42.719
//    Product C   -2.184  0.117   1.702
//    Product D   -8.309  0.003   0.423
//    Product E   -15.216 -0.023  0.309
//    Product F   -74.517 -0.002  0

//getCell(int worksheetIndex, int row, int column, Object value)


IChartSeries seriesA = chart.getChartData().getSeries().add(workbook.getCell(0, 0, 0, "Product A"), ChartType.Bubble);
IChartDataPoint dpA = seriesA.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 0, 1, -8.88),
        workbook.getCell(0, 0, 2, 0),
        workbook.getCell(0, 0, 3, 100));
seriesA.getFormat().getFill().setFillType(FillType.Solid);
seriesA.getFormat().getFill().getSolidFillColor().setColor(new Color(233, 113, 50));

IChartSeries seriesB = chart.getChartData().getSeries().add(workbook.getCell(0, 2, 0, "Product B"), ChartType.Bubble);
IChartDataPoint dpB = seriesB.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 2, 1, -6.884),
        workbook.getCell(0, 2, 2, 0.916),
        workbook.getCell(0, 2, 3, 42.719));
seriesB.getFormat().getFill().setFillType(FillType.Solid);
seriesB.getFormat().getFill().getSolidFillColor().setColor(new Color(78, 167, 46));

IChartSeries seriesC = chart.getChartData().getSeries().add(workbook.getCell(0, 3, 0, "Product C"), ChartType.Bubble);
IChartDataPoint dpC = seriesC.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 3, 1, -2.184),
        workbook.getCell(0, 3, 2, 0.117),
        workbook.getCell(0, 3, 3, 1.702));
seriesC.getFormat().getFill().setFillType(FillType.Solid);
seriesC.getFormat().getFill().getSolidFillColor().setColor(new Color(25, 107, 36));

IChartSeries seriesD = chart.getChartData().getSeries().add(workbook.getCell(0, 4, 0, "Product D"), ChartType.Bubble);
IChartDataPoint dpD = seriesD.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 4, 1, -8.309),
        workbook.getCell(0, 4, 2, 0.003),
        workbook.getCell(0, 4, 3, 0.423));
seriesD.getFormat().getFill().setFillType(FillType.Solid);
seriesD.getFormat().getFill().getSolidFillColor().setColor(new Color(15, 158, 213));

IChartSeries seriesE = chart.getChartData().getSeries().add(workbook.getCell(0, 5, 0, "Product E"), ChartType.Bubble);
IChartDataPoint dpE = seriesE.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 5, 1, -15.216),
        workbook.getCell(0, 5, 2, -0.023),
        workbook.getCell(0, 5, 3, 0.309));
seriesE.getFormat().getFill().setFillType(FillType.Solid);
seriesE.getFormat().getFill().getSolidFillColor().setColor(new Color(160, 43, 147));

IChartSeries seriesF = chart.getChartData().getSeries().add(workbook.getCell(0, 6, 0, "Product F"), ChartType.Bubble);
IChartDataPoint dpF = seriesF.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 6, 1, -74.517),
        workbook.getCell(0, 6, 2, -0.0),
        workbook.getCell(0, 6, 3, 0));
seriesF.getFormat().getFill().setFillType(FillType.Solid);
seriesF.getFormat().getFill().getSolidFillColor().setColor(new Color(21, 93, 130));

for (int i = 1; i < 7; i++) {
    setPercentFormat(workbook, i);
    setNumberFormat(workbook, i);
}

IChartLinesFormat gridLineFormat = chart.getAxes().getVerticalAxis().getMajorGridLinesFormat();
gridLineFormat.getLine().getFillFormat().setFillType(FillType.NoFill);


IAxis verticalAxis = chart.getAxes().getVerticalAxis();
verticalAxis.getFormat().getLine().setWidth(2);
verticalAxis.setCrossType(CrossesType.Custom);
verticalAxis.setCrossAt(0.0f);

verticalAxis.setTickLabelPosition(1);
verticalAxis.setMajorTickMark(TickMarkType.None);

verticalAxis.setCategoryAxisType(0);
verticalAxis.setNumberFormat("0.0");

verticalAxis.setAutomaticMinValue(false);
verticalAxis.setMinValue(-0.2);

verticalAxis.setAutomaticMaxValue(false);
verticalAxis.setMaxValue(1.2);

verticalAxis.setAutomaticMinValue(true);
verticalAxis.setAutomaticMaxValue(true);

verticalAxis.getTextFormat().getPortionFormat().setFontHeight(12);
verticalAxis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));

IAxis horizontalAxis = chart.getAxes().getHorizontalAxis();
horizontalAxis.getFormat().getLine().setWidth(2);
horizontalAxis.setCrossType(CrossesType.Custom);
horizontalAxis.setCrossAt(0.0f);

horizontalAxis.setTickLabelPosition(1);
horizontalAxis.setMajorTickMark(TickMarkType.None);

horizontalAxis.setCategoryAxisType(3);
horizontalAxis.setNumberFormat("#,##0.0\\%");

horizontalAxis.setAutomaticMinValue(false);
horizontalAxis.setMinValue(-90);

horizontalAxis.setAutomaticMaxValue(false);
horizontalAxis.setMaxValue(20);

horizontalAxis.setAutomaticMajorUnit(false);
horizontalAxis.setMinorUnit(2);
horizontalAxis.setAutomaticMinorUnit(false);
horizontalAxis.setMajorUnit(10);

horizontalAxis.setAutomaticMinValue(true);
horizontalAxis.setAutomaticMaxValue(true);
horizontalAxis.setAutomaticMajorUnit(true);
horizontalAxis.setAutomaticMinorUnit(true);

horizontalAxis.getTextFormat().getPortionFormat().setFontHeight(12);
horizontalAxis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));

// Save the presentation to a file
try {
    presentation.save("output.pptx", SaveFormat.Pptx);
    System.out.println("Presentation created successfully!");
} catch (Exception e) {
    System.out.println("Error saving presentation: " + e.getMessage());
}
private static void setNumberFormat(IChartDataWorkbook workbook, int i) {
    workbook.getCell(0, "C" + i).setCustomNumberFormat("0.0");
}

private static void setPercentFormat(IChartDataWorkbook workbook, int i) {
    workbook.getCell(0, "B" + i).setCustomNumberFormat("#,##0.0\\%");
    workbook.getCell(0, "D" + i).setCustomNumberFormat("#,##0.0\\%");
}

More examples:
Chart Axis|Aspose.Slides Documentation
Bubble Chart|Aspose.Slides Documentation

Hi @andrey.potapov ,

Thanks for your reply.

I see you have manually set the units and bounds for both vertical and horizontal axis.

Blockquote
horizontalAxis.setAutomaticMinValue(false);
horizontalAxis.setMinValue(-90);
horizontalAxis.setAutomaticMaxValue(false);
horizontalAxis.setMaxValue(20);
horizontalAxis.setAutomaticMajorUnit(false);
horizontalAxis.setMinorUnit(2);
horizontalAxis.setAutomaticMinorUnit(false);
horizontalAxis.setMajorUnit(10);

The main issue for me is, I will not be able to hardcode the values, I want it to be auto set.

As I mentioned earlier, the ppt created using Aspose and manually created ppt has difference with auto units and bounds.

Could you please check and update the reason behind the difference between Aspose generated ppt and manually generated ppt? Also, please let me know if that difference could be fixed.

Thanks,
Thilak Babu

@Thilakbabu,
Thank you for the clarification. I’ve forwarded your requirements to our developers.

1 Like

@Thilakbabu,
Please try using the following code example:

Presentation presentation = new Presentation();

presentation.getSlideSize().setSize(SlideSizeType.Widescreen, SlideSizeScaleType.DoNotScale);

// Create a slide to add the chart
ISlide slide = presentation.getSlides().get_Item(0);

// Add a Bubble chart to the slide
IChart chart = slide.getShapes().addChart(ChartType.Bubble, 150, 70, 650, 400);

chart.setTitle(false);

chart.getLineFormat().getFillFormat().setFillType(FillType.Solid);
chart.getLineFormat().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

chart.getPlotArea().getFormat().getLine().getFillFormat().setFillType(FillType.Solid);
chart.getPlotArea().getFormat().getLine().getFillFormat().getSolidFillColor().setColor(Color.BLACK);

chart.getLegend().getTextFormat().getPortionFormat().setFontHeight(12);
chart.getLegend().getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));

// Get the chart's data sheet
IChartDataWorkbook workbook = chart.getChartData().getChartDataWorkbook();

// Clear the default data
chart.getChartData().getSeries().clear();

// Create the first (and only) series for the chart
//    Series  X-Values    Y-Values    Size
//    Product A   -8.88   0   100
//    Product B   -6.884  0.916   42.719
//    Product C   -2.184  0.117   1.702
//    Product D   -8.309  0.003   0.423
//    Product E   -15.216 -0.023  0.309
//    Product F   -74.517 -0.002  0

//getCell(int worksheetIndex, int row, int column, Object value)


IChartSeries seriesA = chart.getChartData().getSeries().add(workbook.getCell(0, 0, 0, "Product A"), ChartType.Bubble);
IChartDataPoint dpA = seriesA.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 0, 1, -8.88),
        workbook.getCell(0, 0, 2, 0),
        workbook.getCell(0, 0, 3, 100));
seriesA.getFormat().getFill().setFillType(FillType.Solid);
seriesA.getFormat().getFill().getSolidFillColor().setColor(new Color(233, 113, 50));

IChartSeries seriesB = chart.getChartData().getSeries().add(workbook.getCell(0, 2, 0, "Product B"), ChartType.Bubble);
IChartDataPoint dpB = seriesB.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 2, 1, -6.884),
        workbook.getCell(0, 2, 2, 0.916),
        workbook.getCell(0, 2, 3, 42.719));
seriesB.getFormat().getFill().setFillType(FillType.Solid);
seriesB.getFormat().getFill().getSolidFillColor().setColor(new Color(78, 167, 46));

IChartSeries seriesC = chart.getChartData().getSeries().add(workbook.getCell(0, 3, 0, "Product C"), ChartType.Bubble);
IChartDataPoint dpC = seriesC.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 3, 1, -2.184),
        workbook.getCell(0, 3, 2, 0.117),
        workbook.getCell(0, 3, 3, 1.702));
seriesC.getFormat().getFill().setFillType(FillType.Solid);
seriesC.getFormat().getFill().getSolidFillColor().setColor(new Color(25, 107, 36));

IChartSeries seriesD = chart.getChartData().getSeries().add(workbook.getCell(0, 4, 0, "Product D"), ChartType.Bubble);
IChartDataPoint dpD = seriesD.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 4, 1, -8.309),
        workbook.getCell(0, 4, 2, 0.003),
        workbook.getCell(0, 4, 3, 0.423));
seriesD.getFormat().getFill().setFillType(FillType.Solid);
seriesD.getFormat().getFill().getSolidFillColor().setColor(new Color(15, 158, 213));

IChartSeries seriesE = chart.getChartData().getSeries().add(workbook.getCell(0, 5, 0, "Product E"), ChartType.Bubble);
IChartDataPoint dpE = seriesE.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 5, 1, -15.216),
        workbook.getCell(0, 5, 2, -0.023),
        workbook.getCell(0, 5, 3, 0.309));
seriesE.getFormat().getFill().setFillType(FillType.Solid);
seriesE.getFormat().getFill().getSolidFillColor().setColor(new Color(160, 43, 147));

IChartSeries seriesF = chart.getChartData().getSeries().add(workbook.getCell(0, 6, 0, "Product F"), ChartType.Bubble);
IChartDataPoint dpF = seriesF.getDataPoints().addDataPointForBubbleSeries(
        workbook.getCell(0, 6, 1, -74.517),
        workbook.getCell(0, 6, 2, -0.0),
        workbook.getCell(0, 6, 3, 0));
seriesF.getFormat().getFill().setFillType(FillType.Solid);
seriesF.getFormat().getFill().getSolidFillColor().setColor(new Color(21, 93, 130));

for (int i = 1; i < 7; i++) {
    setPercentFormat(workbook, i);
    setNumberFormat(workbook, i);
}

IChartLinesFormat gridLineFormat = chart.getAxes().getVerticalAxis().getMajorGridLinesFormat();
gridLineFormat.getLine().getFillFormat().setFillType(FillType.NoFill);

IAxis verticalAxis = chart.getAxes().getVerticalAxis();
verticalAxis.getFormat().getLine().setWidth(2);
verticalAxis.setCrossType(CrossesType.Custom);
verticalAxis.setCrossAt(0.0f);

verticalAxis.setTickLabelPosition(1);
verticalAxis.setMajorTickMark(TickMarkType.None);

verticalAxis.setCategoryAxisType(0);
verticalAxis.setNumberFormat("0.0");

verticalAxis.setAutomaticMinValue(true);
verticalAxis.setAutomaticMaxValue(true);

verticalAxis.getTextFormat().getPortionFormat().setFontHeight(12);
verticalAxis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));

IAxis horizontalAxis = chart.getAxes().getHorizontalAxis();
horizontalAxis.getFormat().getLine().setWidth(2);
horizontalAxis.setCrossType(CrossesType.Custom);
horizontalAxis.setCrossAt(0.0f);

horizontalAxis.setTickLabelPosition(1);
horizontalAxis.setMajorTickMark(TickMarkType.None);

horizontalAxis.setCategoryAxisType(3);
horizontalAxis.setNumberFormat("#,##0.0\\%");

horizontalAxis.setAutomaticMinValue(true);
horizontalAxis.setAutomaticMaxValue(true);
horizontalAxis.setAutomaticMajorUnit(true);
horizontalAxis.setAutomaticMinorUnit(true);

horizontalAxis.getTextFormat().getPortionFormat().setFontHeight(12);
horizontalAxis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));

// Save the presentation to a file
try {
    presentation.save("output.pptx", SaveFormat.Pptx);
    System.out.println("Presentation created successfully!");
} catch (Exception e) {
    System.out.println("Error saving presentation: " + e.getMessage());
}
private static void setNumberFormat(IChartDataWorkbook workbook, int i) {
    workbook.getCell(0, "C" + i).setCustomNumberFormat("0.0");
}

private static void setPercentFormat(IChartDataWorkbook workbook, int i) {
    workbook.getCell(0, "B" + i).setCustomNumberFormat("#,##0.0\\%");
    workbook.getCell(0, "D" + i).setCustomNumberFormat("#,##0.0\\%");
}

If you want the same “automatic” chart behavior in the case of Axis, you must set all styles of Axis elements. For example, you should set the size and font:

horizontalAxis.getTextFormat().getPortionFormat().setFontHeight(12);
horizontalAxis.getTextFormat().getPortionFormat().setLatinFont(new FontData("Aptos"));

output.zip (30.1 KB)

Hi @andrey.potapov ,

You mean the only missing code was setting the font and size for the axes?

Thanks,
Thilak Babu

@Thilakbabu,
Yes, that is true.