InsertChart

InsertChart(ChartType, double, double)

Inserts an chart object into the document and scales it to the specified size.

public Shape InsertChart(ChartType chartType, double width, double height)
ParameterTypeDescription
chartTypeChartTypeThe chart type to insert into the document.
widthDoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightDoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.

Return Value

The image node that was just inserted.

Remarks

You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

Examples

Shows how to insert a pie chart into a document.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

Chart chart = builder.InsertChart(ChartType.Pie, ConvertUtil.PixelToPoint(300), 
    ConvertUtil.PixelToPoint(300)).Chart;
chart.Series.Clear();
chart.Series.Add("My fruit",
    new[] { "Apples", "Bananas", "Cherries" },
    new[] { 1.3, 2.2, 1.5 });

doc.Save(ArtifactsDir + "DocumentBuilder.InsertPieChart.docx");

See Also


InsertChart(ChartTypeRelativeHorizontalPosition, double, RelativeVerticalPosition, double, double, double, WrapType)

Inserts an chart object into the document and scales it to the specified size.

public Shape InsertChart(ChartType chartType, RelativeHorizontalPosition horzPos, double left, 
    RelativeVerticalPosition vertPos, double top, double width, double height, WrapType wrapType)
ParameterTypeDescription
chartTypeChartTypeThe chart type to insert into the document.
horzPosRelativeHorizontalPositionSpecifies where the distance to the image is measured from.
leftDoubleDistance in points from the origin to the left side of the image.
vertPosRelativeVerticalPositionSpecifies where the distance to the image measured from.
topDoubleDistance in points from the origin to the top side of the image.
widthDoubleThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightDoubleThe height of the image in points. Can be a negative or zero value to request 100% scale.
wrapTypeWrapTypeSpecifies how to wrap text around the image.

Return Value

The image node that was just inserted.

Remarks

You can change the image size, location, positioning method and other settings using the Shape object returned by this method.

Examples

Shows how to specify position and wrapping while inserting a chart.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

builder.InsertChart(ChartType.Pie, RelativeHorizontalPosition.Margin, 100, RelativeVerticalPosition.Margin,
    100, 200, 100, WrapType.Square);

doc.Save(ArtifactsDir + "DocumentBuilder.InsertedChartRelativePosition.docx");

See Also