Creating a Bubblechart with a specific image in each bubble

Hi,


Is it possible ?

How I can do it ?

Thanks

Hi,


Thanks for your query.

Yes, sure, it is possible 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 and you may add/update your code accordingly for your needs. I have also attached the input and output Excel files for your reference.
e.g
Sample code:

Workbook workbook = new Workbook(@“e:\test2\Bk_Bubble1.xlsx”);

Worksheet datasheet = workbook.Worksheets[“Sheet1”];

Cells cells = datasheet.Cells;

Worksheet chartsheet = workbook.Worksheets[workbook.Worksheets.Add()];

chartsheet.Type = SheetType.Chart;

chartsheet.Name = “Chart2”;

int chartIndex = chartsheet.Charts.Add(ChartType.Bubble, 0, 0, 25, 15);

Chart chart = chartsheet.Charts[chartIndex];


chart.PlotArea.Area.ForegroundColor = Color.Transparent;

chart.PlotArea.Border.IsVisible = false;


chart.ChartArea.Border.IsVisible = false;


chart.NSeries.Add("=Sheet1!D2", true);

chart.NSeries[0].XValues = “Sheet1!$B2”;

chart.NSeries[0].Name = datasheet.Cells[1, 0].Value.ToString();

chart.NSeries[0].BubbleSizes = “=Sheet1!C2”;

//Set the image for the series’ fill format

//Similarly you may set Series’ point fill format.

//Also, using similar way, you may set image as a fill format for other series/points

FileStream fs = File.OpenRead(@“e:\test\school.jpg”);

byte[] data = new byte[fs.Length];

fs.Read(data, 0, data.Length);

chart.NSeries[0].Area.FillFormat.ImageData = data;



chart.NSeries.Add("=Sheet1!D4", true);

chart.NSeries[1].XValues = “Sheet1!$B4”;

chart.NSeries[1].Name = datasheet.Cells[3, 0].Value.ToString();

chart.NSeries[1].BubbleSizes = “=Sheet1!C4”;


chart.NSeries.Add("=Sheet1!D3", true);

chart.NSeries[2].XValues = “Sheet1!$B3”;

chart.NSeries[2].Name = datasheet.Cells[2, 0].Value.ToString();

chart.NSeries[2].BubbleSizes = “=Sheet1!C3”;


chart.NSeries.Add("=Sheet1!D5", true);

chart.NSeries[3].XValues = “Sheet1!$B5”;

chart.NSeries[3].Name = datasheet.Cells[4, 0].Value.ToString();

chart.NSeries[3].BubbleSizes = “=Sheet1!C5”;


chart.NSeries.IsColorVaried = true;


//Set the legend position type

chart.Legend.Position = LegendPositionType.Top;


workbook.Save(@“e:\test2\out1_BubblesChart1.xlsx”);


Hope, this helps a bit.

Thank you.