كيفية إنشاء الرسوم البيانية في عرض تقديمي
دعم الشيفرة القديمة
لاستخدام الشيفرة القديمة التي تم تطويرها باستخدام Aspose.Slides for Java بالإصدارات التي تسبق 14.x.x، تحتاج إلى إجراء بعض التغييرات الطفيفة في الشيفرة الخاصة بك وستعمل الشيفرة كما كانت في السابق. جميع الفئات التي كانت موجودة في Aspose.Slides for Java القديمة تحت المساحتي com.aspose.slides و com.aspose.slides.pptx تم دمجها الآن في مساحة أسماء واحدة com.aspose.slides. يرجى إلقاء نظرة على مقتطف الشيفرة البسيط التالي لإنشاء رسم بياني عادي من الصفر في عرض تقديمي باستخدام واجهة برمجة التطبيقات القديمة لـ Aspose.Slides واتباع الخطوات التي تصف كيفية الانتقال إلى واجهة برمجة التطبيقات الجديدة المدمجة.
النهج القديم لـ Aspose.Slides for Java
//Instantiate PresentationEx class that represents PPTX file | |
PresentationEx pres = new PresentationEx(); | |
//Access first slide | |
SlideEx sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
ChartEx chart = sld.getShapes().addChart(ChartTypeEx.ClusteredColumn, 0, 0, 500, 500); | |
//Setting chart Title | |
chart.getChartTitle().getText().setText("Sample Title"); | |
chart.getChartTitle().getText().setCenterText(true); | |
chart.getChartTitle().setHeight(20f); | |
chart.hasTitle(true); | |
//Set first series to Show Values | |
chart.getChartData().getSeries().get_Item(0).getLabels().setShowValue(true); | |
//Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
//Getting the chart data worksheet | |
ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory(); | |
//Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
int s = chart.getChartData().getSeries().getCapacity(); | |
//Adding new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType()); | |
//Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); | |
//Take first chart series | |
ChartSeriesEx series = chart.getChartData().getSeries().get_Item(0); | |
//Now populating series data | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 1, 1, 20)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 2, 1, 50)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 3, 1, 30)); | |
//Setting fill color for series | |
series.getFormat().getFill().setFillType(FillTypeEx.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(new java.awt.Color(com.aspose.slides.PresetColorEx.Red)); | |
//Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
//Now populating series data | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 1, 2, 30)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 2, 2, 10)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 3, 2, 60)); | |
//Setting fill color for series | |
series.getFormat().getFill().setFillType(FillTypeEx.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(new java.awt.Color(PresetColorEx.Green)); | |
//create custom lables for each of categories for new series | |
//first label will be show Category name | |
DataLabelEx lbl = new DataLabelEx(series); | |
lbl.setShowCategoryName( true); | |
lbl.setId (0); | |
series.getLabels().add(lbl); | |
//Show series name for second label | |
lbl = new DataLabelEx(series); | |
lbl.setShowSeriesName(true); | |
lbl.setId(1); | |
series.getLabels().add(lbl); | |
//show value for third label | |
lbl = new DataLabelEx(series); | |
lbl.setShowValue(true); | |
lbl.setShowSeriesName(true); | |
lbl.setSeparator("/"); | |
lbl.setId( 2); | |
series.getLabels().add(lbl); | |
// show value and custom text | |
lbl = new DataLabelEx(series); | |
lbl.getTextFrame().setText( "My text"); | |
lbl.setId( 3); | |
series.getLabels().add(lbl); | |
// Save presentation with chart | |
pres.write("D:\\Aspose Data\\AsposeChart.pptx"); |
النهج الجديد لـ Aspose.Slides for Java 14.x.x
//Instantiate Presentation class that represents PPTX file | |
Presentation pres = new Presentation(); | |
//Access first slide | |
ISlide sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
IChart chart = sld.getShapes().addChart(ChartType.ClusteredColumn, 0, 0, 500, 500); | |
//Setting chart Title | |
//chart.getChartTitle().TextFrameForOverriding.Text = "Sample Title"; | |
chart.getChartTitle().addTextFrameForOverriding("Sample Title"); | |
chart.getChartTitle().getTextFrameForOverriding().getTextFrameFormat().setCenterText(NullableBool.True); | |
chart.getChartTitle().setHeight(20); | |
chart.hasTitle(true); | |
//Set first series to Show Values | |
chart.getChartData().getSeries().get_Item(0).getLabels().getDefaultDataLabelFormat().setShowValue(true); | |
//Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
//Getting the chart data worksheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
//Delete default generated series and categories | |
chart.getChartData().getSeries().clear(); | |
chart.getChartData().getCategories().clear(); | |
int s = chart.getChartData().getSeries().size(); | |
s = chart.getChartData().getCategories().size(); | |
//Adding new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 2, "Series 2"), chart.getType()); | |
//Adding new categories | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 1, 0, "Caetegoty 1")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 2, 0, "Caetegoty 2")); | |
chart.getChartData().getCategories().add(fact.getCell(defaultWorksheetIndex, 3, 0, "Caetegoty 3")); | |
//Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
//Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 1, 20)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 50)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 30)); | |
//Setting fill color for series | |
series.getFormat().getFill().setFillType(FillType.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.RED); | |
//Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
//Now populating series data | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 1, 2, 30)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 2, 2, 10)); | |
series.getDataPoints().addDataPointForBarSeries(fact.getCell(defaultWorksheetIndex, 3, 2, 60)); | |
//Setting fill color for series | |
series.getFormat().getFill().setFillType(FillType.Solid); | |
series.getFormat().getFill().getSolidFillColor().setColor(java.awt.Color.GREEN); | |
//create custom labels for each of categories for new series | |
//first label will be show Category name | |
IDataLabel lbl = series.getDataPoints().get_Item(0).getLabel(); | |
lbl.getDataLabelFormat().setShowCategoryName(true); | |
lbl = series.getDataPoints().get_Item(1).getLabel(); | |
lbl.getDataLabelFormat().setShowSeriesName(true); | |
//Show value for third label | |
lbl = series.getDataPoints().get_Item(2).getLabel(); | |
lbl.getDataLabelFormat().setShowValue(true); | |
lbl.getDataLabelFormat().setShowSeriesName(true); | |
lbl.getDataLabelFormat().setSeparator("/"); | |
//Save presentation with chart | |
pres.save("AsposeChart.pptx",SaveFormat.Pptx); |
يرجى إلقاء نظرة على مقتطف الشيفرة البسيط التالي لإنشاء رسم بياني متفرق من الصفر في عرض تقديمي باستخدام واجهة برمجة التطبيقات القديمة لـ Aspose.Slides وكيفية تحقيق ذلك باستخدام واجهة برمجة التطبيقات الجديدة المدمجة.
النهج القديم لـ Aspose.Slides for Java
//Instantiate PresentationEx class that represents PPTX file | |
PresentationEx pres = new PresentationEx("D:\\AsposeChart.pptx"); | |
//Access first slide | |
SlideEx sld = pres.getSlides().get_Item(0); | |
// Add chart with default data | |
ChartEx chart = (ChartEx)sld.getShapes().get_Item(0); | |
//Setting the index of chart data sheet | |
int defaultWorksheetIndex = 0; | |
//Getting the chart data worksheet | |
ChartDataCellFactory fact = chart.getChartData().getChartDataCellFactory(); | |
//Take first chart series | |
ChartSeriesEx series = chart.getChartData().getSeries().getItem(0); | |
//Now updating series data | |
fact.getCell(defaultWorksheetIndex, 0, 1, "New_Series1");//modifying series name | |
series.getValues().get_Item(0).setValue(90); | |
series.getValues().get_Item(1).setValue(123); | |
series.getValues().get_Item(2).setValue(44); | |
//Take Second chart series | |
series = chart.getChartData().getSeries().getItem(1); | |
//Now updating series data | |
fact.getCell(defaultWorksheetIndex, 0, 2, "New_Series2");//modifying series name | |
series.getValues().get_Item(0).setValue(23); | |
series.getValues().get_Item(1).setValue(67); | |
series.getValues().get_Item(2).setValue(99); | |
//Now, Adding a new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 0, 3, "Series 3"), chart.getType()); | |
//Take 3rd chart series | |
series = chart.getChartData().getSeries().getItem(2); | |
//Now populating series data | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 1, 3, 20)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 2, 3, 50)); | |
series.getValues().add(fact.getCell(defaultWorksheetIndex, 3, 3, 30)); | |
chart.setType(ChartTypeEx.ClusteredCylinder); | |
// Save presentation with chart | |
pres.write("D:\\AsposeChartMoodified.pptx"); |
النهج الجديد لـ Aspose.Slides for Java 14.x.x
Presentation pres = new Presentation(); | |
ISlide slide = pres.getSlides().get_Item(0); | |
//Creating the default chart | |
IChart chart = slide.getShapes().addChart(ChartType.ScatterWithSmoothLines, 0, 0, 400, 400); | |
//Getting the default chart data worksheet index | |
int defaultWorksheetIndex = 0; | |
//Accessing the chart data worksheet | |
IChartDataWorkbook fact = chart.getChartData().getChartDataWorkbook(); | |
//Delete demo series | |
chart.getChartData().getSeries().clear(); | |
//Add new series | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 1, "Series 1"), chart.getType()); | |
chart.getChartData().getSeries().add(fact.getCell(defaultWorksheetIndex, 1, 3, "Series 2"), chart.getType()); | |
//Take first chart series | |
IChartSeries series = chart.getChartData().getSeries().get_Item(0); | |
//Add new point (1:3) there. | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 2, 1, 1), fact.getCell(defaultWorksheetIndex, 2, 2, 3)); | |
//Add new point (2:10) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 3, 1, 2), fact.getCell(defaultWorksheetIndex, 3, 2, 10)); | |
//Edit the type of series | |
series.setType (ChartType.ScatterWithStraightLinesAndMarkers); | |
//Changing the chart series marker | |
series.getMarker().setSize(10); | |
series.getMarker().setSymbol(MarkerStyleType.Star); | |
//Take second chart series | |
series = chart.getChartData().getSeries().get_Item(1); | |
//Add new point (5:2) there. | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 2, 3, 5), fact.getCell(defaultWorksheetIndex, 2, 4, 2)); | |
//Add new point (3:1) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 3, 3, 3), fact.getCell(defaultWorksheetIndex, 3, 4, 1)); | |
//Add new point (2:2) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 4, 3, 2), fact.getCell(defaultWorksheetIndex, 4, 4, 2)); | |
//Add new point (5:1) | |
series.getDataPoints().addDataPointForScatterSeries(fact.getCell(defaultWorksheetIndex, 5, 3, 5), fact.getCell(defaultWorksheetIndex, 5, 4, 1)); | |
//Changing the chart series marker | |
series.getMarker().setSize(10); | |
series.getMarker().setSymbol (MarkerStyleType.Circle); | |
pres.save("AsposeScatterChart.pptx",SaveFormat.Pptx); |