if (label == null) {
label = item.getName();
}
Iterable<HistoricItem> result;
FilterCriteria filter;
// Generate data collections
Collection<Date> xData = new ArrayList<Date>();
Collection<Number> yData = new ArrayList<Number>();
// Declare state here so it will hold the last value at the end of the process
org.openhab.core.types.State state = null;
// First, get the value at the start time.
// This is necessary for values that don't change often otherwise data will start
// after the start of the graph (or not at all if there's no change during the graph period)
filter = new FilterCriteria();
filter.setEndDate(timeBegin);
filter.setItemName(item.getName());
filter.setPageSize(1);
filter.setOrdering(Ordering.DESCENDING);
result = service.query(filter);
if(result.iterator().hasNext()) {
HistoricItem historicItem = result.iterator().next();
state = historicItem.getState();
xData.add(timeBegin);
yData.add(convertData(state));
}
// Now, get all the data between the start and end time
filter.setBeginDate(timeBegin);
filter.setEndDate(timeEnd);
filter.setPageSize(Integer.MAX_VALUE);
filter.setOrdering(Ordering.ASCENDING);
// Get the data from the persistence store
result = service.query(filter);
Iterator<HistoricItem> it = result.iterator();