org.jfree.chart.renderer.xy.XYDifferenceRenderer Java Examples
The following examples show how to use
org.jfree.chart.renderer.xy.XYDifferenceRenderer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XYDifferenceRendererTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { XYDifferenceRenderer r1 = new XYDifferenceRenderer(Color.red, Color.blue, false); XYDifferenceRenderer r2 = new XYDifferenceRenderer(Color.red, Color.blue, false); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); }
Example #2
Source File: XYDifferenceRendererTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ public void testGetLegendItemSeriesIndex() { XYSeriesCollection d1 = new XYSeriesCollection(); XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); XYSeries s2 = new XYSeries("S2"); s2.add(1.0, 1.1); d1.addSeries(s1); d1.addSeries(s2); XYSeriesCollection d2 = new XYSeriesCollection(); XYSeries s3 = new XYSeries("S3"); s3.add(1.0, 1.1); XYSeries s4 = new XYSeries("S4"); s4.add(1.0, 1.1); XYSeries s5 = new XYSeries("S5"); s5.add(1.0, 1.1); d2.addSeries(s3); d2.addSeries(s4); d2.addSeries(s5); XYDifferenceRenderer r = new XYDifferenceRenderer(); XYPlot plot = new XYPlot(d1, new NumberAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, d2); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("S5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
Example #3
Source File: XYDifferenceRendererTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * Two objects that are equal are required to return the same hashCode. */ public void testHashcode() { XYDifferenceRenderer r1 = new XYDifferenceRenderer(Color.red, Color.blue, false); XYDifferenceRenderer r2 = new XYDifferenceRenderer(Color.red, Color.blue, false); assertTrue(r1.equals(r2)); int h1 = r1.hashCode(); int h2 = r2.hashCode(); assertEquals(h1, h2); }
Example #4
Source File: XYDifferenceRendererTests.java From astor with GNU General Public License v2.0 | 5 votes |
/** * A check for the datasetIndex and seriesIndex fields in the LegendItem * returned by the getLegendItem() method. */ public void testGetLegendItemSeriesIndex() { XYSeriesCollection d1 = new XYSeriesCollection(); XYSeries s1 = new XYSeries("S1"); s1.add(1.0, 1.1); XYSeries s2 = new XYSeries("S2"); s2.add(1.0, 1.1); d1.addSeries(s1); d1.addSeries(s2); XYSeriesCollection d2 = new XYSeriesCollection(); XYSeries s3 = new XYSeries("S3"); s3.add(1.0, 1.1); XYSeries s4 = new XYSeries("S4"); s4.add(1.0, 1.1); XYSeries s5 = new XYSeries("S5"); s5.add(1.0, 1.1); d2.addSeries(s3); d2.addSeries(s4); d2.addSeries(s5); XYDifferenceRenderer r = new XYDifferenceRenderer(); XYPlot plot = new XYPlot(d1, new NumberAxis("x"), new NumberAxis("y"), r); plot.setDataset(1, d2); /*JFreeChart chart =*/ new JFreeChart(plot); LegendItem li = r.getLegendItem(1, 2); assertEquals("S5", li.getLabel()); assertEquals(1, li.getDatasetIndex()); assertEquals(2, li.getSeriesIndex()); }
Example #5
Source File: SWTTimeSeriesDemo.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Creates a chart. * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart( "Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); //plot.setForegroundAlpha(0.5f); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } // code to test the alpha channel IntervalMarker interv = new IntervalMarker(120, 150, Color.blue, new BasicStroke(5.0f),null,null,0.2f); plot.addRangeMarker(interv); // code to test the alpha channel within awt colors XYDifferenceRenderer differenceRenderer= new XYDifferenceRenderer( new Color(255, 0, 0, 128),new Color(0, 255, 0, 128), false); plot.setRenderer(differenceRenderer); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
Example #6
Source File: XYDifferenceRendererTests.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Verify that this class implements {@link PublicCloneable}. */ public void testPublicCloneable() { XYDifferenceRenderer r1 = new XYDifferenceRenderer(); assertTrue(r1 instanceof PublicCloneable); }
Example #7
Source File: SWTTimeSeriesDemo.java From astor with GNU General Public License v2.0 | 4 votes |
/** * Creates a chart. * * @param dataset a dataset. * * @return A chart. */ private static JFreeChart createChart(XYDataset dataset) { JFreeChart chart = ChartFactory.createTimeSeriesChart( "Legal & General Unit Trust Prices", // title "Date", // x-axis label "Price Per Unit", // y-axis label dataset, // data true, // create legend? true, // generate tooltips? false // generate URLs? ); chart.setBackgroundPaint(Color.white); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.lightGray); plot.setDomainGridlinePaint(Color.white); plot.setRangeGridlinePaint(Color.white); plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0)); plot.setDomainCrosshairVisible(true); plot.setRangeCrosshairVisible(true); //plot.setForegroundAlpha(0.5f); XYItemRenderer r = plot.getRenderer(); if (r instanceof XYLineAndShapeRenderer) { XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r; renderer.setBaseShapesVisible(true); renderer.setBaseShapesFilled(true); } // code to test the alpha channel IntervalMarker interv = new IntervalMarker(120, 150, Color.blue, new BasicStroke(5.0f),null,null,0.2f); plot.addRangeMarker(interv); // code to test the alpha channel within awt colors XYDifferenceRenderer differenceRenderer= new XYDifferenceRenderer(new Color(255,0,0,128),new Color(0,255,0,128),false); plot.setRenderer(differenceRenderer); DateAxis axis = (DateAxis) plot.getDomainAxis(); axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy")); return chart; }
Example #8
Source File: TimesheetDisciplineChartBuilder.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * Ein Diagramm, welches über die letzten n Tage die kummulierten IST-Arbeitsstunden und als Soll-Wert die tatsächlich gebuchten * Zeitberichte aufträgt. Dies wird in einem Differenz-XY-Diagramm visualisiert. Die Darstellung soll motivieren, dass Projektmitarbeiter * ihre Zeitberichte möglichst zeitnah eintragen. * @param timesheetDao * @param userId * @param workingHoursPerDay * @param forLastNDays * @param shape e. g. new Ellipse2D.Float(-3, -3, 6, 6) or null, if no marker should be printed. * @param stroke e. g. new BasicStroke(3.0f). * @param showAxisValues * @return */ public JFreeChart create(final TimesheetDao timesheetDao, final Integer userId, final double workingHoursPerDay, final short forLastNDays, final boolean showAxisValues) { final DayHolder dh = new DayHolder(); final TimesheetFilter filter = new TimesheetFilter(); filter.setStopTime(dh.getDate()); dh.add(Calendar.DATE, -forLastNDays); filter.setStartTime(dh.getDate()); filter.setUserId(userId); filter.setOrderType(OrderDirection.ASC); final List<TimesheetDO> list = timesheetDao.getList(filter); final TimeSeries sollSeries = new TimeSeries("Soll"); final TimeSeries istSeries = new TimeSeries("Ist"); planWorkingHours = 0; actualWorkingHours = 0; final Iterator<TimesheetDO> it = list.iterator(); TimesheetDO current = null; if (it.hasNext() == true) { current = it.next(); } for (int i = 0; i <= forLastNDays; i++) { while (current != null && (dh.isSameDay(current.getStartTime()) == true || current.getStartTime().before(dh.getDate()) == true)) { actualWorkingHours += ((double) current.getWorkFractionDuration()) / 3600000; if (it.hasNext() == true) { current = it.next(); } else { current = null; break; } } if (dh.isWorkingDay() == true) { final BigDecimal workFraction = dh.getWorkFraction(); if (workFraction != null) { planWorkingHours += workFraction.doubleValue() * workingHoursPerDay; } else { planWorkingHours += workingHoursPerDay; } } final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear()); sollSeries.add(day, planWorkingHours); istSeries.add(day, actualWorkingHours); dh.add(Calendar.DATE, 1); } final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(sollSeries); dataset.addSeries(istSeries); final XYChartBuilder cb = new XYChartBuilder(null, null, null, dataset, false); final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getRedFill(), cb.getGreenFill(), true); diffRenderer.setSeriesPaint(0, cb.getRedMarker()); diffRenderer.setSeriesPaint(1, cb.getGreenMarker()); cb.setRenderer(0, diffRenderer).setStrongStyle(diffRenderer, false, sollSeries, istSeries); cb.setDateXAxis(true).setYAxis(true, "hours"); return cb.getChart(); }
Example #9
Source File: TimesheetDisciplineChartBuilder.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * Ein Diagramm, welches über die letzten n Tage die Tage visualisiert, die zwischen Zeitberichtsdatum und Zeitpunkt der tatsächlichen * Buchung liegen. * @param timesheetDao * @param userId * @param forLastNDays * @param shape e. g. new Ellipse2D.Float(-3, -3, 6, 6) or null, if no marker should be printed. * @param stroke e. g. new BasicStroke(3.0f). * @param showAxisValues * @return */ public JFreeChart create(final TimesheetDao timesheetDao, final Integer userId, final short forLastNDays, final boolean showAxisValues) { final DayHolder dh = new DayHolder(); final TimesheetFilter filter = new TimesheetFilter(); filter.setStopTime(dh.getDate()); dh.add(Calendar.DATE, -forLastNDays); filter.setStartTime(dh.getDate()); filter.setUserId(userId); filter.setOrderType(OrderDirection.ASC); final List<TimesheetDO> list = timesheetDao.getList(filter); final TimeSeries planSeries = new TimeSeries("Soll"); final TimeSeries actualSeries = new TimeSeries("Ist"); final Iterator<TimesheetDO> it = list.iterator(); TimesheetDO current = null; if (it.hasNext() == true) { current = it.next(); } long numberOfBookedDays = 0; long totalDifference = 0; for (int i = 0; i <= forLastNDays; i++) { long difference = 0; long totalDuration = 0; // Weight for average. while (current != null && (dh.isSameDay(current.getStartTime()) == true || current.getStartTime().before(dh.getDate()) == true)) { final long duration = current.getWorkFractionDuration(); difference += (current.getCreated().getTime() - current.getStartTime().getTime()) * duration; totalDuration += duration; if (it.hasNext() == true) { current = it.next(); } else { current = null; break; } } final double averageDifference = difference > 0 ? ((double) difference) / totalDuration / 86400000 : 0; // In days. final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear()); if (averageDifference > 0) { planSeries.add(day, PLANNED_AVERAGE_DIFFERENCE_BETWEEN_TIMESHEET_AND_BOOKING); // plan average // (PLANNED_AVERAGE_DIFFERENCE_BETWEEN_TIMESHEET_AND_BOOKING // days). actualSeries.add(day, averageDifference); totalDifference += averageDifference; numberOfBookedDays++; } dh.add(Calendar.DATE, 1); } averageDifferenceBetweenTimesheetAndBooking = numberOfBookedDays > 0 ? new BigDecimal(totalDifference).divide(new BigDecimal( numberOfBookedDays), 1, RoundingMode.HALF_UP) : BigDecimal.ZERO; final TimeSeriesCollection dataset = new TimeSeriesCollection(); dataset.addSeries(actualSeries); dataset.addSeries(planSeries); final XYChartBuilder cb = new XYChartBuilder(null, null, null, dataset, false); final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getRedFill(), cb.getGreenFill(), true); diffRenderer.setSeriesPaint(0, cb.getRedMarker()); diffRenderer.setSeriesPaint(1, cb.getGreenMarker()); cb.setRenderer(0, diffRenderer).setStrongStyle(diffRenderer, false, actualSeries, planSeries); cb.setDateXAxis(true).setYAxis(true, "days"); return cb.getChart(); }
Example #10
Source File: LiquidityChartBuilder.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
/** * @param forecast * @param settings (next days) * @return */ public JFreeChart createXYPlot(final LiquidityForecast forecast, final LiquidityForecastSettings settings) { Validate.isTrue(settings.getNextDays() > 0 && settings.getNextDays() < 500); final LiquidityForecastCashFlow cashFlow = new LiquidityForecastCashFlow(forecast, settings.getNextDays()); final TimeSeries accumulatedSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.dueDate")); final TimeSeries accumulatedSeriesExpected = new TimeSeries( PFUserContext.getLocalizedString("plugins.liquidityplanning.forecast.expected")); final TimeSeries worstCaseSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.worstCase")); double accumulatedExpected = settings.getStartAmount().doubleValue(); double accumulated = accumulatedExpected; double worstCase = accumulated; final DayHolder dh = new DayHolder(); final Date lower = dh.getDate(); for (int i = 0; i < settings.getNextDays(); i++) { if (log.isDebugEnabled() == true) { log.debug("day: " + i + ", credits=" + cashFlow.getCredits()[i] + ", debits=" + cashFlow.getDebits()[i]); } final Day day = new Day(dh.getDayOfMonth(), dh.getMonth() + 1, dh.getYear()); if (i > 0) { accumulated += cashFlow.getDebits()[i - 1].doubleValue() + cashFlow.getCredits()[i - 1].doubleValue(); accumulatedExpected += cashFlow.getDebitsExpected()[i - 1].doubleValue() + cashFlow.getCreditsExpected()[i - 1].doubleValue(); worstCase += cashFlow.getCredits()[i - 1].doubleValue(); } accumulatedSeries.add(day, accumulated); accumulatedSeriesExpected.add(day, accumulatedExpected); worstCaseSeries.add(day, worstCase); dh.add(Calendar.DATE, 1); } dh.add(Calendar.DATE, -1); final XYChartBuilder cb = new XYChartBuilder(null, null, null, null, true); int counter = 0; final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection(); xyDataSeries.addSeries(accumulatedSeries); xyDataSeries.addSeries(worstCaseSeries); final XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); lineRenderer.setSeriesPaint(0, Color.BLACK); lineRenderer.setSeriesVisibleInLegend(0, true); lineRenderer.setSeriesPaint(1, cb.getGrayMarker()); lineRenderer.setSeriesStroke(1, cb.getDashedStroke()); lineRenderer.setSeriesVisibleInLegend(1, true); cb.setRenderer(counter, lineRenderer).setDataset(counter++, xyDataSeries); final TimeSeriesCollection accumulatedSet = new TimeSeriesCollection(); accumulatedSet.addSeries(accumulatedSeriesExpected); final XYDifferenceRenderer diffRenderer = new XYDifferenceRenderer(cb.getGreenFill(), cb.getRedFill(), true); diffRenderer.setSeriesPaint(0, cb.getRedMarker()); cb.setRenderer(counter, diffRenderer).setDataset(counter++, accumulatedSet) .setStrongStyle(diffRenderer, false, accumulatedSeriesExpected); diffRenderer.setSeriesVisibleInLegend(0, true); cb.setDateXAxis(true).setDateXAxisRange(lower, dh.getDate()).setYAxis(true, null); return cb.getChart(); }