Shapes in Charts

Adding Label Control to the Chart

Labels provide a means for giving information to users about a spreadsheet’s content.
Aspose.Cells for Python via .NET allows you to add and manipulate labels even within charts.

The aspose.cells.drawing.ShapeCollection class provides a method named add_label_in_chart, used to add a label control to a chart. Below is a list of the parameters used for the method:

  • top – the vertical offset of the label from the upper left corner in units of 1/4000 of the chart area.
  • left – the horizontal offset of the label from the upper left corner in units of 1/4000 of the chart area.
  • height – the height of the label, in units of 1/4000 of the chart area.
  • width – the width of the label, in units of 1/4000 of the chart area.

The method returns an aspose.cells.drawing.Label object. The Label class represents a label in the chart. It has some important members:

  • text (property) – specifies a label’s caption string.
  • fill (property) – specifies the fill color attributes.

The following example shows how to add a label to the chart. The example uses a designer file (exp_piechart.xls) which has a chart in it. We use this file to insert a label into the chart. Below is the original code for adding a label to the chart. The following output is generated when executing the code.

Adding TextBox Control to the Chart

One way to highlight important information in a report is to use a text box. For example, enter text to highlight the company name or to indicate the geographic region with the highest sales. The aspose.cells.drawing.ShapeCollection class provides a method named add_text_box_in_chart, which is used to add a text box control to a chart. The following is the parameters list used for the method:

  • top – the vertical offset of the text box from the upper left corner in units of 1/4000 of the chart area.
  • left – the horizontal offset of the text box from the upper left corner in units of 1/4000 of the chart area.
  • height – the height of the text box, in units of 1/4000 of the chart area.
  • width – the width of the text box, in units of 1/4000 of the chart area.

The method returns an aspose.cells.drawing.TextBox object. The TextBox class represents a text box in the chart.

The following example shows how to add a text box to a chart. The example uses the previous designer file (exp_piechart.xls) which has a chart in it. We use this file to insert a text box into the chart to show the chart title. Below is the original code for adding a text box to the chart.

Adding Picture to the Chart

Aspose.Cells for Python via .NET allows you to insert images into a chart. For example, add a picture to emphasize or give more meaning to a chart or its contents, or insert a brand image file.

The aspose.cells.drawing.ShapeCollection class provides a method named add_picture_in_chart, which is used to add a picture object to the chart. The following is the parameters list used for the method:

  • top – the vertical offset of the picture from the upper left corner in units of 1/4000 of the chart area.
  • left – the horizontal offset of the picture from the upper left corner in units of 1/4000 of the chart area.
  • stream – a stream object which contains the image data.
  • widthScale – the scale of image width, a percentage value.
  • heightScale – the scale of image height, a percentage value.

The method returns an aspose.cells.drawing.Picture object. The Picture class represents a picture object in the chart.

The following example shows how to add a picture to the chart. The example utilizes the previous designer file (exp_piechart.xls) which has a chart in it. We use this file to insert an image into the chart. Below is the original code for adding a picture to the chart.

Adding Checkbox in the Chart

Aspose.Cells for Python via .NET allows you to insert checkboxes into a chart sheet by using the MsoDrawingType enumeration. The following example demonstrates adding a checkbox to a chart sheet.

The following image shows the chart sheet with the checkbox in the output file.

todo:image_alt_text

The output file generated by the following code snippet is attached for your reference.

Advanced topics

  • Add WordArt Watermark to Chart