チャート内の図形
チャートにラベルコントロールを追加
ラベルはスプレッドシートの内容に関するユーザーへの情報提供手段を提供します。 Aspose.Cells for Python via .NETは、チャートにラベルを追加および操作することを可能にします。
クラスには add_label_in_chart という名前のメソッドを備えた aspose.cells.drawing.ShapeCollection クラス があります。 このメソッドを使用してチャートにラベルコントロールを追加します。 このメソッドに使用されるパラメータのリストは以下の通りです:
- top - ラベルの上部左隅からの垂直オフセット、チャートエリアの1/4000単位。
- left - ラベルの上部左隅からの水平オフセット、チャートエリアの1/4000単位。
- height - ラベルの高さ、チャートエリアの1/4000単位。
- width - ラベルの幅、チャートエリアの1/4000単位。
このメソッドは aspose.cells.drawing.Label オブジェクトを返します。 Label クラス はチャート内のラベルを表します。 いくつかの重要なメンバを持っています:
以下の例では、チャートにラベルを追加する方法が示されています。 この例では、チャートが含まれたデザイナーファイル(exp_piechart.xls)を使用します。 このファイルを使用してチャートにラベルを挿入します。 チャートにラベルを追加するための元のコードは以下の通りです。
from aspose.cells import Workbook | |
from aspose.cells.drawing import PlacementType | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Open the existing file. | |
workbook = Workbook(dataDir + "chart.xls") | |
# Get the designer chart in the second sheet. | |
sheet = workbook.worksheets[1] | |
chart = sheet.charts[0] | |
# Add a new label to the chart. | |
label = chart.shapes.add_label_in_chart(100, 100, 350, 900) | |
# Set the caption of the label. | |
label.text = "A Label In Chart" | |
# Set the Placement Type, the way the | |
# Label is attached to the cells. | |
label.placement = PlacementType.FREE_FLOATING | |
# Save the excel file. | |
workbook.save(dataDir + "chart.out.xls") |
チャートにテキストボックスコントロールを追加
レポートで重要な情報を強調表示する一つの方法は、テキストボックスを使用することです。たとえば、企業名を表示したり、最高の売上地域を示したりするためにテキストを入力します。 aspose.cells.drawing.ShapeCollection クラス には add_text_box_in_chart という名前のメソッドがあり、これを使用してチャートにテキストボックスコントロールを追加します。以下は、このメソッドに使用されるパラメータのリストです:
- top - テキストボックスの上部左隅からの垂直オフセット、チャートエリアの1/4000単位。
- left - テキストボックスの上部左隅からの水平オフセット、チャートエリアの1/4000単位。
- height – テキストボックスの高さ、チャートエリアの1/4000単位で指定します。
- width – テキストボックスの幅、チャートエリアの1/4000単位で指定します。
メソッドは aspose.cells.drawing.TextBox オブジェクトを返します。TextBox クラスはチャート内のテキストボックスを表します。
下の例は、チャートにテキストボックスを追加する方法を示しています。この例では、以前のデザイナーファイル(exp_piechart.xls)を使用し、その中にチャートが含まれています。このファイルを使用してチャートにテキストボックスを挿入してチャートタイトルを表示します。以下は、チャートにテキストボックスを追加するための元のコードです。
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle | |
from aspose.pydrawing import Color | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Open the existing file. | |
workbook = Workbook(dataDir + "chart.xls") | |
# Get the designer chart in the second sheet. | |
sheet = workbook.worksheets[1] | |
chart = sheet.charts[0] | |
# Add a new textbox to the chart. | |
textbox0 = chart.shapes.add_text_box_in_chart(100, 1100, 350, 2550) | |
# Fill the text. | |
textbox0.text = "Sales By Region" | |
# Get the textbox text frame. | |
# Aspose.Cells.Drawing.MsoTextFrame textframe0 = textbox0.TextFrame; | |
# Set the textbox to adjust it according to its contents. | |
# textframe0.AutoSize = true; | |
# Set the font color. | |
textbox0.font.color = Color.maroon | |
# Set the font to bold. | |
textbox0.font.is_bold = True | |
# Set the font size. | |
textbox0.font.size = 14 | |
# Set font attribute to italic. | |
textbox0.font.is_italic = True | |
# Get the filformat of the textbox. | |
fillformat = textbox0.fill | |
# Get the lineformat type of the textbox. | |
lineformat = textbox0.line | |
# Set the line weight. | |
lineformat.weight = 2.0 | |
# Set the dash style to solid. | |
lineformat.dash_style = MsoLineDashStyle.SOLID | |
# Save the excel file. | |
workbook.save(dataDir + "chart.out.xls") |
チャートに画像を追加する
Aspose.Cells for Python via .NETは、チャートに画像を挿入することも可能です。例として、強調や内容に意味を持たせるために画像を追加したり、ブランド画像ファイルを挿入したりできます。
aspose.cells.drawing.ShapeCollection クラスは、画像オブジェクトをチャートに追加するために使用されるadd_picture_in_chartメソッドを提供します。以下は、メソッドに使用されるパラメータのリストです。
- top – 画像の上部左隅からの垂直オフセット、チャートエリアの1/4000単位で指定します。
- left – 画像の上部左隅からの水平オフセット、チャートエリアの1/4000単位で指定します。
- stream – 画像データを含むストリームオブジェクト。
- widthScale – 画像幅のスケール、パーセンテージ値。
- heightScale – 画像の高さのスケール、パーセンテージ値。
メソッドはaspose.cells.drawing.Picture オブジェクトを返します。Picture クラスはチャート内の画像オブジェクトを表します。
下の例は、チャートに画像を追加する方法を示しています。この例では、以前のデザイナーファイル(exp_piechart.xls)を使用し、その中にチャートが含まれています。このファイルを使用してチャートに画像を挿入します。以下は、チャートに画像を追加するための元のコードです。
from aspose.cells import Workbook | |
from aspose.cells.drawing import MsoLineDashStyle | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# The path to the documents directory. | |
dataDir = RunExamples.GetDataDir(".") | |
# Open the existing file. | |
workbook = Workbook(dataDir + "chart.xls") | |
# Get an image file to the stream. | |
stream = open(dataDir + "logo.jpg", "rb") | |
# Get the designer chart in the second sheet. | |
sheet = workbook.worksheets[0] | |
chart = sheet.charts[0] | |
# Add a new picture to the chart. | |
pic0 = chart.shapes.add_picture_in_chart(50, 50, stream, 40, 40) | |
# Get the lineformat type of the picture. | |
lineformat = pic0.line | |
# Set the dash style. | |
lineformat.dash_style = MsoLineDashStyle.SOLID | |
# Set the line weight. | |
lineformat.weight = 4.0 | |
# Save the excel file. | |
workbook.save(dataDir + "chart.out.xls") |
チャートにチェックボックスを追加する
Aspose.Cells for Python via .NETは、MsoDrawingType列挙体を使用してチャートシートにチェックボックスを挿入できます。以下の例では、チャートシートにチェックボックスを追加する方法を示します。
次の画像は、出力ファイルに含まれるチャートシートにチェックボックスが表示されています。
次のコードスニペットによって生成された出力ファイルが添付されています。
from aspose.cells import SheetType, Workbook | |
from aspose.cells.charts import ChartType | |
from aspose.cells.drawing import MsoDrawingType, PlacementType | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Adding a chart to the worksheet | |
index = workbook.worksheets.add(SheetType.CHART) | |
sheet = workbook.worksheets[index] | |
sheet.charts.add_floating_chart(ChartType.COLUMN, 0, 0, 1024, 960) | |
sheet.charts[0].n_series.add("{1,2,3}", False) | |
# Add checkbox to the chart. | |
sheet.charts[0].shapes.add_shape_in_chart(MsoDrawingType.CHECK_BOX, PlacementType.MOVE, 400, 400, 1000, 600) | |
sheet.charts[0].shapes[0].text = "CheckBox 1" | |
# Save the excel file. | |
workbook.save(outputDir + "InsertCheckboxInChartSheet_out.xlsx") |