我正在创建包含一些统计信息的Excel文件,也包括折线图。我成功地创建了图表并用数据填充它们。但我对图表系列的默认颜色不满意。
那我怎么能改变图表系列的颜色呢?我找不到任何关于它的文档,所以请帮忙。我也听说,这个问题可能与工作簿的默认颜色有关,所以也许你可以指导我如何改变它们?
我正在使用Apache POI 3.10。
答案 0 :(得分:2)
它对我有用。 Groovy,PieChart,随机颜色。
10
答案 1 :(得分:0)
值得注意的是,对于折线图,颜色选项存在多个不同的地方。线条的颜色,标记的填充颜色和标记的轮廓颜色。可以相互独立设置。在此示例中,我只是将它们设置为同一事物,但是如果您希望它们不同,则在设置它们时提供不同的rgb字节数组。
CTChart ctChart = chart.getCTChart();
CTPlotArea plotArea = ctChart.getPlotArea();
CTLineChart lineChart = plotArea.addNewLineChart();
lineChart.addNewVaryColors().setVal(false);
CTLineSer lineSeries = lineChart.addNewSer();
lineSeries.addNewSmooth().setVal(false);
// some rgb color code. in this example it is a light greenish color
byte[] color = new byte[] {(byte) 195, (byte) 224, (byte) 176};
CTShapeProperties lineProp = lineSeries.addNewSpPr();
//Set the colour of the line connecting points
CTSRgbColor fill = lineProp.addNewLn().addNewSolidFill().addNewSrgbClr();
fill.setVal(color);
CTShapeProperties markerProp = lineSeries.addNewMarker().addNewSpPr();
// Set the fill colour of the marker
markerProp.addNewLn().addNewSolidFill().setSrgbClr(fill);
//Set the outline colour of the marker
markerProp.addNewSolidFill().setSrgbClr(fill);