
На изображении выше я хочу изменить цвет всей области красной маркировки, которая является XSSFClientAnchore, на собственный цвет.
private void createDounughtChart(final XSSFWorkbook workbook,String sheetName){
final XSSFSheet uebersicht = workbook.getSheet(sheetName);
String[] categories = new String[]{"one","two","three","four","five","six","seven","eight","nine","ten"};
Number[] values = new Number[]{ 11L,2L,3L,4L,5L,6L,7L,8L,9L,10L };
XSSFChart chart1 = createDoughnutChart(uebersicht, categories, values, "Zusammensetzung Abfallfraktionen\n", 2, 5, 5, 26);
categories = new String[]{"one","two"};
values = new Number[]{ 60L,40L };
XSSFChart chart2 = createDoughnutChart(uebersicht, categories, values, "Anteil gefährliche / nicht gefährliche Abfälle\n", 5, 5, 8, 24);
categories = new String[]{"one","two","three","four","five","six","seven","eight","nine","ten"};
values = new Number[]{ 11L,2L,3L,4L,5L,6L,7L,8L,9L,10L };
XSSFChart chart3 = createDoughnutChart(uebersicht, categories, values, "Zusammensetzung Entsorgungswege\n", 8, 5, 11, 26);
}
static XSSFChart createDoughnutChart(XSSFSheet sheet, String[] categories, Number[] values, String titleText, int col1, int row1, int col2, int row2) {
XSSFDrawing drawing = sheet.createDrawingPatriarch();
XSSFClientAnchor anchor = drawing.createAnchor(0, 0, 0, 0, col1, row1, col2, row2);
XSSFChart chart = drawing.createChart(anchor);
chart.setTitleText(titleText);
chart.setTitleOverlay(false);
XDDFChartLegend legend = chart.getOrAddLegend();
legend.setPosition(LegendPosition.BOTTOM);
XDDFDataSource cat = XDDFDataSourcesFactory.fromArray(categories);
XDDFNumericalDataSource val = XDDFDataSourcesFactory.fromArray(values);
XDDFDoughnutChartData data = (XDDFDoughnutChartData)chart.createData(ChartTypes.DOUGHNUT, null, null);
//XDDFDoughnutChartData data = new XDDFDoughnutChartData(chart, chart.getCTChart().getPlotArea().addNewDoughnutChart());
data.setVaryColors(true);
//data.setHoleSize(10);
//data.setHoleSize(50);
XDDFChartData.Series series = data.addSeries(cat, val);
chart.plot(data);
// Do not auto delete the title; is necessary for showing title in Calc
if (chart.getCTChart().getAutoTitleDeleted() == null) chart.getCTChart().addNewAutoTitleDeleted();
chart.getCTChart().getAutoTitleDeleted().setVal(false);
// Data point colors; is necessary for showing data points in Calc
int pointCount = series.getCategoryData().getPointCount();
for (int p = 0; p < pointCount; p++) {
chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).addNewDPt().addNewIdx().setVal(p);
chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).getDPtArray(p)
.addNewSpPr().addNewSolidFill().addNewSrgbClr().setVal(XlsxService.getColor(p));
}
// Add data labels
if (!chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).isSetDLbls()) {
chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).addNewDLbls();
}
chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).getDLbls().addNewShowVal().setVal(true);
chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).getDLbls().addNewShowSerName().setVal(false);
chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).getDLbls().addNewShowCatName().setVal(false);
chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).getDLbls().addNewShowPercent().setVal(false);
chart.getCTChart().getPlotArea().getDoughnutChartArray(0).getSerArray(0).getDLbls().addNewShowLegendKey().setVal(false);
// chart area (chartspace) without border line
chart.getCTChartSpace().addNewSpPr().addNewLn().addNewNoFill();
return chart;
}
Подробнее здесь: https://stackoverflow.com/questions/774 ... of-anchore
Мобильная версия