Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
خطوط المؤشر هي رسوم بيانية صغيرة الحجم داخل الخلية وتكون مفيدة عندما تريد عرض اتجاه سريع بجوار صف أو عمود من البيانات دون أن تستهلك مساحة رسم بياني كامل. يدعم Excel ثلاثة أنواع من خطوط المؤشر: خطية، عمودية، وفوز/خسارة. يعكس Aspose.Cells هذه القدرة من خلال واجهات SparklineGroup وSparklineGroupCollection الموجودة في مساحة الاسم Aspose.Cells.Charts.
في Aspose.Cells، يتم إنشاء كل خط مؤشر تضيفه عبر worksheet.sparklineGroups.add(...)، والتي تُرجع كائنًا من نوع SparklineGroup. يمكنك بعد ذلك استخدام هذا الكائن لتعيين نوع خط المؤشر ونطاق البيانات والخلية الهدف والخصائص البصرية مثل لون الخط ووزن الخط والعلامات ومؤشرات نقاط القمة/القاع.
يستعرض هذا المقال كلًا من أنواع خطوط المؤشر الثلاثة التي يدعمها Aspose.Cells — الخطية، العمودية، والفوز/الخسارة — ويوضح كيفية إضافتها وتخصيص ألوانها وحفظ المصنف الناتج.
يرسم خط المؤشر الخطي خطًا متصلًا عبر نقاط البيانات في سلسلة، مما يجعله الخيار الأكثر طبيعية لإظهار الاتجاهات عبر الزمن. في Aspose.Cells، يتم إنشاء خط المؤشر الخطي بتمرير SparklineType.Line إلى طريقة sparklineGroups.add.
Workbook جديدًا وانتقل إلى ورقة العمل الأولى.CellArea يصف الخلية الهدف التي سيتم فيها رسم خط المؤشر.worksheet.sparklineGroups.add(SparklineType.Line, "A1:E1", false, dest). الوسيط الثالث — false — يخبر Aspose.Cells بأن نطاق البيانات أفقي (صف)، وليس عمودي (عمود).SparklineGroup المُعاد. لخط المؤشر الخطي، يمكنك تعيين لون الخط باستخدام group.line.color (الذي يتوقع CellsColor من Aspose.Cells.Drawing)، وضبط وزن الخط، وتبديل علامات نقاط القمة/القاع.const AsposeCells = require("aspose.cells.node");
let workbook = new AsposeCells.Workbook();
let worksheet = workbook.getWorksheets().get(0);
// Step 2: Populate sample data in row 1 (A1:E1)
worksheet.getCells().get("A1").putValue(5);
worksheet.getCells().get("B1").putValue(-3);
worksheet.getCells().get("C1").putValue(8);
worksheet.getCells().get("D1").putValue(-2);
worksheet.getCells().get("E1").putValue(6);
// Step 3: Add a Line sparkline group at F1
let lineArea = new AsposeCells.CellArea();
lineArea.startColumn = 5;
lineArea.endColumn = 5;
lineArea.startRow = 0;
lineArea.endRow = 0;
let lineIdx = worksheet.getSparklineGroups().add(AsposeCells.SparklineType.Line, "A1:E1", false, lineArea);
let lineGroup = worksheet.getSparklineGroups().get(lineIdx);
// Customize the line sparkline color via CellsColor
let lineColor = workbook.createCellsColor();
lineColor.setColor(AsposeCells.Color.Blue);
lineGroup.setSeriesColor(lineColor);
// Step 4: Add a Column sparkline group at F2
let columnArea = new AsposeCells.CellArea();
columnArea.startColumn = 5;
columnArea.endColumn = 5;
columnArea.startRow = 1;
columnArea.endRow = 1;
let columnIdx = worksheet.getSparklineGroups().add(AsposeCells.SparklineType.Column, "A1:E1", false, columnArea);
let columnGroup = worksheet.getSparklineGroups().get(columnIdx);
// Customize the column sparkline series color
let columnColor = workbook.createCellsColor();
columnColor.setColor(AsposeCells.Color.Green);
columnGroup.setSeriesColor(columnColor);
// Step 5: Add a Win/Loss (Stacked) sparkline group at F3
let stackedArea = new AsposeCells.CellArea();
stackedArea.startColumn = 5;
stackedArea.endColumn = 5;
stackedArea.startRow = 2;
stackedArea.endRow = 2;
let stackedIdx = worksheet.getSparklineGroups().add(AsposeCells.SparklineType.Stacked, "A1:E1", false, stackedArea);
let stackedGroup = worksheet.getSparklineGroups().get(stackedIdx);
// Customize the win/loss sparkline series color
let stackedColor = workbook.createCellsColor();
stackedColor.setColor(AsposeCells.Color.DarkOrange);
stackedGroup.setSeriesColor(stackedColor);
// Step 6: Save the workbook
workbook.save("output_all.xlsx");
يعرض خط المؤشر العمودي كل نقطة بيانات كشريط عمودي. وهذا يجعله مناسبًا تمامًا للبيانات التي يكون فيها المقدار ذا معنى — على سبيل المثال، أرقام المبيعات الشهرية أو العدادات. في Aspose.Cells، تُنشئ خط المؤشر العمودي بتمرير SparklineType.Column إلى طريقة sparklineGroups.add.
يتبع الإجراء مثال خط المؤشر الخطي:
Workbook جديدًا وانتقل إلى ورقة العمل الأولى.CellArea يصف الخلية الهدف.worksheet.sparklineGroups.add(SparklineType.Column, "A1:E1", false, dest).SparklineGroup الناتج — على سبيل المثال، بتعيين group.type لتأكيد النوع، أو بضبط لون الأعمدة.const AsposeCells = require("aspose.cells.node");
let workbook = new AsposeCells.Workbook();
let worksheet = workbook.getWorksheets().get(0);
worksheet.setName("WinLoss");
// Step 2: Populate sample data in row 1: A1=5, B1=-3, C1=8, D1=-2, E1=6
worksheet.getCells().get("A1").putValue(5);
worksheet.getCells().get("B1").putValue(-3);
worksheet.getCells().get("C1").putValue(8);
worksheet.getCells().get("D1").putValue(-2);
worksheet.getCells().get("E1").putValue(6);
// Step 3: Build a CellArea pointing to F1 (column 5, row 0)
let dest = new AsposeCells.CellArea();
dest.startColumn = 5; // F
dest.endColumn = 5;
dest.startRow = 0; // row 1
dest.endRow = 0;
// Step 4: Add a Win/Loss sparkline (SparklineType.Stacked)
let groupIndex = worksheet.getSparklineGroups().add(
AsposeCells.SparklineType.Stacked,
"A1:E1",
false,
dest);
let group = worksheet.getSparklineGroups().get(groupIndex);
// Step 5: Customize the sparkline group
// Enable high-point and low-point markers
group.setShowHighPoint(true);
group.setShowLowPoint(true);
group.setShowNegativePoints(true);
// Set the high-point color to green
let highColor = workbook.createCellsColor();
highColor.setColor(AsposeCells.Color.Green);
group.setHighPointColor(highColor);
// Set the low-point color to red
let lowColor = workbook.createCellsColor();
lowColor.setColor(AsposeCells.Color.Red);
group.setLowPointColor(lowColor);
// Set the negative-point color to orange
let negColor = workbook.createCellsColor();
negColor.setColor(AsposeCells.Color.Orange);
group.setNegativePointsColor(negColor);
// Set the default series color (used for positive bars)
let seriesColor = workbook.createCellsColor();
seriesColor.setColor(AsposeCells.Color.SteelBlue);
group.setSeriesColor(seriesColor);
// Step 6: Save the workbook
workbook.save("output_winloss.xlsx");
console.log("Workbook saved successfully: output_winloss.xlsx");
خط المؤشر من نوع فوز/خسارة هو تباين خاص لخط المؤشر العمودي مصمم لإظهار نتيجتين فقط: القيمة الموجبة تُرسم كشريط “أعلى” (فوز)، والقيمة الصفرية أو السالبة تُرسم كشريط “أسفل” (خسارة). تُستخدم خطوط المؤشر من نوع فوز/خسارة بشكل شائع لتصوير تتابعات الانتصارات والهزائم، أو نتائج النجاح/الفشل، أو أي نتيجة ثنائية عبر الزمن.
في Aspose.Cells، يُنشأ خط المؤشر من نوع فوز/خسارة بتمرير SparklineType.Stacked إلى طريقة sparklineGroups.add. (بالرغم من الاسم، فإن SparklineType.Stacked هو قيمة التعداد المستخدمة لطلب العرض من نوع فوز/خسارة.)
Workbook جديدًا وانتقل إلى ورقة العمل الأولى.CellArea يصف الخلية الهدف.worksheet.sparklineGroups.add(SparklineType.Stacked, "A1:E1", false, dest).SparklineGroup المُعاد، مثل تعيين ألوان مميزة لأشرطة الفوز والخسارة.const AsposeCells = require("aspose.cells.node");
let workbook = new AsposeCells.Workbook();
let worksheet = workbook.getWorksheets().get(0);
// Step 2: Write sample values into A1:E1
let values = [5, -3, 8, -2, 6];
for (let i = 0; i < values.length; i++) {
worksheet.getCells().get(0, i).putValue(values[i]);
}
// Step 3: Build a CellArea pointing to F1 (column index 5, row index 0)
let dest = new AsposeCells.CellArea();
dest.startColumn = 5;
dest.endColumn = 5;
dest.startRow = 0;
dest.endRow = 0;
// Step 4: Add a Column sparkline to the destination cell
let idx = worksheet.getSparklineGroups().add(
AsposeCells.SparklineType.Column, "A1:E1", false, dest);
let group = worksheet.getSparklineGroups().get(idx);
// Step 5: Confirm the sparkline type by reading group.Type
console.log("Sparkline Type added: " + group.getType());
// Step 6: Save the workbook
workbook.save("output_column.xlsx");
console.log("Workbook saved as output_column.xlsx");
يُنشئ المثال المدمج أدناه مصنفًا واحدًا، ويملأ الصف 1 بالقيم 5 و-3 و8 و-2 و6، ثم يُضيف ثلاث مجموعات من خطوط المؤشر في الخلايا F1 وF2 وF3 — واحدة من كل نوع — بحيث يُظهر الملف الناتج أنماط خطوط المؤشر الثلاثة جميعها دفعة واحدة.
const AsposeCells = require("aspose.cells.node");
// Step 1: Create a Workbook and get the first worksheet
const workbook = new AsposeCells.Workbook();
const worksheet = workbook.getWorksheets().get(0);
const cells = worksheet.getCells();
// Step 2: Write sample values 5, -3, 8, -2, 6 into cells A1:E1
cells.get("A1").putValue(5);
cells.get("B1").putValue(-3);
cells.get("C1").putValue(8);
cells.get("D1").putValue(-2);
cells.get("E1").putValue(6);
// Step 3: Build a CellArea pointing to destination cell F1
const dest = new AsposeCells.CellArea();
dest.startColumn = 5; // column F (0-indexed)
dest.endColumn = 5;
dest.startRow = 0; // row 1 (0-indexed)
dest.endRow = 0;
// Step 4: Add a Line sparkline from A1:E1 into F1
// SparklineGroups.Add returns the index of the newly added group
const index = worksheet.getSparklineGroups().add(AsposeCells.SparklineType.Line, "A1:E1", false, dest);
const group = worksheet.getSparklineGroups().get(index);
// Step 5: Create a red CellsColor and assign it to the sparkline line color
const red = workbook.createCellsColor();
red.setColor(AsposeCells.Color.Red);
group.setSeriesColor(red);
// Step 6: Enable high-point and low-point markers
group.setShowHighPoint(true);
group.setShowLowPoint(true);
// Step 7: Save the workbook
workbook.save("output_line.xlsx");
بمجرد إنشاء SparklineGroup وإضافته إلى worksheet.sparklineGroups، يمكنك قراءة أو تعديل عدة خصائص بصرية له قبل حفظ المصنف. أكثر الخصائص شيوعًا في التخصيص هي:
group.type — نوع SparklineType (Line أو Column أو Stacked). يُحدد عند إضافة المجموعة، ولكن يمكنك قراءته لتأكيده.group.line.color — لون الخط، يُعبر عنه كـ CellsColor يُنشأ عبر workbook.createCellsColor(). هذه هي الخاصية التي يجب استخدامها للون خط المؤشر الخطي.group.line.weight — وزن الخط بالنقاط. القيم الأكبر تنتج خطوطًا أسمك.CellsColor وعيّنها إلى الخاصية ذات الصلة. لا تُعيّن System.Drawing.Color مباشرةً إلى خصائص لون خط المؤشر — فهي تتوقع نوع CellsColor من Aspose.Cells.Drawing. طريقة sparklineGroups.add نفسها تُرجع كائن SparklineGroup مُنوعًا بالكامل، لذا يمكنك تسلسل تعيينات الخصائص على القيمة المُعادة أو تخزينها في متغير محلي وتخصيصها قبل الحفظ.Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.