@Override public Chart generateChart() { if (selectedImages == null || selectedPhoneModels == null || selectedTests == null) { throw new IllegalStateException("missing parameters"); } Chart chart = new Chart(); chart.setLabels(generateLabels(selectedTests)); List<ChartResult> datasets = new ArrayList<>(); for (PhoneModel device : selectedPhoneModels) { ChartResult chartResult = new ChartResult(); chartResult.setFillColor(device.getColor()); chartResult.setStrokeColor(device.getColor()); chartResult.setHighlightFill(device.getColor()); chartResult.setHighlightStroke(device.getColor()); List<Long> durations = new ArrayList<>(); for (Test test : selectedTests) { long duration = 0; for (Image image : selectedImages) { duration += resultRepository.findAvarageTime(device, test, image) != null ? resultRepository.findAvarageTime(device, test, image) : 0; // .size()>0?resultRepository.findAvarageTime(device, test, image).get(0):0; } durations.add(duration); } chartResult.setData(durations); datasets.add(chartResult); } chart.setDatasets(datasets); return chart; }