akhilgangwarmpec Posted April 28, 2014 Posted April 28, 2014 I am facing a problem when i do a area chart through jasper. The problem is that when multiple areas are there in the area chart section ,one is overrided by the next one.So the previous one is not visble. It seems to be an issue of transperancy of colours used. below is piece of code public class StatsChartCustomiser extends JRAbstractChartCustomizer implements JRChartCustomizer { 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); } } } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now