繁体   English   中英

碧玉报告中面积图中面积的透明度问题

[英]Transparency issue of area in area chart in jasper report

我通过碧玉做面积图时遇到问题。

问题在于,当面积图部分中存在多个区域时,下一个区域会覆盖一个区域。因此,上一个区域是不可见的。

这似乎是所用颜色透明度的问题。

下面是一段代码

公共类StatsChartCustomiser扩展了JRAbstractChartCustomizer实现的JRChartCustomizer {

/** The class logger. */
private static final Log log = LogFactory.getLog(StatsChartCustomiser.class);

public void customize(final JFreeChart jFreeChart, final JRChart jasperChart) {
    Plot plot = jFreeChart.getPlot();
    jFreeChart.getCategoryPlot().getRenderer().getPlot().setForegroundAlpha(0.5f);
    jasperChart.getPlot().setForegroundAlpha(0.5f);
    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryItemRenderer renderer = categoryPlot.getRenderer();
        renderer.setSeriesPaint(0, Color.blue);
        renderer.setSeriesPaint(1, Color.red);
        renderer.setSeriesPaint(2, Color.green);
        categoryPlot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        categoryPlot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        categoryPlot.setDomainGridlinesVisible(true);
        categoryPlot.setForegroundAlpha(0.5f);
        categoryPlot.getForegroundAlpha();
        CategoryAxis xAxis = categoryPlot.getDomainAxis();
        Font tickLabelFont = xAxis.getTickLabelFont();
        ChartFrame frame1=new ChartFrame("Area Chart",jFreeChart);
        frame1.setVisible(true);
        //frame1.setOpacity((float) .5);
        // category labels in category charts with lots of tick marks are
        // unreadable, so reduce font size (think a JFreeChart bug)
        xAxis.setTickLabelFont(tickLabelFont.deriveFont(8f));
        ValueAxis yAxis = categoryPlot.getRangeAxis();
        xAxis.setCategoryLabelPositions(CategoryLabelPositions.createUpRotationLabelPositions(Math.PI / 2.0)); // vertical
        yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        jasperChart.getParentProperties();
        JRChartPlot jasperplot = jasperChart.getPlot();
        System.out.println("before----    "+jasperplot.getForegroundAlpha());
        jasperplot.setForegroundAlpha(0.5f);
        System.out.println("after----    "+jasperplot.getForegroundAlpha());
        jasperplot.getForegroundAlpha();


    } else if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        XYItemRenderer renderer = xyPlot.getRenderer();
        renderer.setSeriesPaint(0, Color.blue);
        xyPlot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        xyPlot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        ValueAxis xAxis = xyPlot.getDomainAxis();
        NumberAxis yAxis = (NumberAxis) xyPlot.getRangeAxis();
        yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        xAxis.setVerticalTickLabels(true);
        if (xAxis instanceof DateAxis) {
            DateAxis dateAxis = (DateAxis) xAxis;
            SimpleDateFormat sdf = new SimpleDateFormat("dd MMMM yyyy");
            String interval = (String) getParameterValue("Interval");
            if ("Day".equals(interval)) {
                sdf.applyPattern("HH:mm");
                // strange, but the range seems to comes out wrong for Day (comes out as 23:00 - 01:00 ???) unless explicitly set
                String fromDateString = (String) getParameterValue("FromDate");
                DateFormat dfdt = new SimpleDateFormat(Bof2Constants.CALENDAR_WIDGET_DATE_TIME_FORMAT);
                // set hours,min,sec to 0 in FromDate to get the start time for the x axis
                try {
                Date fromDate = dfdt.parse(fromDateString);
                Calendar cal = Calendar.getInstance();
                cal.setTime(fromDate);
                cal.set(Calendar.HOUR_OF_DAY, 0);
                cal.set(Calendar.MINUTE, 0);
                cal.set(Calendar.SECOND, 0);
                cal.set(Calendar.MILLISECOND, 0);
                Date startOfDay = cal.getTime();
                cal.set(Calendar.HOUR_OF_DAY, 23);
                cal.set(Calendar.MINUTE, 59);
                cal.set(Calendar.SECOND, 59);
                cal.set(Calendar.MILLISECOND, 999);
                Date endOfDay = cal.getTime();  
                dateAxis.setRange(startOfDay, endOfDay);
                SegmentedTimeline timeline = new SegmentedTimeline(Bof2Constants.MILLISECS_IN_AN_HOUR, 24, 0);
                timeline.setStartTime(fromDate.getTime() - 1);
                dateAxis.setTimeline(timeline);
                } catch (ParseException e) {
                    log.error("Failed to parse fromDateString:" + fromDateString + " for StatsChartReport by Day");
                }
            }
            int tickInterval = ((Integer) getParameterValue("TickInterval")).intValue();
            int tickIntervalCount = ((Integer) getParameterValue("TickIntervalCount")).intValue();
            dateAxis.setTickUnit(new DateTickUnit(tickInterval, tickIntervalCount, sdf));
            dateAxis.setAutoTickUnitSelection(false);
        }
    }
}

}

与JFreeChart相比,这更可能是PDF问题。 图表是使用Graphics2D对象在画布上呈现的,并且如果基础图形引擎(在您的情况下为JasperReports)无法正确处理Alpha通道, 或者在呈现为PDF之前对画布进行了栅格化,则不会有任何透明度。

发生这种情况可能是因为JasperReports无法按JFreeChart期望的方式处理Alpha通道。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM