我需要帮助改变甘特图中百分比条的颜色。我正在使用动态报告api生成pdf格式的报告。
我需要更改进度条的颜色,它始终显示为绿色,我想要更改它。
private JasperReportBuilder build(){
JasperReportBuilder report = DynamicReports.report();
TextColumnBuilder<String> uName = col.column("Name", "name", type.stringType()).setHorizontalAlignment(HorizontalAlignment.LEFT);
TextColumnBuilder<Date> uStart = col.column("Start", "start", type.dateType());
TextColumnBuilder<Date> uEnd = col.column("End", "end", type.dateType());
TextColumnBuilder<Double> uProgress = col.column("Progress", "progress", type.doubleType());
GanttChartBuilder chart2 = cht.ganttChart().customizers(new ChartCustomizer())
.setTask(uName)
.series(
cht.ganttSerie()
.setStartDate(uStart)
.setEndDate(uEnd)
.setPercent(uProgress)
).seriesColors(new Color(163,209,255)).setDataSource(createDataSourceForGanntChart(initiativeList,initiativeGroup,periodId,subPeriodId,fullPath,model))
.setTimeAxisFormat(
cht.axisFormat().setLabel(objectInitiativeChart.getCategoryLabel()))
.setTaskAxisFormat(
cht.axisFormat().setLabel(objectInitiativeChart.getSeriesLabel()));
report.summary(chart2);
return report;
}
private class ChartCustomizer implements DRIChartCustomizer, Serializable {
private static final long serialVersionUID = 1L;
@Override
public void customize(JFreeChart chart, ReportParameters reportParameters) {
BarRenderer renderer = (BarRenderer) chart.getCategoryPlot().getRenderer();
renderer.setMaximumBarWidth(0.1);
org.jfree.chart.axis.CategoryAxis domainAxis = chart.getCategoryPlot().getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 6.0));
domainAxis.setCategoryMargin(-0.5d);
}
}
答案 0 :(得分:1)
您需要将GanttRenderer
转换为setCompletePaint(Color c)
,因此现在您要转向BarRenderer
完整示例
添加图表自定义程序以获取JFreeChart
对象。 (注意您使用的是deprecated
)
chart2.addCustomizer(new DRIChartCustomizer() {
private static final long serialVersionUID = 1L;
@Override
public void customize(JFreeChart chart, ReportParameters arg) {
//Here we got the JFreeChart object and we can modify it as we like
CategoryPlot plot = (CategoryPlot) chart.getPlot();
//Cast to GanttRenderer
GanttRenderer renderer = (GanttRenderer) plot.getRenderer();
//Set colors as desired.
renderer.setIncompletePaint(Color.CYAN);
renderer.setCompletePaint(Color.MAGENTA);
}
});