Other API Samples

Charting Bubble Chart

Create a bubble chart representing three sets of data values.

``````// Create a new workbook and get a reference to the active worksheet, window info,
// and cells.

// Add a chart to the worksheet's shape collection.
// NOTE: Calculate the coordinates of the chart by converting row and column
//       coordinates to points.  Use fractional row and column values to get
//       coordinates anywhere in between row and column boundaries.
double left = windowInfo.ColumnToPoints(0.15);
double top = windowInfo.RowToPoints(0.5);
double right = windowInfo.ColumnToPoints(5.85);
double bottom = windowInfo.RowToPoints(13.5);
worksheet.Shapes.AddChart(left, top, right - left, bottom - top).Chart;

// Set the chart type to bubble.

// Get the chart's source data range.

// for each row in the data range...
for (int row = 0; row < source.RowCount; row++)
{
// Add a series to the chart's series collection.

// Set the series name, x values, y values, and bubble size values.
series.Name = "=" + source[row, 0].Address;
series.XValues = source[row, 1];
series.Values = source[row, 2];
series.BubbleSizes = source[row, 3];
}

// Get a reference to the x value axis, add a title, and link the title to a cell.
xValueAxis.HasTitle = true;
xValueAxis.AxisTitle.Text = "=H2";

// Get a reference to the y value axis, add a title, and link the title to a cell.
yValueAxis.HasTitle = true;
yValueAxis.AxisTitle.Text = "=I2";

// Add a chart title and change the font size.
chart.HasTitle = true;
chart.ChartTitle.Text = "Estimated Return on Investment";
chart.ChartTitle.Font.Size = 12;``````
Render Image

Generate an image representation of the results of this sample, which uses the SpreadsheetGear.Drawing.Image class to convert ranges, charts and shapes to images.