Description
Creating Excel-compatible Column Charts is trivial to do with SpreadsheetGear. At its most basic level you call IShapes.AddChart(...) and then set the returned chart object to use a ChartType.ColumnClustered chart type (or one of the other column-based chart types).
- Opens an Excel workbook (
ChartData.xlsx) pre-populated with chart source data located in the Defined Name "RegionalSales" which points to the rangeG2:K6. - Charts are positioned on the worksheet relative to the top-left edge of the worksheet (in Points); however, you might want to position the column chart based on row / column indexes. SpreadsheetGear can take care of this conversion by using the
IWorksheetWindowInfo.ColumnToPoints(double columnIndex)andRowToPoints(double rowIndex)methods. - Adds the chart at the specified worksheet location by calling
IShapes.AddChart(double top, double left, double width, double height)and setting the source data for the chart by callingIChart.SetSourceData(IRange source, RowCol rowCol). - Sets the chart's type (
IChart.ChartType) toChartType.ColumnClustered. Other column-based chart types are available, such asChartType.ColumnStacked,ChartType.ColumnStacked100and others. - Additional chart options are configured, including:
- Adding a chart title by setting
IChart.HasTitletotrue, then setting the title text and other chart title options under theIChart.ChartTitleproperty. - Accessing the "value" axis (Y-axis) via the
IChart.Axes[...]collection to apply a dashed line for the major gridlines.
- Adding a chart title by setting