use of org.jfree.data.time.TimeSeriesCollection in project projectforge by micromata.
the class LiquidityChartBuilder method createXYPlot.
/**
* @param forecast
* @param settings (next days)
* @return
*/
public JFreeChart createXYPlot(final LiquidityForecast forecast, final LiquidityForecastSettings settings) {
if (!(settings.getNextDays() > 0 && settings.getNextDays() <= LiquidityForecastSettings.MAX_FORECAST_DAYS)) {
settings.setNextDays(LiquidityForecastSettings.DEFAULT_FORECAST_DAYS);
}
final LiquidityForecastCashFlow cashFlow = new LiquidityForecastCashFlow(forecast, settings.getNextDays());
final TimeSeries accumulatedSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.dueDate"));
final TimeSeries accumulatedSeriesExpected = new TimeSeries(ThreadLocalUserContext.getLocalizedString("plugins.liquidityplanning.forecast.expected"));
// The paranoia case assumes only costs and no incomes (no invoice will be paid by the customers).
final TimeSeries paranoiaCaseSeries = new TimeSeries(I18n.getString("plugins.liquidityplanning.forecast.paranoiaCase"));
double accumulatedExpected = settings.getStartAmount().doubleValue();
double accumulated = accumulatedExpected;
double paranoiaCase = accumulated;
PFDay dt = PFDay.fromOrNow(forecast.getBaseDate());
final Date lower = dt.getUtilDate();
for (int i = 0; i < settings.getNextDays(); i++) {
if (log.isDebugEnabled()) {
log.debug("day: " + i + ", credits=" + cashFlow.getCredits()[i] + ", debits=" + cashFlow.getDebits()[i]);
}
final Day day = new Day(dt.getDayOfMonth(), dt.getMonthValue(), dt.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();
paranoiaCase += cashFlow.getCredits()[i - 1].doubleValue();
}
accumulatedSeries.add(day, accumulated);
accumulatedSeriesExpected.add(day, accumulatedExpected);
paranoiaCaseSeries.add(day, paranoiaCase);
dt = dt.plusDays(1);
}
dt = dt.minusDays(1);
final XYChartBuilder cb = new XYChartBuilder(null, null, null, null, true);
int counter = 0;
final TimeSeriesCollection xyDataSeries = new TimeSeriesCollection();
xyDataSeries.addSeries(accumulatedSeries);
xyDataSeries.addSeries(paranoiaCaseSeries);
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, dt.getUtilDate()).setYAxis(true, null);
return cb.getChart();
}
use of org.jfree.data.time.TimeSeriesCollection in project projectforge by micromata.
the class TimesheetDisciplineChartBuilder method create.
/**
* 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
* @return
*/
public JFreeChart create(final TimesheetDao timesheetDao, final Integer userId, final short forLastNDays) {
PFDateTime dt = PFDateTime.now();
final TimesheetFilter filter = new TimesheetFilter();
filter.setStopTime(dt.getUtilDate());
dt = dt.minusDays(forLastNDays);
filter.setStartTime(dt.getUtilDate());
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()) {
current = it.next();
}
long numberOfBookedDays = 0;
long totalDifference = 0;
for (int i = 0; i <= forLastNDays; i++) {
long difference = 0;
// Weight for average.
long totalDuration = 0;
PFDateTime dateTime = null;
if (current != null)
// not null
dateTime = PFDateTime.from(current.getStartTime());
while (current != null && (dt.isSameDay(dateTime) || dateTime.isBefore(dt))) {
final long duration = current.getWorkFractionDuration();
difference += (current.getCreated().getTime() - current.getStartTime().getTime()) * duration;
totalDuration += duration;
if (it.hasNext()) {
current = it.next();
// not null
dateTime = PFDateTime.from(current.getStartTime());
} else {
current = null;
break;
}
}
// In days.
final double averageDifference = difference > 0 ? ((double) difference) / totalDuration / 86400000 : 0;
final Day day = new Day(dt.getDayOfMonth(), dt.getMonthValue(), dt.getYear());
if (averageDifference > 0) {
// plan average
planSeries.add(day, PLANNED_AVERAGE_DIFFERENCE_BETWEEN_TIMESHEET_AND_BOOKING);
// (PLANNED_AVERAGE_DIFFERENCE_BETWEEN_TIMESHEET_AND_BOOKING
// days).
actualSeries.add(day, averageDifference);
totalDifference += averageDifference;
numberOfBookedDays++;
}
dt = dt.plusDays(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();
}
use of org.jfree.data.time.TimeSeriesCollection in project projectforge by micromata.
the class TimesheetDisciplineChartBuilder method create.
/**
* 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
* @return
*/
public JFreeChart create(final TimesheetDao timesheetDao, final Integer userId, final double workingHoursPerDay, final short forLastNDays, boolean useWorkingHours) {
PFDateTime dt = PFDateTime.now();
final TimesheetFilter filter = new TimesheetFilter();
filter.setStopTime(dt.getUtilDate());
dt = dt.minusDays(forLastNDays);
filter.setStartTime(dt.getUtilDate());
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()) {
current = it.next();
}
long numberOfBookedDays = 0;
long totalDifference = 0;
for (int i = 0; i <= forLastNDays; i++) {
// NPE-Fix required: current may be null.
long difference = 0;
// Weight for average.
long totalDuration = 0;
PFDateTime dateTime = null;
if (current != null)
// not null
dateTime = PFDateTime.from(current.getStartTime());
while (current != null && (dt.isSameDay(dateTime) || dateTime.isBefore(dt))) {
if (useWorkingHours) {
actualWorkingHours += ((double) current.getWorkFractionDuration()) / 3600000;
} else {
final long duration = current.getWorkFractionDuration();
difference += (current.getCreated().getTime() - current.getStartTime().getTime()) * duration;
totalDuration += duration;
}
if (it.hasNext()) {
current = it.next();
// not null
dateTime = PFDateTime.from(current.getStartTime());
} else {
current = null;
break;
}
}
final Day day = new Day(dt.getDayOfMonth(), dt.getMonthValue(), dt.getYear());
if (useWorkingHours) {
Holidays holidays = Holidays.getInstance();
if (holidays.isWorkingDay(dt.getDateTime())) {
final BigDecimal workFraction = holidays.getWorkFraction(dt);
if (workFraction != null) {
planWorkingHours += workFraction.doubleValue() * workingHoursPerDay;
} else {
planWorkingHours += workingHoursPerDay;
}
}
sollSeries.add(day, planWorkingHours);
istSeries.add(day, actualWorkingHours);
} else {
// In days.
final double averageDifference = difference > 0 ? ((double) difference) / totalDuration / 86400000 : 0;
if (averageDifference > 0) {
// plan average
sollSeries.add(day, PLANNED_AVERAGE_DIFFERENCE_BETWEEN_TIMESHEET_AND_BOOKING);
// (PLANNED_AVERAGE_DIFFERENCE_BETWEEN_TIMESHEET_AND_BOOKING
// days).
istSeries.add(day, averageDifference);
totalDifference += averageDifference;
numberOfBookedDays++;
}
}
dt = dt.plusDays(1);
}
final TimeSeriesCollection dataset = new TimeSeriesCollection();
if (useWorkingHours) {
dataset.addSeries(sollSeries);
dataset.addSeries(istSeries);
} else {
dataset.addSeries(istSeries);
dataset.addSeries(sollSeries);
}
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);
if (useWorkingHours) {
cb.setDateXAxis(true).setYAxis(true, "hours");
} else {
averageDifferenceBetweenTimesheetAndBooking = numberOfBookedDays > 0 ? new BigDecimal(totalDifference).divide(new BigDecimal(numberOfBookedDays), 1, RoundingMode.HALF_UP) : BigDecimal.ZERO;
cb.setDateXAxis(true).setYAxis(true, "days");
}
return cb.getChart();
}
use of org.jfree.data.time.TimeSeriesCollection in project graphcode2vec by graphcode2vec.
the class TimeSeriesChartDemo1 method createDataset.
/**
* Creates a dataset, consisting of two series of monthly data.
*
* @return The dataset.
*/
private static XYDataset createDataset() {
TimeSeries s1 = new TimeSeries("L&G European Index Trust");
s1.add(new Month(2, 2001), 181.8);
s1.add(new Month(3, 2001), 167.3);
s1.add(new Month(4, 2001), 153.8);
s1.add(new Month(5, 2001), 167.6);
s1.add(new Month(6, 2001), 158.8);
s1.add(new Month(7, 2001), 148.3);
s1.add(new Month(8, 2001), 153.9);
s1.add(new Month(9, 2001), 142.7);
s1.add(new Month(10, 2001), 123.2);
s1.add(new Month(11, 2001), 131.8);
s1.add(new Month(12, 2001), 139.6);
s1.add(new Month(1, 2002), 142.9);
s1.add(new Month(2, 2002), 138.7);
s1.add(new Month(3, 2002), 137.3);
s1.add(new Month(4, 2002), 143.9);
s1.add(new Month(5, 2002), 139.8);
s1.add(new Month(6, 2002), 137.0);
s1.add(new Month(7, 2002), 132.8);
TimeSeries s2 = new TimeSeries("L&G UK Index Trust");
s2.add(new Month(2, 2001), 129.6);
s2.add(new Month(3, 2001), 123.2);
s2.add(new Month(4, 2001), 117.2);
s2.add(new Month(5, 2001), 124.1);
s2.add(new Month(6, 2001), 122.6);
s2.add(new Month(7, 2001), 119.2);
s2.add(new Month(8, 2001), 116.5);
s2.add(new Month(9, 2001), 112.7);
s2.add(new Month(10, 2001), 101.5);
s2.add(new Month(11, 2001), 106.1);
s2.add(new Month(12, 2001), 110.3);
s2.add(new Month(1, 2002), 111.7);
s2.add(new Month(2, 2002), 111.0);
s2.add(new Month(3, 2002), 109.6);
s2.add(new Month(4, 2002), 113.2);
s2.add(new Month(5, 2002), 111.6);
s2.add(new Month(6, 2002), 108.8);
s2.add(new Month(7, 2002), 101.6);
// ******************************************************************
// More than 150 demo applications are included with the JFreeChart
// Developer Guide...for more information, see:
//
// > http://www.object-refinery.com/jfreechart/guide.html
//
// ******************************************************************
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(s1);
dataset.addSeries(s2);
return dataset;
}
use of org.jfree.data.time.TimeSeriesCollection in project radargun by radargun.
the class TimelineChart method setEvents.
public void setEvents(List<? extends Object> events, int workerIndex, long startTimestamp, long endTimestamp, double lowerBound, double upperBound) {
int paintIndex = workerIndex % DEFAULT_PAINTS.length;
if (paintIndex < 0)
paintIndex += DEFAULT_PAINTS.length;
paint = DEFAULT_PAINTS[paintIndex];
this.startTimestamp = startTimestamp;
this.endTimestamp = endTimestamp + (startTimestamp == endTimestamp ? 1 : 0);
TimeSeries series = new TimeSeries("Worker " + workerIndex);
TimeSeriesCollection dataset = new TimeSeriesCollection(series, GMT);
chart = ChartFactory.createTimeSeriesChart(null, "Time from start", null, dataset, false, false, false);
chart.setBackgroundPaint(new Color(0, 0, 0, 0));
XYPlot plot = chart.getXYPlot();
plot.getRenderer().setSeriesPaint(0, paint);
plot.setBackgroundAlpha(0);
plot.setDomainGridlinesVisible(false);
plot.setDomainZeroBaselineVisible(true);
plot.setRangeGridlinesVisible(false);
plot.setRangeZeroBaselineVisible(true);
Number[] minValues = new Number[MAX_EVENT_VALUES];
Number[] maxValues = new Number[MAX_EVENT_VALUES];
long[] minTimestamps = new long[MAX_EVENT_VALUES];
long[] maxTimestamps = new long[MAX_EVENT_VALUES];
for (Object event : events) {
if (event instanceof Timeline.Value) {
Timeline.Value value = (Timeline.Value) event;
if (value.timestamp > this.endTimestamp) {
throw new IllegalStateException(String.format("Current timestamp %d is bigger then end timestamp %d", value.timestamp, this.endTimestamp));
}
int bucket = (int) ((value.timestamp - startTimestamp) * (MAX_EVENT_VALUES - 1) / (this.endTimestamp - startTimestamp));
if (minValues[bucket] == null) {
minValues[bucket] = value.value;
maxValues[bucket] = value.value;
minTimestamps[bucket] = value.timestamp;
maxTimestamps[bucket] = value.timestamp;
} else {
if (minValues[bucket].doubleValue() > value.value.doubleValue()) {
minValues[bucket] = value.value;
}
if (maxValues[bucket].doubleValue() < value.value.doubleValue()) {
maxValues[bucket] = value.value;
}
minTimestamps[bucket] = Math.min(minTimestamps[bucket], value.timestamp);
maxTimestamps[bucket] = Math.max(maxTimestamps[bucket], value.timestamp);
}
} else if (event instanceof Timeline.IntervalEvent) {
Timeline.IntervalEvent intervalEvent = (Timeline.IntervalEvent) event;
IntervalMarker marker = new IntervalMarker(intervalEvent.timestamp - startTimestamp, intervalEvent.timestamp + intervalEvent.duration - startTimestamp, paint, stroke, paint, stroke, 0.3f);
marker.setLabel(intervalEvent.description);
marker.setLabelAnchor(RectangleAnchor.BOTTOM);
marker.setLabelTextAnchor(TextAnchor.BOTTOM_CENTER);
marker.setLabelOffset(new RectangleInsets(0, 0, (workerIndex + 1) * LABEL_OFFSET, 0));
plot.addDomainMarker(marker);
} else if (event instanceof Timeline.TextEvent) {
Timeline.TextEvent textEvent = (Timeline.TextEvent) event;
ValueMarker marker = new ValueMarker(textEvent.timestamp - startTimestamp, paint, stroke);
marker.setLabel(textEvent.text);
marker.setLabelAnchor(RectangleAnchor.BOTTOM_LEFT);
marker.setLabelTextAnchor(TextAnchor.BOTTOM_LEFT);
marker.setLabelOffset(new RectangleInsets(0, 0, (workerIndex + 1) * LABEL_OFFSET, 0));
plot.addDomainMarker(marker);
}
}
for (int bucket = 0; bucket < MAX_EVENT_VALUES; ++bucket) {
if (minValues[bucket] == null)
continue;
series.addOrUpdate(time(minTimestamps[bucket] - startTimestamp), minValues[bucket]);
series.addOrUpdate(time(maxTimestamps[bucket] - startTimestamp), maxValues[bucket]);
}
DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
dateAxis.setTimeZone(GMT);
dateAxis.setMinimumDate(new Date(0));
dateAxis.setMaximumDate(new Date(endTimestamp - startTimestamp));
if (upperBound > lowerBound) {
plot.getRangeAxis().setRange(lowerBound, upperBound);
}
}
Aggregations