public DataSet buildXYDataSet() {
DataSet targetDataSet = null;
DataProperty domainProperty = getDomainProperty();
DataProperty rangeProperty = getRangeProperty();
ScalarFunction scalarFunction = getRangeScalarFunction();
CodeBlockTrace trace = new BuildXYDataSetTrace(domainProperty, rangeProperty, scalarFunction).begin();
try {
if (domainProperty == null || domainProperty.getDomain() == null) return null;
if (rangeProperty == null || scalarFunction == null) return null;
// Group the original data set by the domain property. Thus the scalar function is applied to the range values.
DataSet sourceDataSet = domainProperty.getDataSet();
List<DataProperty> targetDataProps = Arrays.asList(new DataProperty[]{domainProperty, rangeProperty});
List<String> targetFunctionCodes = Arrays.asList(new String[]{CountFunction.CODE, scalarFunction.getCode()});
targetDataSet = sourceDataSet.groupBy(domainProperty, targetDataProps, targetFunctionCodes);
// Sort the resulting data set according to the sort policy specified.
if (intervalsSortOrder != INTERVALS_SORT_ORDER_NONE) {
DataSetComparator comp = new DataSetComparator();