Grafiklerde Şekiller

Grafiğe Etiket Denetimi Ekleme

Etiketler, bir elektronik tablonun içeriği hakkında kullanıcılara bilgi verme aracı sağlar. Aspose.Cells, etiket eklemenize ve manipüle etmenize olanak tanır, hatta grafiklerin içine bile.

Aspose.Cells.Drawing.ShapeCollection sınıfı, bir AddLabelInChart yöntemi adında bir yöntem sağlar. Bu yöntem, bir etiket denetimini grafiğe eklemek için kullanılır. Yöntem için kullanılan parametrelerin bir listesi aşağıda verilmiştir:

  • üst – etiketin sol üst köşesinden dikey ofset (1/4000 biriminde grafik alanı).
  • sol – etiketin sol üst köşesinden yatay ofset (1/4000 biriminde grafik alanı).
  • yükseklik – etiketin yüksekliği, grafik alanının 1/4000 biriminde.
  • genişlik – etiketin genişliği, grafik alanının 1/4000 biriminde.

Yöntem, Aspose.Cells.Drawing.Label nesnesi döndürür. Label sınıfı, grafikteki bir etiketi temsil eder. Bazı önemli üyelere sahiptir:

  • Text (özellik) – bir etiketin başlık dizgisini belirtir.
  • Fill (özellik) – doldurma rengi özelliklerini belirtir.

Aşağıdaki örnek, bir etiketin grafiğe nasıl ekleneceğini göstermektedir. Örnek, içinde bir grafik bulunan bir tasarımcı dosyası (exp_piechart.xls) kullanır. Bu dosyayı, grafikte bir etiket eklemek için kullanırız. Aşağıda, grafiğe bir etiket eklemek için orijinal kod verilmiştir. Kodu yürüttüğünüzde aşağıdaki çıktı üretilir.

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

Grafiğe TextBox Kontrolü Ekleme

Bir raporda önemli bilgileri vurgulamanın bir yolu, bir metin kutusu kullanmaktır. Örneğin, şirket adını vurgulamak veya en yüksek satış yapılan coğrafi bölgeyi belirtmek için metin girin. Aspose.Cells.Drawing.ShapeCollection sınıfı, grafiğe bir metin kutusu denetimi eklemek için kullanılan AddTextBoxInChart adında bir yöntem sağlar. Aşağıdaki parametre listesi, yöntem için kullanılan parametreleri gösterir:

  • top – metin kutusunun grafik alanının sol üst köşesinden dikey ofseti, 1/4000 birimde.
  • left – metin kutusunun grafik alanının sol üst köşesinden dikey ofseti, 1/4000 birimde.
  • height – metin kutusunun yüksekliği, grafik alanının 1/4000 biriminde.
  • width – metin kutusunun genişliği, grafik alanının 1/4000 biriminde.

Yöntem, bir Aspose.Cells.Drawing.TextBox nesnesi döndürür. TextBox sınıfı, grafiğe bir metin kutusu temsil eder.

Aşağıdaki örnek, bir metin kutusunun grafiğe nasıl ekleneceğini gösterir. Örnek, içinde bir grafik bulunan önceki bir tasarımcı dosyası (exp_piechart.xls) kullanır. Bu dosyayı, grafiğe metin kutusu eklemek için kullanırız. Aşağıda, grafiğe metin kutusu eklemek için orijinal kod bulunmaktadır.

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

Grafiğe Resim Ekleme

Aspose.Cells, bir grafiğe resim eklemenize olanak tanır. Örneğin, bir resim ekleyerek bir grafiği vurgulamak veya anlamını artırmak veya bir marka resim dosyası eklemek.

Aspose.Cells.Drawing.ShapeCollection sınıfı, grafiğe bir resim nesnesi eklemek için kullanılan AddPictureInChart adında bir yöntem sağlar. Aşağıdaki parametre listesi, yöntem için kullanılan parametreleri gösterir:

  • top – resmin, grafik alanının sol üst köşesinden dikey ofseti, 1/4000 birimde.
  • left – resmin, grafik alanının sol üst köşesinden dikey ofseti, 1/4000 birimde.
  • stream – resim verisini içeren bir akım nesnesi.
  • widthScale – resmin genişlik ölçeği, yüzde değeri.
  • heightScale – resmin yükseklik ölçeği, yüzde değeri.

Yöntem, bir Aspose.Cells.Drawing.Picture nesnesi döndürür. Picture sınıfı, grafiğe bir resim nesnesi temsil eder.

Aşağıdaki örnek, bir resmin grafiğe nasıl ekleneceğini gösterir. Örnek, içinde bir grafik bulunan önceki bir tasarımcı dosyası (exp_piechart.xls) kullanır. Bu dosyayı, grafiğe bir resim eklemek için kullanırız. Aşağıda, grafiğe resim eklemek için orijinal kod bulunmaktadır.

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

Grafiğe Onay Kutusu Ekleme

Aspose.Cells, bir MsoDrawingType numarasını kullanarak bir grafik tablosuna onay kutuları eklemenize olanak tanır. Aşağıdaki örnek, bir grafik tablosuna onay kutusu eklemeyi göstermektedir.

Aşağıdaki resim, çıktı dosyasındaki grafik tablosunu içeren onay kutusu göstermektedir.

todo:image_alt_text

Aşağıdaki kod parçası tarafından oluşturulan çıktı dosyası, referansınız için ekte bulunmaktadır.

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

Gelişmiş Konular