The following image is the output before setting the major and minor unit:
I tried to set the majorUnit and minorUnit of my X-axis( category) in apache poi 5.0.0, By using the following code:
XDDFCategoryAxis bottomAxis = chart.createCategoryAxis(AxisPosition.BOTTOM);
XDDFValueAxis leftAxis = chart.createValueAxis(AxisPosition.LEFT);
leftAxis.setCrosses(AxisCrosses.MIN);
bottomAxis.setCrosses(AxisCrosses.MIN);
setValueAxisTitle(chart, 0, chartDataLocationInExcelFile.getColumnNames()[index + 1]);
setCatAxisTitle(chart, 0, chartDataLocationInExcelFile.getColumnNames()[index - 1]);
// getting minimum cat value of category
CellReference cellReference = new CellReference(chartDataLocationInExcelFile.getFirstRowNumber() + 2,
chartDataLocationInExcelFile.getFirstCellNumber());
Row row = sheet.getRow(cellReference.getRow());
Cell cell = row.getCell(cellReference.getCol());
// setting MajorUnit and MinorUnit of category axis
bottomAxis.setMajorUnit(0.2d);
bottomAxis.setMinorUnit(0.3d);
// setting minimum and maximum of category axis
BigDecimal catMin = new BigDecimal(cell.getNumericCellValue());
BigDecimal subtractResult = catMin.subtract(new BigDecimal(5d));
bottomAxis.setMinimum(subtractResult.doubleValue());
//
Then it didn't work, And the following output generated: Thanks for your help.
After checking the source of XDDFCategoryAxis in Apache POI 5.0.0, I saw that setMajorUnit and setMinorUnit didn't have body:
@Override
public void setMajorUnit(double major) {
// nothing
}
@Override
public void setMinorUnit(double minor) {
// nothing
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.