إنشاء مخطط شلال المياه
Contents
[
Hide
]
مخطط شلال المياه هو نوع خاص من المخطط يستخدم عادة لإظهار كيفية زيادة أو انخفاض الوضع الابتدائي. تحتوي Microsoft Excel على العديد من أنواع المخططات المحددة مسبقًا، بما في ذلك العمود والخط والدائري والشريطي والراداري، وما إلى ذلك، ولكن مخطط شلال المياه يتجاوز الرسوم البيانية الأساسية ويمكن إنشاؤه باستخدام أنواع المخططات الحالية مع التخصيص القليل أو الكبير.
إنشاء مخطط شلال المياه
تسمح APIs Aspose.Cells بإنشاء مخطط شلال المياه بمساعدة مخطط خطي. كما تسمح الواجهة البرمجية أيضًا بتخصيص مظهر المخطط لإعطائه شكل شلال عن طريق ضبط الخصائص الأكثر أهمية لتشكيل المخطط، وهي الخصائص Series.UpBars و Series.DownBars.
يوضح مقتطف الكود المقدم أدناه استخدام واجهة برمجة التطبيقات Aspose.Cells for Java لإنشاء مخطط شلال المياه من البداية.
كود جافا لإنشاء مخطط الشلال المائي
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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.getDataDir(CreateWaterfallChart.class); | |
// Create an instance of Workbook | |
Workbook workbook = new Workbook(); | |
// Retrieve the first Worksheet in Workbook | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Retrieve the Cells of the first Worksheet | |
Cells cells = worksheet.getCells(); | |
// Input some data which chart will use as source | |
cells.get("A1").putValue("Previous Year"); | |
cells.get("A2").putValue("January"); | |
cells.get("A3").putValue("March"); | |
cells.get("A4").putValue("August"); | |
cells.get("A5").putValue("October"); | |
cells.get("A6").putValue("Current Year"); | |
cells.get("B1").putValue(8.5); | |
cells.get("B2").putValue(1.5); | |
cells.get("B3").putValue(7.5); | |
cells.get("B4").putValue(7.5); | |
cells.get("B5").putValue(8.5); | |
cells.get("B6").putValue(3.5); | |
cells.get("C1").putValue(1.5); | |
cells.get("C2").putValue(4.5); | |
cells.get("C3").putValue(3.5); | |
cells.get("C4").putValue(9.5); | |
cells.get("C5").putValue(7.5); | |
cells.get("C6").putValue(9.5); | |
// Add a Chart of type Waterfall in same worksheet as of data | |
int idx = worksheet.getCharts().add(ChartType.WATERFALL, 4, 4, 25, 13); | |
// Reterieve the Chart object | |
Chart chart = worksheet.getCharts().get(idx); | |
// Add Series | |
chart.getNSeries().add("$B$1:$C$6", true); | |
// Add Category Data | |
chart.getNSeries().setCategoryData("$A$1:$A$6"); | |
// Series has Up Down Bars | |
chart.getNSeries().get(0).setHasUpDownBars(true); | |
// Set the colors of Up and Down Bars | |
chart.getNSeries().get(0).getUpBars().getArea().setForegroundColor(Color.getGreen()); | |
chart.getNSeries().get(0).getDownBars().getArea().setForegroundColor(Color.getRed()); | |
// Make both Series Lines invisible | |
chart.getNSeries().get(0).getBorder().setVisible(false); | |
chart.getNSeries().get(1).getBorder().setVisible(false); | |
// Set the Plot Area Formatting Automatic | |
chart.getPlotArea().getArea().setFormatting(FormattingType.AUTOMATIC); | |
// Delete the Legend | |
chart.getLegend().getLegendEntries().get(0).setDeleted(true); | |
chart.getLegend().getLegendEntries().get(1).setDeleted(true); | |
// Save the workbook | |
workbook.save(dataDir + "output.xlsx"); |