チャートの形状

チャートへのラベル コントロールの追加

ラベルは、スプレッドシートのコンテンツに関する情報をユーザーに提供する手段を提供します。 Aspose.Cells を使用すると、チャートにもラベルを追加して操作できます。

Aspose.Cells.Drawing.ShapeCollectionクラスは、という名前のメソッドを提供しますAddLabelInChart、チャートにラベル コントロールを追加するために使用されます。以下は、メソッドに使用されるパラメーターのリストです。

  • – グラフ領域の 1/4000 単位での左上隅からのラベルの垂直オフセット。
  • – グラフ領域の 1/4000 単位での左上隅からのラベルの垂直オフセット。
  • 身長– グラフ エリアの 1/4000 単位のラベルの高さ。
  • – グラフ領域の 1/4000 単位のラベルの幅。

メソッドは戻りますAspose.Cells.Drawing.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");

TextBox コントロールをチャートに追加する

レポートで重要な情報を強調する 1 つの方法は、テキスト ボックスを使用することです。たとえば、テキストを入力して会社名を強調表示したり、売上高が最も多い地域を示したりします。のAspose.Cells.Drawing.ShapeCollectionクラスは、という名前のメソッドを提供しますAddTextBoxInChart、テキスト ボックス コントロールをチャートに追加するために使用されます。以下は、メソッドに使用されるパラメーター リストです。

  • – グラフ領域の 1/4000 単位での左上隅からのテキスト ボックスの垂直オフセット。
  • – グラフ領域の 1/4000 単位での左上隅からのテキスト ボックスの垂直オフセット。
  • 身長– テキスト ボックスの高さ (グラフ領域の 1/4000 単位)。
  • – テキスト ボックスの幅 (グラフ領域の 1/4000 単位)。

メソッドは戻りますAspose.Cells.Drawing.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、チャートに画像オブジェクトを追加するために使用されます。以下は、メソッドに使用されるパラメーター リストです。

  • – グラフ領域の 1/4000 単位での左上隅からのピクチャの垂直オフセット。
  • – グラフ領域の 1/4000 単位での左上隅からのピクチャの垂直オフセット。
  • ストリーム– 画像データを含むストリーム オブジェクト。
  • 幅スケール– 画像幅のスケール、パーセント値。
  • 高さスケール– 画像の高さのスケール、パーセント値。

メソッドはAspose.Cells.Drawing.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列挙。次の例は、グラフ シートにチェックボックスを追加する方法を示しています。

次の図は、出力ファイルにチェックボックスがあるグラフ シートを示しています。

todo:画像_代替_文章

出力ファイル参照用に、次のコード スニペットによって生成されたコードを添付します。

// 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");

先行トピック