Jasper reports 如何在动态报告中更改甘特图中百分比栏的颜色?

Jasper reports 如何在动态报告中更改甘特图中百分比栏的颜色?,jasper-reports,jfreechart,dynamic-reports,Jasper Reports,Jfreechart,Dynamic Reports,我需要有关更改甘特图中百分比栏颜色的帮助。我正在使用动态报告api生成pdf格式的报告 我需要更改进度条的颜色,它总是显示为绿色,我想更改它 private JasperReportBuilder build(){ JasperReportBuilder report = DynamicReports.report(); TextColumnBuilder<String> uName = col.column("Name", "name", type.stringType())

我需要有关更改甘特图中百分比栏颜色的帮助。我正在使用动态报告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);
  }

}  
private JasperReportBuilder build(){
JasperReportBuilder report=DynamicReports.report();
TextColumnBuilder uName=col.column(“Name”、“Name”、type.stringType()).setHorizontalAlignment(HorizontalAlignment.LEFT);
TextColumnBuilder uStart=col.column(“开始”,“开始”,type.dateType());
TextColumnBuilder uEnd=col.column(“End”,“End”,type.dateType());
TextColumnBuilder uProgress=col.column(“Progress”,“Progress”,type.doubleType());
GantChartChartBuilder chart2=cht.GantChart().Customizer(新的ChartCustomizer())
.setTask(uName)
.系列(
cht.ganttSerie()
.设置开始日期(uStart)
.setEndDate(上界)
.setPercent(uProgress)
).SeriesColor(新颜色(163209255)).setDataSource(CreateDataSourceOrganntChart(initiativeList、initiativeGroup、periodId、subPeriodId、fullPath、model))
.setTimeAxisFormat(
cht.axisFormat().setLabel(objectInitiativeChart.getCategoryLabel())
.setTaskAxisFormat(
cht.axisFormat().setLabel(objectInitiativeChart.getSeriesLabel());
报告摘要(图2);
返回报告;
}
私有类ChartCustomizer实现DRIChartCustomizer,可序列化{
私有静态最终长serialVersionUID=1L;
@凌驾
公共void自定义(JFreeChart图表、ReportParameters ReportParameters){
Ballenderer renderer=(Ballenderer)chart.getCategoryPlot().getRenderer();
渲染器。setMaximumBarWidth(0.1);
org.jfree.chart.axis.CategoryAxis domainAxis=chart.getCategoryPlot().getDomainAxis();
domainAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI/6.0));
域轴毛类边缘蛋白(-0.5d);
}
}  

您需要将
GantTrender
转换为
setCompletePaint(c色)
,因此现在您要转换为
Ballenderer

完整示例

添加图表自定义程序以获取
JFreeChart
对象。(注意,您使用的集合已弃用)


我已经添加了标签jfreechart(这是使用的库)se例如this:Thanx用于回复,实际上我正在尝试更改进度条的颜色(任何任务的完成百分比),它在我的图表图像中是绿色的。如何更改此颜色?我正在使用动态报表api生成报表。在报告中,我需要实现甘特图。但是没有合适的文档来定制图表。所以,请检查这个链接,并帮助我,我如何才能做到这一点。基本上你需要在JFreeChart上搜索,这是你需要玩的对象,我已经给你一个答案,祝你玩得开心。。。。。
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);
    }
});