[]
        
(Showing Draft Content)

GrapeCity.Documents.Excel.Drawing.IShapes.AddChart

AddChart Method

AddChart(ChartType, double, double, double, double)

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.

Declaration
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
Parameters
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.

Returns
Type Description
IShape

The IShape object.

Examples
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);

AddChart(ChartType, IRange)

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.

Declaration
IShape AddChart(ChartType chartType, IRange targetRange)
Function AddChart(chartType As ChartType, targetRange As IRange) As IShape
Parameters
Type Name Description
ChartType chartType

The chart type.

IRange targetRange

The target range on the current sheet where the chart is created.

Returns
Type Description
IShape

The IShape object that represents the new chart.

Examples
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);

AddChart(string, ChartType, double, double, double, double)

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.

Declaration
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
Parameters
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.

Returns
Type Description
IShape

The IShape object that represents the new chart.

Examples
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);

AddChart(string, ChartType, IRange)

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.

Declaration
IShape AddChart(string name, ChartType chartType, IRange targetRange)
Function AddChart(name As String, chartType As ChartType, targetRange As IRange) As IShape
Parameters
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.

Returns
Type Description
IShape

The IShape object that represents the new chart.

Examples
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);