insert_chart method

insert_chart(chart_type, width, height)

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

def insert_chart(self, chart_type: aspose.words.drawing.charts.ChartType, width: float, height: float):
    ...
ParameterTypeDescription
chart_typeChartTypeThe chart type to insert into the document.
widthfloatThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightfloatThe height of the image in points. Can be a negative or zero value to request 100% scale.

Remarks

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

Returns

The image node that was just inserted.

insert_chart(chart_type, horz_pos, left, vert_pos, top, width, height, wrap_type)

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

def insert_chart(self, chart_type: aspose.words.drawing.charts.ChartType, horz_pos: aspose.words.drawing.RelativeHorizontalPosition, left: float, vert_pos: aspose.words.drawing.RelativeVerticalPosition, top: float, width: float, height: float, wrap_type: aspose.words.drawing.WrapType):
    ...
ParameterTypeDescription
chart_typeChartTypeThe chart type to insert into the document.
horz_posRelativeHorizontalPositionSpecifies where the distance to the image is measured from.
leftfloatDistance in points from the origin to the left side of the image.
vert_posRelativeVerticalPositionSpecifies where the distance to the image measured from.
topfloatDistance in points from the origin to the top side of the image.
widthfloatThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightfloatThe height of the image in points. Can be a negative or zero value to request 100% scale.
wrap_typeWrapTypeSpecifies how to wrap text around the image.

Remarks

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

Returns

The image node that was just inserted.

Examples

Shows how to insert a pie chart into a document.

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

chart = builder.insert_chart(aw.drawing.charts.ChartType.PIE, aw.ConvertUtil.pixel_to_point(300),
    aw.ConvertUtil.pixel_to_point(300)).chart
chart.series.clear()
chart.series.add("My fruit",
    [ "Apples", "Bananas", "Cherries" ],
    [ 1.3, 2.2, 1.5 ])

doc.save(ARTIFACTS_DIR + "DocumentBuilder.insert_pie_chart.docx")

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

doc = aw.Document()
builder = aw.DocumentBuilder(doc)

builder.insert_chart(aw.drawing.charts.ChartType.PIE, aw.drawing.RelativeHorizontalPosition.MARGIN, 100, aw.drawing.RelativeVerticalPosition.MARGIN,
    100, 200, 100, aw.drawing.WrapType.SQUARE)

doc.save(ARTIFACTS_DIR + "DocumentBuilder.inserted_chart_relative_position.docx")

See Also