我使用此代码绘制“ one_row_table”的条形图。
private void addBarChart1(Sheet sheet, int top, int col1, int row1, int col2, int row2, String title) {
Drawing drawing = sheet.createDrawingPatriarch();
ClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, col1, row1, col2, row2);
Chart chart = drawing.createChart(anchor);
CTChart ctChart = ((XSSFChart) chart).getCTChart();
CTPlotArea ctPlotArea = ctChart.getPlotArea();
CTBarChart ctBarChart = ctPlotArea.addNewBarChart();
ctBarChart.addNewBarDir().setVal(STBarDir.COL);
String lastCol = CellReference.convertNumToColString(sheet.getRow(sheet.getFirstRowNum()).getLastCellNum() - 1);
Integer start = 0;
Integer end = 1;
CTBarSer ctBarSer = ctBarChart.addNewSer();
CTSerTx ctSerTx = ctBarSer.addNewTx();
CTStrRef ctStrRef = ctSerTx.addNewStrRef();
ctStrRef.setF("'" + sheet.getSheetName() + "'!$A$" + ( 2));
ctBarSer.addNewIdx().setVal(0);// id must be below 255
CTAxDataSource cttAxDataSource = ctBarSer.addNewCat();
ctStrRef = cttAxDataSource.addNewStrRef();
ctStrRef.setF("'" + sheet.getSheetName() + "'!$B$1:$" + lastCol + "$1");
CTNumDataSource ctNumDataSource = ctBarSer.addNewVal();
CTNumRef ctNumRef = ctNumDataSource.addNewNumRef();
ctNumRef.setF("'" + sheet.getSheetName() + "'!$B$" + (2) + ":$" +
lastCol + "$" + (2));
// at least the border lines in Libreoffice Calc ;-)
ctBarSer.addNewSpPr().addNewLn().addNewSolidFill().addNewSrgbClr().setVal(new byte[] { 0, 0, 0 });
}
// telling the BarChart that it has axes and giving them Ids
ctBarChart.addNewAxId().setVal(123456);
ctBarChart.addNewAxId().setVal(123457);
// cat axis
CTCatAx ctCatAx = ctPlotArea.addNewCatAx();
ctCatAx.addNewAxId().setVal(123456); // id of the cat axis
CTScaling ctScaling = ctCatAx.addNewScaling();
ctScaling.addNewOrientation().setVal(STOrientation.MIN_MAX);
ctCatAx.addNewDelete().setVal(false);
ctCatAx.addNewAxPos().setVal(STAxPos.B);
ctCatAx.addNewCrossAx().setVal(123457); // id of the val axis
ctCatAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
// val axis
CTValAx ctValAx = ctPlotArea.addNewValAx();
ctValAx.addNewAxId().setVal(123457); // id of the val axis
ctScaling = ctValAx.addNewScaling();
ctScaling.addNewOrientation().setVal(STOrientation.MIN_MAX);
ctValAx.addNewDelete().setVal(false);
ctValAx.addNewAxPos().setVal(STAxPos.L);
ctValAx.addNewCrossAx().setVal(123456); // id of the cat axis
ctValAx.addNewTickLblPos().setVal(STTickLblPos.NEXT_TO);
// legend
CTLegend ctLegend = ctChart.addNewLegend();
ctLegend.addNewLegendPos().setVal(STLegendPos.B);
ctLegend.addNewOverlay().setVal(false);
// title
CTTitle ctTitle = ctChart.addNewTitle();
ctTitle.addNewOverlay().setVal(false);
ctTitle.addNewTx().addNewRich().addNewBodyPr();
ctTitle.getTx().getRich().addNewP().addNewR().setT(title);
}
我的主管不喜欢每个条形都有不同的颜色,因为它们表示相同类型的数据,但是位置不同。
我想用相同的颜色制作所有的东西,但是该功能自行选择了颜色,有什么方法可以使所有条形变成蓝色?