الأشكال في الرسوم البيانية
إضافة عنصر تحكم التسمية إلى الرسم البياني.
توفر التسميات وسيلة لإعطاء معلومات للمستخدمين حول محتوى جدول البيانات. تتيح لك Aspose.Cells إضافة التسميات والتلاعب بها حتى في الرسوم البيانية.
توفر فئة Aspose.Cells.Drawing.ShapeCollection طريقة تسمى AddLabelInChart تُستخدَم لإضافة عنصر تحكم تسمية إلى رسم بياني. فيما يلي قائمة بالمعلمات المستخدمة للطريقة:
- الأعلى - الإزاحة الرأسية للتسمية عن الزاوية اليسرى العلوية بوحدات تمثل 1/4000 من منطقة الرسم البياني.
- اليسار - الإزاحة الرأسية للتسمية عن الزاوية اليسرى العلوية بوحدات تمثل 1/4000 من منطقة الرسم البياني.
- الارتفاع - ارتفاع التسمية، بوحدات تمثل 1/4000 من منطقة الرسم البياني.
- العرض - عرض التسمية، بوحدات تمثل 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. يوضح المثال التالي إضافة خانة اختيار إلى ورقة الرسم البياني.
الصورة التالية تظهر ورقة الرسم البياني مع خانة الاختيار في ملف الإخراج.
الملف الناتج (101089316.xlsx) الذي تم إنشاؤه بواسطة مقتطف الكود التالي مرفق للرجوع إليه.
// 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"); |