Other API Samples

#### Charting Combination Chart

Create a combination chart by utilizing multiple chart groups and multiple axes groups.

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

cells["G3:G7"].Value =
new string[,] { { "Mon" }, { "Tue" }, { "Wed" }, { "Thu" }, { "Fri" } };
cells["H2:K2"].Value =
new string[,] { { "Breakfast", "Lunch", "Dinner", "Total" } };
cells["H3:J7"].Formula = "=INT(RAND() * 500) + 300";
cells["K3:K7"].Formula = "=SUM(H3:J3)";

// 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's source data range, plotting series in columns.

// Set the chart type to a 100% stacked column.

// Get a reference to the chart's series collection and each series.

// Change the last series chart type and plot it on the secondary axis.
// NOTE: This creates a combination chart using multiple chart groups
//       and utilizes both primary and secondary axes sets, allowing for
//       disproportionate ranges of values to be plotted separately.

// Change the fill color of each primary series.

// Change the line color of the total series.

// Add data labels to the total series and get a reference to the data labels.
seriesTotal.HasDataLabels = true;

// Position each data label below each data point.

// Change the fill formatting of the data labels.
fillFormat.Visible = true;

// Change the line formatting of the data labels.
lineFormat.Visible = true;

// Change the legend position to the top of the chart.

// Get a reference to the primary value axis, hide major
// gridlines, and use a fixed major unit scaling value.
valueAxis.HasMajorGridlines = false;
valueAxis.MajorUnit = 0.25;

// Change the chart font name and size.
chart.ChartArea.Font.Name = "Verdana";
chart.ChartArea.Font.Size = 8;

// Add a chart title and change the font size.
chart.HasTitle = true;
chart.ChartTitle.Text = "Weekday Calorie Intake";
chart.ChartTitle.Font.Size = 9;``````
##### 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.

Download an Excel Open XML Workbook (*.xlsx) file with the results of this sample.