[]
Creates a chart at the specified location on the active sheet.
Use the position and size arguments, in points, to place the chart on the worksheet. The returned IShape contains the chart and can be used to access the chart through Chart.
IShape AddChart(ChartType chartType, double left, double top, double width, double height)
Function AddChart(chartType As ChartType, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| ChartType | chartType | The chart type. |
| double | left | The distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart). |
| double | top | The distance, in points, from the top edge of the new chart shape to the top edge of the worksheet. |
| double | width | The width, in points, of the object. |
| double | height | The height, in points, of the object. |
| Type | Description |
|---|---|
| IShape | The IShape object. |
worksheet.Range["A1:D5"].Value = new object[,] {
{null, "Revenue", "Profit", "Sales"},
{"North", 10, 25, 25},
{"East", 51, 36, 27},
{"South", 52, 85, 30},
{"West", 22, 65, 65}
};
IShape shape = worksheet.Shapes.AddChart(ChartType.ColumnClustered, 200, 75, 300, 220);
shape.Chart.SeriesCollection.Add(worksheet.Range["A1:D5"], RowCol.Columns, true, true);
Creates a chart at the specified range on the current sheet.
The sheet of the target range and the sheet to which the shape is added must be the same sheet.
IShape AddChart(ChartType chartType, IRange targetRange)
Function AddChart(chartType As ChartType, targetRange As IRange) As IShape
| Type | Name | Description |
|---|---|---|
| ChartType | chartType | The chart type. |
| IRange | targetRange | The target range on the current sheet where the chart is created. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new chart. |
worksheet.Range["A1:B3"].Value = new object[,] {
{"Month", "Sales"},
{"Jan", 100},
{"Feb", 200}
};
IRange range = worksheet.Range["D1:J8"];
IShape chart = worksheet.Shapes.AddChart(ChartType.ColumnClustered, range);
Creates a chart at the specified location on the active sheet.
Use this method to add a chart shape with an explicit name and size. The position and size are measured in points. After the chart is created, use Chart to configure its data series and other chart settings.
IShape AddChart(string name, ChartType chartType, double left, double top, double width, double height)
Function AddChart(name As String, chartType As ChartType, left As Double, top As Double, width As Double, height As Double) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The chart name. |
| ChartType | chartType | The chart type. |
| double | left | The distance, in points, from the left edge of the object to the left edge of column A (on a worksheet) or the left edge of the chart area (on a chart). |
| double | top | The distance, in points, from the top edge of the new chart shape to the top edge of the worksheet. |
| double | width | The width, in points, of the object. |
| double | height | The height, in points, of the object. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new chart. |
worksheet.Range["A1:D5"].Value = new object[,] {
{null, "Revenue", "Profit", "Sales"},
{"North", 10, 25, 25},
{"East", 51, 36, 27},
{"South", 52, 85, 30},
{"West", 22, 65, 65}
};
IShape shape = worksheet.Shapes.AddChart("SalesChart", ChartType.ColumnClustered, 200, 75, 300, 220);
shape.Chart.SeriesCollection.Add(worksheet.Range["A1:D5"], RowCol.Columns, true, true);
Creates a chart at the specified range on the current sheet.
The sheet of targetRange and the sheet to which the shape is added must be the same sheet.
IShape AddChart(string name, ChartType chartType, IRange targetRange)
Function AddChart(name As String, chartType As ChartType, targetRange As IRange) As IShape
| Type | Name | Description |
|---|---|---|
| string | name | The chart name. |
| ChartType | chartType | The chart type. |
| IRange | targetRange | The target range on the current sheet. This range must belong to the same sheet as the shape collection. |
| Type | Description |
|---|---|
| IShape | The IShape object that represents the new chart. |
worksheet.Range["A1:B3"].Value = new object[,] {
{"Region", "Sales"},
{"North", 10},
{"South", 15}
};
IRange range = worksheet.Range["D1:H10"];
IShape shape = worksheet.Shapes.AddChart("SalesChart", ChartType.ColumnClustered, range);
shape.Chart.SeriesCollection.Add(worksheet.Range["A1:B3"], RowCol.Columns, true, true);