チャート内の図形
チャートにラベルコントロールを追加
ラベルはスプレッドシートの内容に関するユーザーへの情報提供手段を提供します。 Aspose.Cellsを使用して、チャートにラベルを追加したり操作したりすることができます。
クラスには AddLabelInChart という名前のメソッドを備えた Aspose.Cells.Drawing.ShapeCollection クラス があります。 このメソッドを使用してチャートにラベルコントロールを追加します。 このメソッドに使用されるパラメータのリストは以下の通りです:
- top - ラベルの上部左隅からの垂直オフセット、チャートエリアの1/4000単位。
- left - ラベルの上部左隅からの水平オフセット、チャートエリアの1/4000単位。
- height - ラベルの高さ、チャートエリアの1/4000単位。
- width - ラベルの幅、チャートエリアの1/4000単位。
このメソッドは Aspose.Cells.Drawing.Label オブジェクトを返します。 Label クラス はチャート内のラベルを表します。 いくつかの重要なメンバを持っています:
以下の例では、チャートにラベルを追加する方法が示されています。 この例では、チャートが含まれたデザイナーファイル(exp_piechart.xls)を使用します。 このファイルを使用してチャートにラベルを挿入します。 チャートにラベルを追加するための元のコードは以下の通りです。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the existing file. | |
Workbook workbook = new Workbook(dataDir + "chart.xls"); | |
// Get the designer chart in the second sheet. | |
Worksheet sheet = workbook.Worksheets[1]; | |
Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; | |
// Add a new label to the chart. | |
Aspose.Cells.Drawing.Label label = chart.Shapes.AddLabelInChart(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 = Aspose.Cells.Drawing.PlacementType.FreeFloating; | |
// Save the excel file. | |
workbook.Save(dataDir + "chart.out.xls"); |
チャートにテキストボックスコントロールを追加
レポートで重要な情報を強調表示する一つの方法は、テキストボックスを使用することです。たとえば、企業名を表示したり、最高の売上地域を示したりするためにテキストを入力します。 Aspose.Cells.Drawing.ShapeCollection クラス には AddTextBoxInChart という名前のメソッドがあり、これを使用してチャートにテキストボックスコントロールを追加します。以下は、このメソッドに使用されるパラメータのリストです:
- top - テキストボックスの上部左隅からの垂直オフセット、チャートエリアの1/4000単位。
- left - テキストボックスの上部左隅からの水平オフセット、チャートエリアの1/4000単位。
- height – テキストボックスの高さ、チャートエリアの1/4000単位で指定します。
- width – テキストボックスの幅、チャートエリアの1/4000単位で指定します。
メソッドは Aspose.Cells.Drawing.TextBox オブジェクトを返します。TextBox クラスはチャート内のテキストボックスを表します。
下の例は、チャートにテキストボックスを追加する方法を示しています。この例では、以前のデザイナーファイル(exp_piechart.xls)を使用し、その中にチャートが含まれています。このファイルを使用してチャートにテキストボックスを挿入してチャートタイトルを表示します。以下は、チャートにテキストボックスを追加するための元のコードです。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the existing file. | |
Workbook workbook = new Workbook(dataDir + "chart.xls"); | |
// Get the designer chart in the second sheet. | |
Worksheet sheet = workbook.Worksheets[1]; | |
Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; | |
// Add a new textbox to the chart. | |
Aspose.Cells.Drawing.TextBox textbox0 = chart.Shapes.AddTextBoxInChart(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.IsBold = true; | |
// Set the font size. | |
textbox0.Font.Size = 14; | |
// Set font attribute to italic. | |
textbox0.Font.IsItalic = true; | |
// Get the filformat of the textbox. | |
Aspose.Cells.Drawing.FillFormat fillformat = textbox0.Fill; | |
// Get the lineformat type of the textbox. | |
Aspose.Cells.Drawing.LineFormat lineformat = textbox0.Line; | |
// Set the line weight. | |
lineformat.Weight = 2; | |
// Set the dash style to solid. | |
lineformat.DashStyle = Aspose.Cells.Drawing.MsoLineDashStyle.Solid; | |
// Save the excel file. | |
workbook.Save(dataDir + "chart.out.xls"); |
チャートに画像を追加する
Aspose.Cellsを使用すると、チャートに画像を挿入することができます。たとえば、チャートやその内容を強調したり、意味を追加するために画像を追加したり、ブランドのイメージファイルを挿入することができます。
Aspose.Cells.Drawing.ShapeCollection クラスは、画像オブジェクトをチャートに追加するために使用されるAddPictureInChartメソッドを提供します。以下は、メソッドに使用されるパラメータのリストです。
- top – 画像の上部左隅からの垂直オフセット、チャートエリアの1/4000単位で指定します。
- left – 画像の上部左隅からの水平オフセット、チャートエリアの1/4000単位で指定します。
- stream – 画像データを含むストリームオブジェクト。
- widthScale – 画像幅のスケール、パーセンテージ値。
- heightScale – 画像の高さのスケール、パーセンテージ値。
メソッドはAspose.Cells.Drawing.Picture オブジェクトを返します。Picture クラスはチャート内の画像オブジェクトを表します。
下の例は、チャートに画像を追加する方法を示しています。この例では、以前のデザイナーファイル(exp_piechart.xls)を使用し、その中にチャートが含まれています。このファイルを使用してチャートに画像を挿入します。以下は、チャートに画像を追加するための元のコードです。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Open the existing file. | |
Workbook workbook = new Workbook(dataDir + "chart.xls"); | |
// Get an image file to the stream. | |
FileStream stream = new FileStream(dataDir + "logo.jpg", FileMode.Open, FileAccess.Read); | |
// Get the designer chart in the second sheet. | |
Worksheet sheet = workbook.Worksheets[0]; | |
Aspose.Cells.Charts.Chart chart = sheet.Charts[0]; | |
// Add a new picture to the chart. | |
Aspose.Cells.Drawing.Picture pic0 = chart.Shapes.AddPictureInChart(50, 50, stream, 40, 40); | |
// Get the lineformat type of the picture. | |
Aspose.Cells.Drawing.LineFormat lineformat = pic0.Line; | |
// Set the dash style. | |
lineformat.DashStyle = Aspose.Cells.Drawing.MsoLineDashStyle.Solid; | |
// Set the line weight. | |
lineformat.Weight = 4; | |
// Save the excel file. | |
workbook.Save(dataDir + "chart.out.xls"); |
チャートにチェックボックスを追加する
Aspose.Cellsを使用すると、MsoDrawingType列挙型を使用して、チャートシートにチェックボックスを挿入することができます。以下の例では、チャートシートにチェックボックスを追加する方法を示しています。
次の画像は、出力ファイルに含まれるチャートシートにチェックボックスが表示されています。
次のコードスニペットによって生成された出力ファイルが添付されています。
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Adding a chart to the worksheet | |
int index = workbook.Worksheets.Add(SheetType.Chart); | |
Worksheet sheet = workbook.Worksheets[index]; | |
sheet.Charts.AddFloatingChart(ChartType.Column, 0, 0, 1024, 960); | |
sheet.Charts[0].NSeries.Add("{1,2,3}", false); | |
// Add checkbox to the chart. | |
sheet.Charts[0].Shapes.AddShapeInChart(MsoDrawingType.CheckBox, PlacementType.Move, 400, 400, 1000, 600); | |
sheet.Charts[0].Shapes[0].Text = "CheckBox 1"; | |
// Save the excel file. | |
workbook.Save(outputDir + "InsertCheckboxInChartSheet_out.xlsx"); |