How to generate Bubble chart

I have a Excel template with some data. I am not able to generate the correct Bubble chart using Aspose. Please help me with steps to generate the bubble chart. The chart created manually in Excel and the data is attached.


This message was posted using Page2Forum (attachment) from BubbleSizes Property - Aspose.Cells for .NET and Java

I want to specify a particular cell for the series name, x-value, y-value and bubble size.

Hi,

Thanks for providing us the template excel file containing your desired chart.

I have created a sample code to create your desired chart (similar to Chart1), I used the data in your template file sheet named sheet1 as a data source for the chart data series. Kindly refer to it. Attached is the generated excel file.

Sample code:

Workbook workbook = new Workbook();
workbook.Open(@"f:\test\Bubble.xls");
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";

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(@"f:\test\output_BubblesChart1.xls");

Thank you.