تنسيق الرسم البياني
ضبط مظهر الرسم البياني
في أنواع الرسوم البيانية ، قدمنا مقدمة موجزة لأنواع الرسوم البيانية وكائنات الرسم البياني التي تقدمها Aspose.Cells.
في هذه المقالة، نناقش كيفية تخصيص مظهر الرسوم البيانية عن طريق تعيين عدد من الخصائص المختلفة:
- ضبط منطقة الرسم البياني.
- ضبط خطوط الرسم البياني.
- تطبيق السمات.
- ضبط عناوين الرسوم البيانية والمحاور.
- العمل مع خطوط الشبكة.
- ضبط حدود الجدران الخلفية والجانبية.
تعيين منطقة الرسم البياني
هناك أنواع مختلفة من المناطق في الرسم البياني وتوفر Aspose.Cells مرونة تعديل مظهر كل منطقة. يمكن للمطورين تطبيق إعدادات تنسيق مختلفة على منطقة عن طريق تغيير لون الخلفية ولون الخلفية وتنسيق الملء وما إلى ذلك.
في المثال الوارد أدناه، قمنا بتطبيق إعدادات تنسيق مختلفة على أنواع مختلفة من المناطق في رسم بياني. هذه المناطق تشمل:
- منطقة الرسم
- منطقة الرسم البياني
- منطقة SeriesCollection
- منطقة نقطة واحدة في SeriesCollection
بعد تنفيذ كود المثال، سيتم إضافة رسم بياني للعمود إلى ورقة العمل كما هو موضح أدناه:
رسم بياني للعمود مع مناطق مملوءة
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingChartArea.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
// Obtaining the reference of the newly added worksheet by passing its | |
// sheet index | |
Worksheet worksheet = worksheets.get(0); | |
Cells cells = worksheet.getCells(); | |
// Adding a sample value to "A1" cell | |
cells.get("A1").setValue(50); | |
// Adding a sample value to "A2" cell | |
cells.get("A2").setValue(100); | |
// Adding a sample value to "A3" cell | |
cells.get("A3").setValue(150); | |
// Adding a sample value to "B1" cell | |
cells.get("B1").setValue(60); | |
// Adding a sample value to "B2" cell | |
cells.get("B2").setValue(32); | |
// Adding a sample value to "B3" cell | |
cells.get("B3").setValue(50); | |
// Adding a chart to the worksheet | |
ChartCollection charts = worksheet.getCharts(); | |
// Accessing the instance of the newly added chart | |
int chartIndex = charts.add(ChartType.COLUMN, 5, 0, 15, 7); | |
Chart chart = charts.get(chartIndex); | |
// Adding NSeries (chart data source) to the chart ranging from "A1" | |
// cell | |
SeriesCollection nSeries = chart.getNSeries(); | |
nSeries.add("A1:B3", true); | |
// Setting the foreground color of the plot area | |
ChartFrame plotArea = chart.getPlotArea(); | |
Area area = plotArea.getArea(); | |
area.setForegroundColor(Color.getBlue()); | |
// Setting the foreground color of the chart area | |
ChartArea chartArea = chart.getChartArea(); | |
area = chartArea.getArea(); | |
area.setForegroundColor(Color.getYellow()); | |
// Setting the foreground color of the 1st NSeries area | |
Series aSeries = nSeries.get(0); | |
area = aSeries.getArea(); | |
area.setForegroundColor(Color.getRed()); | |
// Setting the foreground color of the area of the 1st NSeries point | |
ChartPointCollection chartPoints = aSeries.getPoints(); | |
ChartPoint point = chartPoints.get(0); | |
point.getArea().setForegroundColor(Color.getCyan()); | |
// Save the Excel file | |
workbook.save(dataDir + "SettingChartArea_out.xls"); | |
// Print message | |
System.out.println("ChartArea is settled successfully."); |
تعيين خطوط الرسم البياني
يمكن للمطورين أيضًا تطبيق أنواع مختلفة من الأنماط على الخطوط أو علامات البيانات لـ SeriesCollection كما هو موضح أدناه في المثال. تنفيذ كود المثال يضيف رسم بياني لورقة العمل كما هو موضح أدناه:
رسم بياني للأعمدة بعد تطبيق أنماط الخطوط
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingChartLines.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
// Obtaining the reference of the newly added worksheet by passing its | |
// sheet index | |
Worksheet worksheet = worksheets.get(0); | |
Cells cells = worksheet.getCells(); | |
// Adding a chart to the worksheet | |
ChartCollection charts = worksheet.getCharts(); | |
Chart chart = charts.get(0); | |
// Adding NSeries (chart data source) to the chart ranging from "A1" | |
// cell | |
SeriesCollection nSeries = chart.getNSeries(); | |
nSeries.add("A1:B3", true); | |
Series aSeries = nSeries.get(0); | |
Line line = aSeries.getSeriesLines(); | |
line.setStyle(LineType.DOT); | |
// Applying a triangular marker style on the data markers of an NSeries | |
aSeries.getMarker().setMarkerStyle(ChartMarkerType.TRIANGLE); | |
// Setting the weight of all lines in an NSeries to medium | |
aSeries = nSeries.get(1); | |
line = aSeries.getSeriesLines(); | |
line.setWeight(WeightType.MEDIUM_LINE); | |
// Save the Excel file | |
workbook.save(dataDir + "SettingChartLines_out.xls"); | |
// Print message | |
System.out.println("ChartArea is settled successfully."); |
تطبيق سمات مايكروسوفت اكسيل 2007/2010 على الرسوم البيانية
يمكن للمطورين تطبيق ثيمات وألوان مايكروسوفت إكسيل المختلفة على SeriesCollection أو كائنات الرسم البياني الأخرى كما هو موضح في المثال أدناه.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ApplyingThemes.class) + "charts/"; | |
// Instantiate the workbook to open the file that contains a chart | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Get the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Get the first chart in the sheet | |
Chart chart = worksheet.getCharts().get(0); | |
// Specify the FilFormat's type to Solid Fill of the first series | |
chart.getNSeries().get(0).getArea().getFillFormat().setFillType(FillType.SOLID); | |
// Get the CellsColor of SolidFill | |
CellsColor cc = chart.getNSeries().get(0).getArea().getFillFormat().getSolidFill().getCellsColor(); | |
// Create a theme in Accent style | |
cc.setThemeColor(new ThemeColor(ThemeColorType.ACCENT_6, 0.6)); | |
// Apply the them to the series | |
chart.getNSeries().get(0).getArea().getFillFormat().getSolidFill().setCellsColor(cc); | |
// Save the Excel file | |
workbook.save(dataDir + "AThemes_out.xlsx"); |
ضبط عناوين الرسوم البيانية أو المحاور
يمكنك استخدام مايكروسوفت إكسيل لتعيين عناوين لرسم بياني ومحاوره في بيئة WYSIWYG كما هو موضح أدناه:
تعيين عناوين لرسم بياني & محاوره باستخدام مايكروسوفت إكسيل
تسمح Aspose.Cells أيضًا للمطورين بتعيين عناوين لرسم بياني ومحاوره عند التشغيل. تحتوي جميع الرسوم البيانية ومحاورها على طريقة Title.setText يمكن استخدامها لتعيين عناوينها كما هو موضح أدناه في مثال. بعد تنفيذ كود المثال، سيتم إضافة رسم بياني للعمود إلى ورقة العمل كما هو موضح أدناه:
رسم بياني للأعمدة بعد تعيين العناوين
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(SettingTitlesAxes.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
// Obtaining the reference of the newly added worksheet by passing its | |
// sheet index | |
Worksheet worksheet = worksheets.get(0); | |
Cells cells = worksheet.getCells(); | |
// Adding a chart to the worksheet | |
ChartCollection charts = worksheet.getCharts(); | |
// Accessing the instance of the newly added chart | |
int chartIndex = charts.add(ChartType.COLUMN, 5, 0, 15, 7); | |
Chart chart = charts.get(chartIndex); | |
// Setting the title of a chart | |
Title title = chart.getTitle(); | |
title.setText("ASPOSE"); | |
// Setting the font color of the chart title to blue | |
Font font = title.getFont(); | |
font.setColor(Color.getBlue()); | |
// Setting the title of category axis of the chart | |
Axis categoryAxis = chart.getCategoryAxis(); | |
title = categoryAxis.getTitle(); | |
title.setText("Category"); | |
// Setting the title of value axis of the chart | |
Axis valueAxis = chart.getValueAxis(); | |
title = valueAxis.getTitle(); | |
title.setText("Value"); | |
// Adding NSeries (chart data source) to the chart ranging from "A1" | |
// cell | |
SeriesCollection nSeries = chart.getNSeries(); | |
nSeries.add("A1:B3", true); | |
// Setting the foreground color of the plot area | |
ChartFrame plotArea = chart.getPlotArea(); | |
Area area = plotArea.getArea(); | |
area.setForegroundColor(Color.getBlue()); | |
// Setting the foreground color of the chart area | |
ChartArea chartArea = chart.getChartArea(); | |
area = chartArea.getArea(); | |
area.setForegroundColor(Color.getYellow()); | |
// Setting the foreground color of the 1st NSeries area | |
Series aSeries = nSeries.get(0); | |
area = aSeries.getArea(); | |
area.setForegroundColor(Color.getRed()); | |
// Setting the foreground color of the area of the 1st NSeries point | |
ChartPointCollection chartPoints = aSeries.getPoints(); | |
ChartPoint point = chartPoints.get(0); | |
point.getArea().setForegroundColor(Color.getCyan()); | |
// Save the Excel file | |
workbook.save(dataDir + "SettingTitlesAxes_out.xls"); | |
// Print message | |
System.out.println("Chart Title is changed successfully."); |
تعيين خطوط الشبكة الرئيسية
إخفاء خطوط الشبكة الرئيسية
يمكن للمطورين التحكم في رؤية خطوط الشبكة الرئيسية عن طريق استخدام طريقة setVisible في كائن Line. بعد إخفاء خطوط الشبكة الرئيسية، يظهر الرسم البياني العمودي المضاف إلى ورقة العمل بالمظهر التالي:
رسم بياني عمودي مع خطوط شبكة رئيسية مخفية
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Hiding the major gridlines of value axis | |
Axis valueAxis = chart.getValueAxis(); | |
Line majorGridLines = valueAxis.getMajorGridLines(); | |
majorGridLines.setVisible(false); |
تغيير إعدادات خطوط الشبكة الرئيسية
لا يمكن للمطورين فقط التحكم في رؤية خطوط الشبكة الرئيسية ولكن أيضًا خصائص أخرى بما في ذلك لونها وما إلى ذلك. بعد تعيين لون خطوط الشبكة الرئيسية، سيكون الرسم البياني العمودي المضاف إلى ورقة العمل بالمظهر التالي:
رسم بياني عمودي مع خطوط شبكة رئيسية ملونة
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Setting the color of major gridlines of value axis to silver | |
Axis categoryAxis = chart.getCategoryAxis(); | |
categoryAxis.getMajorGridLines().setColor(Color.getSilver()); |
تعيين حدود للجدران الخلفية والجانبية
منذ إصدار Microsoft Excel 2007، تم تقسيم جدران الرسم البياني ثلاثي الأبعاد إلى قسمين: الجدار الجانبي والجدار الخلفي، لذا يجب علينا استخدام كائنين Walls لتمثيلهما على حدة ويمكنك الوصول إليهما من خلال استخدام Chart.getBackWall() و Chart.getSideWall().
المثال أدناه يوضح كيفية تعيين حدود الجدار الجانبي باستخدام سمات مختلفة.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// Get the side wall border line | |
Line sideLine = chart.getSideWall().getBorder(); | |
// Make it visible | |
sideLine.setVisible(true); | |
// Set the solid line | |
sideLine.setStyle(LineType.SOLID); | |
// Set the line width | |
sideLine.setWeight(10); | |
// Set the color | |
sideLine.setColor(Color.getBlack()); |
تغيير موقع الرسم البياني وحجمه
في بعض الأحيان، قد ترغب في تغيير الموضع أو الحجم للرسم البياني الجديد أو القائم داخل ورقة العمل. توفر Aspose.Cells الخاصية Chart.getChartObject() لتحقيق ذلك. يمكنك استخدام خصائصه الفرعية لإعادة تحجيم الرسم البياني بارتفاع وعرض جديدين أو إعادة تمركزه بإحداثيات X و Y جديدة.
تعديل موقع وحجم الرسم البياني
لتغيير موقع الرسم البياني (إحداثيات X و Y) وحجمه (ارتفاع وعرض)، استخدم هذه الخصائص:
- Chart.getChartObject().get/setWidth()
- Chart.getChartObject().get/setHeight()
- Chart.getChartObject().get/setX()
- Chart.getChartObject().get/setY()
المثال التالي يشرح كيفية استخدام الخصائص أعلاه. يحمل الدفتر العمل الموجود الذي يحتوي على رسم بياني في ورقته الأولى. ثم يقوم بإعادة تحجيم وإعادة تمركز الرسم البياني ويحفظ الدفتر العمل.
قبل تنفيذ كود العينة، يبدو الملف الأصلي على النحو التالي:
حجم الرسم البياني وموضعه قبل تنفيذ رمز العينة
بعد التنفيذ، يبدو ملف الإخراج هكذا:
حجم وموقع الرسم البياني بعد تنفيذ الشفرة المثالية
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ChangeChartPositionAndSize.class) + "charts/"; | |
String filePath = dataDir + "book1.xls"; | |
Workbook workbook = new Workbook(filePath); | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Load the chart from source worksheet | |
Chart chart = worksheet.getCharts().get(0); | |
// Resize the chart | |
chart.getChartObject().setWidth(400); | |
chart.getChartObject().setHeight(300); | |
// Reposition the chart | |
chart.getChartObject().setX(250); | |
chart.getChartObject().setY(150); | |
// Output the file | |
workbook.save(dataDir + "ChangeChartPositionAndSize_out.xls"); | |
// Print message | |
System.out.println("Position and Size of Chart is changed successfully."); |
تلاعب الرسوم البيانية للمصمم
هناك وقت قد تحتاج فيه إلى تلاعب أو تعديل الرسومات في ملفات القوالب المصممة. Aspose.Cells تدعم بشكل كامل تلاعب الرسومات المصممة مع محتوياتها وعناصرها. يمكن الحفاظ على البيانات ومحتويات الرسم البياني وصورة الخلفية والتنسيق بدقة.
تلاعب برسومات المصمم في ملفات القوالب
لتلاعب برسومات المصمم في ملف القالب، استخدم جميع المكالمات البرمجية ذات الصلة بالرسم البياني. على سبيل المثال، استخدم خاصية Worksheet.getCharts للحصول على مجموعة الرسوم البيانية الحالية في ملف القالب.
إنشاء رسم بياني
المثال التالي يوضح كيفية إنشاء رسم بياني دائري. سنقوم لاحقًا بتلاعب في هذا الرسم البياني. الإخراج التالي مولّد بواسطة الشفرة.
تم تعديل رسم الكعكة
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(CreateChart.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
// Obtaining the reference of the first worksheet | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet sheet = worksheets.get(0); | |
// Adding some sample value to cells | |
Cells cells = sheet.getCells(); | |
Cell cell = cells.get("A1"); | |
cell.setValue(50); | |
cell = cells.get("A2"); | |
cell.setValue(100); | |
cell = cells.get("A3"); | |
cell.setValue(150); | |
cell = cells.get("B1"); | |
cell.setValue(4); | |
cell = cells.get("B2"); | |
cell.setValue(20); | |
cell = cells.get("B3"); | |
cell.setValue(50); | |
ChartCollection charts = sheet.getCharts(); | |
// Adding a chart to the worksheet | |
int chartIndex = charts.add(ChartType.PYRAMID, 5, 0, 15, 5); | |
Chart chart = charts.get(chartIndex); | |
// Adding NSeries (chart data source) to the chart ranging from "A1" | |
// cell to "B3" | |
SeriesCollection serieses = chart.getNSeries(); | |
serieses.add("A1:B3", true); | |
// Saving the Excel file | |
workbook.save(dataDir + "CreateChart_out.xls"); | |
// Print message | |
System.out.println("Workbook with chart is successfully created."); |
تلاعب الرسم البياني
المثال التالي يوضح كيفية تلاعب الرسم البياني الحالي. في هذا المثال نقوم بتعديل الرسم البياني الذي تم إنشاؤه أعلاه. الإخراج التالي مولّد بواسطة الشفرة. لاحظ أن لون عنوان الرسم البياني تغير من الأزرق إلى الأسود، وتغير ‘إنجلترا 30000’ إلى ‘المملكة المتحدة، 30 ألف’.
تم تعديل رسم الكعكة
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ModifyPieChart.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "ModifyCharts.xlsx"); | |
// Obtaining the reference of the first worksheet | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet sheet = worksheets.get(1); | |
// Load the chart from source worksheet | |
Chart chart = sheet.getCharts().get(0); | |
DataLabels datalabels = chart.getNSeries().get(0).getPoints().get(0).getDataLabels(); | |
datalabels.setText("aspose"); | |
// Saving the Excel file | |
workbook.save(dataDir + "ModifyPieChart_out.xls"); | |
// Print message | |
System.out.println("Pie chart is successfully modified."); |
تلاعب رسم بياني الخط في القالب المصمم
في هذا المثال، سنقوم بتلاعب رسم بياني خطي. سنضيف بعض سلاسل البيانات إلى الرسم البياني الحالي وتغيير ألوان خطوطها.
أولاً، دعنا نلقي نظرة على رسم البياني الخطي المصمم.
تم تعديل رسم البياني الخطي
الآن نقوم بتلاعب في رسم البياني الخطي (الموجود في ملف linechart.xls) باستخدام الشفرة التالية. الإخراج التالي مولّد بواسطة الشفرة.
تم تعديل رسم البياني الخطي
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(ModifyLineChart.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(dataDir + "book1.xls"); | |
// Obtaining the reference of the first worksheet | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
Worksheet sheet = worksheets.get(0); | |
// Load the chart from source worksheet | |
Chart chart = sheet.getCharts().get(0); | |
// Adding NSeries (chart data source) to the chart ranging from "A1" | |
// cell to "B3" | |
SeriesCollection serieses = chart.getNSeries(); | |
serieses.add("{20,40,90}", true); | |
serieses.add("{110,70,220}", true); | |
// Saving the Excel file | |
workbook.save(dataDir + "ModifyLineChart_out.xls"); | |
// Print message | |
System.out.println("Line chart is successfully modified."); |
استخدام الشرائط
يمكن لبرنامج Microsoft Excel 2010 تحليل المعلومات بطرق أكثر من أي وقت مضى. يسمح للمستخدمين بتتبع وتسليط الضوء على اتجاهات البيانات المهمة باستخدام أدوات تحليل البيانات والرؤية الجديدة. الشرائط هي رسومات مصغرة يمكنك وضعها داخل الخلايا بحيث يمكنك عرض البيانات والرسم البياني على الجدول نفسه. عند استخدام الشرائط بشكل صحيح، يكون تحليل البيانات أسرع وأكثر دقة. كما أنها توفر رؤية بسيطة للمعلومات، مما يجنب ورقات العمل المزدحمة بالرسوم البيانية الكثيرة.
توفر Aspose.Cells واجهة برمجة التطبيقات للتلاعب في الشرائط في جداول البيانات.
الشرائط في Microsoft Excel
لإدراج الشرائط في Microsoft Excel 2010:
- حدد الخلايا التي ترغب في ظهور الشرائط فيها. لجعلها سهلة الرؤية، حدد الخلايا على جانب البيانات.
- انقر على Insert في الشريط واختر column في Sparklines.
- حدد أو أدخل نطاق الخلايا في ورقة العمل التي تحتوي على بيانات المصدر. ستظهر الرسوم البيانية.
تساعد التأثيرات البصرية الصغيرة في رؤية الاتجاهات، على سبيل المثال، أو سجل الفوز أو الخسارة لرابطة الكرة اللينة. يمكن للتأثيرات البصرية الصغيرة حتى تلخص موسم كل فريق في الرابطة بأكمله.
شرائط البيانات باستخدام Aspose.Cells
يمكن للمطورين إنشاء، حذف أو قراءة التأثيرات البصرية الصغيرة (في ملف القالب) باستخدام واجهة برمجة التطبيقات المقدمة بواسطة Aspose.Cells. من خلال إضافة رسومات مخصصة لنطاق البيانات المعطى، يحظى المطورون بحرية إضافة أنواع مختلفة من الرسوم البيانية الصغيرة إلى مناطق الخلايا المحددة.
يوضح المثال أدناه ميزة شرائط البيانات. يوضح المثال كيفية:
- فتح ملف قالب بسيط.
- قراءة معلومات شرائط البيانات لورقة عمل.
- إضافة شرائط بيانات جديدة لنطاق بيانات معطى إلى منطقة خلية.
- حفظ ملف Excel إلى القرص.
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(UsingSparklines.class) + "charts/"; | |
// Instantiating a Workbook object | |
Workbook workbook = new Workbook(); | |
WorksheetCollection worksheets = workbook.getWorksheets(); | |
// Obtaining the reference of the first worksheet | |
Worksheet worksheet = worksheets.get(0); | |
Cells cells = worksheet.getCells(); | |
System.out.println("Sparkline count: " + worksheet.getSparklineGroupCollection().getCount()); | |
for (int i = 0; i < worksheet.getSparklineGroupCollection().getCount(); i++) { | |
SparklineGroup g = worksheet.getSparklineGroupCollection().get(i); | |
System.out.println("sparkline group: type:" + g.getType()); | |
for (int j = 0; j < g.getSparklineCollection().getCount(); i++) { | |
Sparkline gg = g.getSparklineCollection().get(i); | |
System.out.println("sparkline: row:" + gg.getRow() + ", col:" + gg.getColumn() + ", dataRange:" | |
+ gg.getDataRange()); | |
} | |
} | |
// Add Sparklines | |
// Define the CellArea D2:D10 | |
CellArea ca = new CellArea(); | |
ca.StartColumn = 4; | |
ca.EndColumn = 4; | |
ca.StartRow = 1; | |
ca.EndRow = 7; | |
int idx = worksheet.getSparklineGroupCollection().add(SparklineType.COLUMN, "Sheet1!B2:D8", false, ca); | |
SparklineGroup group = worksheet.getSparklineGroupCollection().get(idx); | |
// Create CellsColor | |
CellsColor clr = workbook.createCellsColor(); | |
clr.setColor(Color.getChocolate()); | |
group.setSeriesColor(clr); | |
workbook.save(dataDir + "UsingSparklines_out.xls"); | |
// Print message | |
System.out.println("Workbook with chart is created successfully."); |
تطبيق تنسيق ثلاثي الأبعاد على الرسم البياني
قد تحتاج إلى أنماط الرسوم البيانية ثلاثية الأبعاد حتى تحصل على النتائج المناسبة لسيناريو الخاص بك. توفر واجهات برمجة التطبيقات لـ Aspose.Cells الواجهة البرمجية ذات الصلة لتطبيق التنسيق ثلاثي الأبعاد لـ Microsoft Excel 2007 كما هو موضح في هذا المقال.
تحديد تنسيق ثلاثي الأبعاد للرسم البياني
يتضمن المثال الكامل أدناه لتوضيح كيفية إنشاء رسم بياني وتطبيق تنسيق ثلاثي الأبعاد لـ Microsoft Excel 2007. بعد تنفيذ رمز المثال أعلاه، سيتم إضافة رسم بياني عمودي (برؤوس ثلاثية الأبعاد) إلى ورقة العمل كما هو موضح أدناه.
رسم بياني عمودي بتنسيق ثلاثي الأبعاد
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(Applying3DFormat.class) + "charts/"; | |
// Instantiate a new Workbook | |
Workbook book = new Workbook(); | |
// Add a Data Worksheet | |
Worksheet dataSheet = book.getWorksheets().add("DataSheet"); | |
// Add Chart Worksheet | |
Worksheet sheet = book.getWorksheets().add("MyChart"); | |
// Put some values into the cells in the data worksheet | |
dataSheet.getCells().get("B1").putValue(1); | |
dataSheet.getCells().get("B2").putValue(2); | |
dataSheet.getCells().get("B3").putValue(3); | |
dataSheet.getCells().get("A1").putValue("A"); | |
dataSheet.getCells().get("A2").putValue("B"); | |
dataSheet.getCells().get("A3").putValue("C"); | |
// Define the Chart Collection | |
ChartCollection charts = sheet.getCharts(); | |
// Add a Column chart to the Chart Worksheet | |
int chartSheetIdx = charts.add(ChartType.COLUMN, 5, 0, 25, 15); | |
// Get the newly added Chart | |
Chart chart = book.getWorksheets().get(2).getCharts().get(0); | |
// Set the background/foreground color for PlotArea/ChartArea | |
chart.getPlotArea().getArea().setBackgroundColor(Color.getWhite()); | |
chart.getChartArea().getArea().setBackgroundColor(Color.getWhite()); | |
chart.getPlotArea().getArea().setForegroundColor(Color.getWhite()); | |
chart.getChartArea().getArea().setForegroundColor(Color.getWhite()); | |
// Hide the Legend | |
chart.setShowLegend(false); | |
// Add Data Series for the Chart | |
chart.getNSeries().add("DataSheet!B1:B3", true); | |
// Specify the Category Data | |
chart.getNSeries().setCategoryData("DataSheet!A1:A3"); | |
// Get the Data Series | |
Series ser = chart.getNSeries().get(0); | |
// Apply the 3D formatting | |
ShapePropertyCollection spPr = ser.getShapeProperties(); | |
Format3D fmt3d = spPr.getFormat3D(); | |
// Specify Bevel with its height/width | |
Bevel bevel = fmt3d.getTopBevel(); | |
bevel.setType(BevelPresetType.CIRCLE); | |
bevel.setHeight(5); | |
bevel.setWidth(9); | |
// Specify Surface material type | |
fmt3d.setSurfaceMaterialType(PresetMaterialType.WARM_MATTE); | |
// Specify surface lighting type | |
fmt3d.setSurfaceLightingType(LightRigType.THREE_POINT); | |
// Specify lighting angle | |
fmt3d.setLightingAngle(20); | |
// Specify Series background/foreground and line color | |
ser.getArea().setBackgroundColor(Color.getMaroon()); | |
ser.getArea().setForegroundColor(Color.getMaroon()); | |
ser.getBorder().setColor(Color.getMaroon()); | |
// Save the Excel file | |
book.save(dataDir + "A3DFormat_out.xls"); | |
// Print message | |
System.out.println("3D format is applied successfully."); |