insertChart method

insertChart(chartType, width, height)

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

insertChart(chartType: Aspose.Words.Drawing.Charts.ChartType, width: number, height: number)
ParameterTypeDescription
chartTypeChartTypeThe chart type to insert into the document.
widthnumberThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightnumberThe 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.

insertChart(chartType, horzPos, left, vertPos, top, width, height, wrapType)

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

insertChart(chartType: Aspose.Words.Drawing.Charts.ChartType, horzPos: Aspose.Words.Drawing.RelativeHorizontalPosition, left: number, vertPos: Aspose.Words.Drawing.RelativeVerticalPosition, top: number, width: number, height: number, wrapType: Aspose.Words.Drawing.WrapType)
ParameterTypeDescription
chartTypeChartTypeThe chart type to insert into the document.
horzPosRelativeHorizontalPositionSpecifies where the distance to the image is measured from.
leftnumberDistance in points from the origin to the left side of the image.
vertPosRelativeVerticalPositionSpecifies where the distance to the image measured from.
topnumberDistance in points from the origin to the top side of the image.
widthnumberThe width of the image in points. Can be a negative or zero value to request 100% scale.
heightnumberThe 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.

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.

let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);

let chart = builder.insertChart(aw.Drawing.Charts.ChartType.Pie, aw.ConvertUtil.pixelToPoint(300), 
  aw.ConvertUtil.pixelToPoint(300)).chart;
expect(aw.ConvertUtil.pixelToPoint(300)).toEqual(225.0);
chart.series.clear();
chart.series.add("My fruit",
  [ "Apples", "Bananas", "Cherries" ],
  [ 1.3, 2.2, 1.5 ]);

doc.save(base.artifactsDir + "DocumentBuilder.InsertPieChart.docx");

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

let doc = new aw.Document();
let builder = new aw.DocumentBuilder(doc);

builder.insertChart(aw.Drawing.Charts.ChartType.Pie, aw.Drawing.RelativeHorizontalPosition.Margin, 100, aw.Drawing.RelativeVerticalPosition.Margin,
  100, 200, 100, aw.Drawing.WrapType.Square);

doc.save(base.artifactsDir + "DocumentBuilder.InsertedChartRelativePosition.docx");

See Also