المحور الأساسي والثانوي
سيناريوهات الاستخدام المحتملة
عندما تتفاوت الأرقام في الرسم البياني بشكل كبير بين سلاسل البيانات، أو عندما تحتوي على أنواع مختلطة من البيانات (السعر والحجم)، ارسم سلسلة بيانات واحدة أو أكثر على محور عمودي (قيمة) ثانوي. مقياس المحور العمودي الثانوي يظهر القيم لسلاسل البيانات المرتبطة. يعمل المحور الثانوي بشكل جيد في رسم بياني يظهر فيه مزيج من رسوم الأعمدة والخطوط.
قم بالتعامل مع المحور الأساسي والثانوي على غرار Microsoft Excel
يرجى الاطلاع على الكود النموذجي التالي الذي ينشئ ملف إكسل جديد ويضع قيم الرسم البياني في الورقة العمل الأولى. ثم نضيف رسم بياني ونعرض المحور الثانوي.
الكود النموذجي التالي يولد ملف Excel الناتج.
الكود المثالي
// Create an instance of Workbook | |
Workbook workbook = new Workbook(); | |
// Access the first worksheet. | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Put the sample values used in a chart | |
worksheet.getCells().get("A1").putValue("Region"); | |
worksheet.getCells().get("A2").putValue("Peking"); | |
worksheet.getCells().get("A3").putValue("New York"); | |
worksheet.getCells().get("A4").putValue("Paris"); | |
worksheet.getCells().get("B1").putValue("Sales Volume"); | |
worksheet.getCells().get("C1").putValue("Growth Rate"); | |
worksheet.getCells().get("B2").putValue(100); | |
worksheet.getCells().get("B3").putValue(80); | |
worksheet.getCells().get("B4").putValue(140); | |
worksheet.getCells().get("C2").putValue(0.7); | |
worksheet.getCells().get("C3").putValue(0.8); | |
worksheet.getCells().get("C4").putValue(1.0); | |
// Create a Scatter chart | |
int pieIdx = worksheet.getCharts().add(ChartType.SCATTER, 6, 6, 15, 11); | |
// Retrieve the Chart object | |
Chart chart = worksheet.getCharts().get(pieIdx); | |
// Add Series | |
chart.getNSeries().add("B2:C4", true); | |
// Set the category data | |
chart.getNSeries().setCategoryData("=Sheet1!$A$2:$A$4"); | |
// Set the Second-Axis | |
chart.getNSeries().get(1).setPlotOnSecondAxis(true); | |
// Show the Second-Axis | |
chart.getSecondValueAxis().setVisible(true); | |
// Set the second series ChartType to line | |
chart.getNSeries().get(1).setType(ChartType.LINE); | |
// Set the series name | |
chart.getNSeries().get(0).setName("Sales Volume"); | |
chart.getNSeries().get(1).setName("Growth Rate"); | |
// Set the Legend at the bottom of the chart area | |
chart.getLegend().setPosition(LegendPositionType.BOTTOM); | |
// Fill the PlotArea area with nothing | |
chart.getPlotArea().getArea().getFillFormat().setFillType(FillType.NONE); | |
// Save the file | |
workbook.save("PrimaryandSecondaryAxis.xlsx"); | |