Creation of Bubble Chart in Excel

Hi Team,

I have a scenario in which I need to create a Bubble Chart in excel. Could you please help me with a sample code.

Please find the attached screenshot for you reference.

Regards,

Sanjeev

Hi Sanjeev,

Thanks for your posting and considering Aspose.Cells.

Please attach your excel file containing your desired bubble chart as you have shown in screenshot for our reference. We will look into it and provide you a sample code to achieve the same thing using Aspose.Cells APIs.

Hi
Thanks for your reply.Please find the attachment of the sample bubble chart.

Hi,

Thanks for your sample file and using Aspose.Cells.

Please see the following sample that creates a Bubble chart. It will give you idea how to get started with the creation of Bubble chart using Aspose.Cells API. I have also attached the output Excel file generated by the code for your reference.

Java


Workbook workbook = new Workbook(FileFormatType.XLSX);

Worksheet sheet = workbook.getWorksheets().get(0);

// Put data

sheet.getCells().get(0, 0).putValue(“Y Values”);

sheet.getCells().get(0, 1).putValue(2);

sheet.getCells().get(0, 2).putValue(4);

sheet.getCells().get(0, 3).putValue(6);


sheet.getCells().get(1, 0).putValue(“Bubble Size”);

sheet.getCells().get(1, 1).putValue(1);

sheet.getCells().get(1, 2).putValue(5);

sheet.getCells().get(1, 3).putValue(3);


sheet.getCells().get(2, 0).putValue(“X Values”);

sheet.getCells().get(2, 1).putValue(1);

sheet.getCells().get(2, 2).putValue(2);

sheet.getCells().get(2, 3).putValue(3);


// Generate chart

int chartIndex = sheet.getCharts().add(ChartType.BUBBLE, 5, 5, 22, 12);

Chart chart = sheet.getCharts().get(chartIndex);


// Insert series, set bubble size and x values

chart.getNSeries().add(“B1:D1”, false);

chart.getNSeries().get(0).setBubbleSizes(“B2:D2”);

chart.getNSeries().get(0).setXValues(“B3:D3”);


// Set a single color the series data points

chart.getNSeries().setColorVaried(true);


workbook.save(“outBubbleChart1.xlsx”);


Hi,

Thanks for the reply.But I just need to clarify one thing.
Here we set the Xvalues and bubble size.How can we set values for Y axis of the bubbles.Do we have any specific methods for setting Yvalues of the bubbles?

Thanks,
Sanjeev

Hi Sanjeev,

Thanks for your posting and using Aspose.Cells.

Y values are set using the following code.

chart.getNSeries().add(“B1:D1”, false);

Here B1:D1 are Y values.

Hi, and how can I add specific image for each bubble. It is possible in Excel.


Thanks
Hi jean-marc,

Well, it is also possible via Aspose.Cells APIs to set images for the bubbles as fill format in a Bubble chart. I have written a sample code to accomplish the task for your needs. Please refer to the code segment pasted in your other thread for your needs. I have also attached the input and output Excel files for your reference there.

Thank you.