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=doc)
chart = builder.insert_chart(chart_type=aw.drawing.charts.ChartType.PIE, width=aw.ConvertUtil.pixel_to_point(pixels=300), height=aw.ConvertUtil.pixel_to_point(pixels=300)).chart
chart.series.clear()
chart.series.add(series_name='My fruit', categories=['Apples', 'Bananas', 'Cherries'], values=[1.3, 2.2, 1.5])
doc.save(file_name=ARTIFACTS_DIR + 'DocumentBuilder.InsertPieChart.docx')

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

doc = aw.Document()
builder = aw.DocumentBuilder(doc=doc)
builder.insert_chart(chart_type=aw.drawing.charts.ChartType.PIE, horz_pos=aw.drawing.RelativeHorizontalPosition.MARGIN, left=100, vert_pos=aw.drawing.RelativeVerticalPosition.MARGIN, top=100, width=200, height=100, wrap_type=aw.drawing.WrapType.SQUARE)
doc.save(file_name=ARTIFACTS_DIR + 'DocumentBuilder.InsertedChartRelativePosition.docx')

See Also