Sizes bubbles in chart

I have a problem with a chart of type ChartType.BUBBLE that has to do with the size of the bubbles.
I add points with a size 1:

chart.getSeries().add(
bubble.getName(),
new double[]{ bubble.getDataX() },
new double[]{ bubble.getDataY() },
new double[]{ 1 });

All the dots are painted the same size but I can’t reduce the size. It doesn’t matter what size I paint them, they are always painted the same.
I manage to change their size by adding a bubble twice the size of the others, then they reduce their size.
How can I better control the size of each dot without having to add an extra bubble?

Thank you so much

@MikeRodriguez You can add several bubbles in one series like this:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Chart chart = builder.insertChart(ChartType.BUBBLE, 300, 200).getChart();
chart.getSeries().clear();
chart.getSeries().add("Bubbles",
        new double[] { 1, 2, 3 }, // Defines X coordinates of bubbles
        new double[] { 2, 4, 6 }, // Defines Y coordinates of bubbles
        new double[] { 1, 2, 5 }); // Defines size of bubbles
doc.save("C:\\Temp\\out.docx");

out.docx (8.6 KB)

Brilliant. This approach has worked, I don’t really understand why my approach doesn’t work very well.
I want to change the color of the bubbles, isn’t there a way to define everything at once? since now, once the points are created, I have to iterate them to change the color.

Thank you so much
All the best

point.getFormat().setFilledColor it is depreciated. What alternative do we have?

@MikeRodriguez You can change color of bubbles by changing fill color of the corresponding data point of the series. For example see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
Chart chart = builder.insertChart(ChartType.BUBBLE, 300, 200).getChart();
chart.getSeries().clear();
ChartSeries series = chart.getSeries().add("Bubbles",
        new double[] { 1, 2, 3 }, // Defines X coordinates of bubbles
        new double[] { 2, 4, 6 }, // Defines Y coordinates of bubbles
        new double[] { 1, 2, 5 }); // Defines size of bubbles
// Change color of bubbles.
series.getDataPoints().get(0).getFormat().getFill().setColor(Color.RED);
series.getDataPoints().get(1).getFormat().getFill().setColor(Color.YELLOW);
series.getDataPoints().get(2).getFormat().getFill().setColor(Color.GREEN);

doc.save("C:\\Temp\\out.docx");

out.docx (8.6 KB)

Perfectly! :ok_hand:

1 Like

Whether you run this (sizes of 1) →

chart.getSeries().add("Bubbles",
         new double[] { 1, 2, 3 },
         new double[] { 2, 4, 6 },
         new double[] { 1, 1, 1 });

2023-11-03 10 27 56.png (13.5 KB)

like you run this (sizes of 2)

chart.getSeries().add("Bubbles",
         new double[] { 1, 2, 3 },
         new double[] { 2, 4, 6 },
         new double[] { 2, 2, 2 });

2023-11-03 10 27 56.png (13.5 KB)

The size of the bubbles is the same in both cases.
Is there something that is incorrect?

@MikeRodriguez Bubble size is not absolute value it is relative. So it is expected that size of bubbles is the same.
MS Word uses approximately 1/8 of minimum plot area area dimension as a maximum allowed diameter of bubble. So when bubble chart is rendered MS Word selects the bubble that has maximum size and renders it with diameter that approximately equals 1/8 of minimum plot area area dimension, other bubbles have the appropriate relative diameter. For example if plot area has dimensions 100x80, the maximum allowed bubble diameter is 80/8=10. Let’s suppose we have 3 bubbles with size 5, 2, 1. The bigger bubble will have diameter 10, the second will have dimeter (10/5)*2=4 and the smallest will have size (10/5)*1=2. In your case all bubbles have the same size, so all of them are rendered with the maximum allowed diameter.

I understand. I will solve it by adding another hidden bubble with a different size.
Thank you so much

1 Like

@MikeRodriguez In MS Word you can scale bubble using the appropriate options:


Unfortunately, currently there is no public API to get/set this option in Aspose.Words.

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

Issue ID(s): WORDSNET-26168

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.