1 68 69 package org.jfree.data; 70 71 import java.util.ArrayList ; 72 import java.util.Iterator ; 73 import java.util.List ; 74 75 80 public class DatasetUtilities { 81 82 85 protected DatasetUtilities() { 86 } 87 88 96 public static Number [] createNumberArray(double[] data) { 97 98 Number [] result = new Number [data.length]; 99 100 for (int i = 0; i < data.length; i++) { 101 result[i] = new Double (data[i]); 102 } 103 104 return result; 105 106 } 107 108 116 public static Number [][] createNumberArray2D(double[][] data) { 117 118 int l1 = data.length; 119 int l2 = data[0].length; 120 121 Number [][] result = new Number [l1][l2]; 122 123 for (int i = 0; i < l1; i++) { 124 result[i] = createNumberArray(data[i]); 125 } 126 127 return result; 128 129 } 130 131 140 public static Range getDomainExtent(Dataset data) { 141 142 if (data == null) { 144 return null; 145 } 146 147 if ((data instanceof CategoryDataset) && !(data instanceof XYDataset)) { 148 throw new IllegalArgumentException ("Datasets.getDomainExtent(...): " 149 + "CategoryDataset does not have a numerical domain."); 150 } 151 152 if (data instanceof DomainInfo) { 154 DomainInfo info = (DomainInfo) data; 155 return info.getDomainRange(); 156 } 157 158 else if (data instanceof XYDataset) { 160 double minimum = Double.POSITIVE_INFINITY; 161 double maximum = Double.NEGATIVE_INFINITY; 162 XYDataset xyData = (XYDataset) data; 163 int seriesCount = xyData.getSeriesCount(); 164 for (int series = 0; series < seriesCount; series++) { 165 int itemCount = xyData.getItemCount(series); 166 for (int item = 0; item < itemCount; item++) { 167 168 Number lvalue = null; 169 Number uvalue = null; 170 if (data instanceof IntervalXYDataset) { 171 IntervalXYDataset intervalXYData = (IntervalXYDataset) data; 172 lvalue = intervalXYData.getStartXValue(series, item); 173 uvalue = intervalXYData.getEndXValue(series, item); 174 } 175 else { 176 lvalue = xyData.getXValue(series, item); 177 uvalue = lvalue; 178 } 179 if (lvalue != null) { 180 minimum = Math.min(minimum, lvalue.doubleValue()); 181 } 182 if (uvalue != null) { 183 maximum = Math.max(maximum, uvalue.doubleValue()); 184 } 185 186 } 187 } 188 if (minimum == Double.POSITIVE_INFINITY) { 189 return null; 190 } 191 else { 192 return new Range(minimum, maximum); 193 } 194 } 195 else { 196 return null; } 198 199 } 200 201 209 public static Range getRangeExtent(Dataset data) { 210 211 if (data == null) { 213 return null; 214 } 215 216 if (data instanceof RangeInfo) { 218 RangeInfo info = (RangeInfo) data; 219 return info.getValueRange(); 220 } 221 222 else if (data instanceof CategoryDataset) { 224 225 CategoryDataset tableData = (CategoryDataset) data; 226 double minimum = Double.POSITIVE_INFINITY; 227 double maximum = Double.NEGATIVE_INFINITY; 228 int rowCount = tableData.getRowCount(); 229 int columnCount = tableData.getColumnCount(); 230 for (int row = 0; row < rowCount; row++) { 231 for (int column = 0; column < columnCount; column++) { 232 Number lvalue = null; 233 Number uvalue = null; 234 if (data instanceof IntervalCategoryDataset) { 235 IntervalCategoryDataset icd = (IntervalCategoryDataset) data; 236 lvalue = icd.getStartValue(row, column); 237 uvalue = icd.getEndValue(row, column); 238 } 239 else { 240 lvalue = tableData.getValue(row, column); 241 uvalue = lvalue; 242 } 243 if (lvalue != null) { 244 minimum = Math.min(minimum, lvalue.doubleValue()); 245 } 246 if (uvalue != null) { 247 maximum = Math.max(maximum, uvalue.doubleValue()); 248 } 249 } 250 } 251 if (minimum == Double.POSITIVE_INFINITY) { 252 return null; 253 } 254 else { 255 return new Range(minimum, maximum); 256 } 257 258 } 259 else if (data instanceof XYDataset) { 260 261 XYDataset xyData = (XYDataset) data; 263 double minimum = Double.POSITIVE_INFINITY; 264 double maximum = Double.NEGATIVE_INFINITY; 265 int seriesCount = xyData.getSeriesCount(); 266 for (int series = 0; series < seriesCount; series++) { 267 int itemCount = xyData.getItemCount(series); 268 for (int item = 0; item < itemCount; item++) { 269 270 Number lvalue = null; 271 Number uvalue = null; 272 if (data instanceof IntervalXYDataset) { 273 IntervalXYDataset intervalXYData = (IntervalXYDataset) data; 274 lvalue = intervalXYData.getStartYValue(series, item); 275 uvalue = intervalXYData.getEndYValue(series, item); 276 } 277 else if (data instanceof HighLowDataset) { 278 HighLowDataset highLowData = (HighLowDataset) data; 279 lvalue = highLowData.getLowValue(series, item); 280 uvalue = highLowData.getHighValue(series, item); 281 } 282 else { 283 lvalue = xyData.getYValue(series, item); 284 uvalue = lvalue; 285 } 286 if (lvalue != null) { 287 minimum = Math.min(minimum, lvalue.doubleValue()); 288 } 289 if (uvalue != null) { 290 maximum = Math.max(maximum, uvalue.doubleValue()); 291 } 292 293 } 294 } 295 if (minimum == Double.POSITIVE_INFINITY) { 296 return null; 297 } 298 else { 299 return new Range(minimum, maximum); 300 } 301 302 } 303 else { 304 return null; 305 } 306 307 } 308 309 322 public static Number getMinimumDomainValue(Dataset data) { 323 324 if (data == null) { 326 throw new IllegalArgumentException ( 327 "DatasetUtilities.getMinimumDomainValue: null dataset not allowed."); 328 } 329 330 if ((data instanceof CategoryDataset) && !(data instanceof XYDataset)) { 331 throw new IllegalArgumentException ("DatasetUtilities.getMinimumDomainValue(...): " 332 + "TableDataset does not have numerical domain."); 333 } 334 335 if (data instanceof DomainInfo) { 337 DomainInfo info = (DomainInfo) data; 338 return info.getMinimumDomainValue(); 339 } 340 341 else if (data instanceof XYDataset) { 343 double minimum = Double.POSITIVE_INFINITY; 344 XYDataset xyData = (XYDataset) data; 345 int seriesCount = xyData.getSeriesCount(); 346 for (int series = 0; series < seriesCount; series++) { 347 int itemCount = xyData.getItemCount(series); 348 for (int item = 0; item < itemCount; item++) { 349 350 Number value = null; 351 if (data instanceof IntervalXYDataset) { 352 IntervalXYDataset intervalXYData = (IntervalXYDataset) data; 353 value = intervalXYData.getStartXValue(series, item); 354 } 355 else { 356 value = xyData.getXValue(series, item); 357 } 358 if (value != null) { 359 minimum = Math.min(minimum, value.doubleValue()); 360 } 361 362 } 363 } 364 if (minimum == Double.POSITIVE_INFINITY) { 365 return null; 366 } 367 else { 368 return new Double (minimum); 369 } 370 } 371 372 else { 373 return null; } 375 376 } 377 378 391 public static Number getMaximumDomainValue(Dataset data) { 392 393 if (data == null) { 395 throw new IllegalArgumentException ( 396 "Datasets.getMaximumDomainValue: null dataset not allowed."); 397 } 398 399 if ((data instanceof CategoryDataset) && !(data instanceof XYDataset)) { 400 throw new IllegalArgumentException ("Datasets.getMaximumDomainValue(...): " 401 + "CategoryDataset does not have numerical domain."); 402 } 403 404 if (data instanceof DomainInfo) { 406 DomainInfo info = (DomainInfo) data; 407 return info.getMaximumDomainValue(); 408 } 409 410 else if (data instanceof XYDataset) { 412 XYDataset xyData = (XYDataset) data; 413 double maximum = Double.NEGATIVE_INFINITY; 414 int seriesCount = xyData.getSeriesCount(); 415 for (int series = 0; series < seriesCount; series++) { 416 int itemCount = xyData.getItemCount(series); 417 for (int item = 0; item < itemCount; item++) { 418 419 Number value = null; 420 if (data instanceof IntervalXYDataset) { 421 IntervalXYDataset intervalXYData = (IntervalXYDataset) data; 422 value = intervalXYData.getEndXValue(series, item); 423 } 424 else { 425 value = xyData.getXValue(series, item); 426 } 427 if (value != null) { 428 maximum = Math.max(maximum, value.doubleValue()); 429 } 430 } 431 } 432 if (maximum == Double.NEGATIVE_INFINITY) { 433 return null; 434 } 435 else { 436 return new Double (maximum); 437 } 438 439 } 440 else { 441 return null; } 443 444 } 445 446 459 public static Number getMinimumRangeValue(Dataset data) { 460 461 if (data == null) { 463 throw new IllegalArgumentException ( 464 "Datasets.getMinimumRangeValue: null dataset not allowed."); 465 } 466 467 if (data instanceof RangeInfo) { 469 RangeInfo info = (RangeInfo) data; 470 return info.getMinimumRangeValue(); 471 } 472 473 else if (data instanceof CategoryDataset) { 475 476 CategoryDataset categoryData = (CategoryDataset) data; 477 double minimum = Double.POSITIVE_INFINITY; 478 int seriesCount = categoryData.getRowCount(); 479 int itemCount = categoryData.getColumnCount(); 480 for (int series = 0; series < seriesCount; series++) { 481 for (int item = 0; item < itemCount; item++) { 482 Number value = null; 483 if (data instanceof IntervalCategoryDataset) { 484 IntervalCategoryDataset icd = (IntervalCategoryDataset) data; 485 value = icd.getStartValue(series, item); 486 } 487 else { 488 value = categoryData.getValue(series, item); 489 } 490 if (value != null) { 491 minimum = Math.min(minimum, value.doubleValue()); 492 } 493 } 494 } 495 if (minimum == Double.POSITIVE_INFINITY) { 496 return null; 497 } 498 else { 499 return new Double (minimum); 500 } 501 502 } 503 else if (data instanceof XYDataset) { 504 505 XYDataset xyData = (XYDataset) data; 507 double minimum = Double.POSITIVE_INFINITY; 508 int seriesCount = xyData.getSeriesCount(); 509 for (int series = 0; series < seriesCount; series++) { 510 int itemCount = xyData.getItemCount(series); 511 for (int item = 0; item < itemCount; item++) { 512 513 Number value = null; 514 if (data instanceof IntervalXYDataset) { 515 IntervalXYDataset intervalXYData = (IntervalXYDataset) data; 516 value = intervalXYData.getStartYValue(series, item); 517 } 518 else if (data instanceof HighLowDataset) { 519 HighLowDataset highLowData = (HighLowDataset) data; 520 value = highLowData.getLowValue(series, item); 521 } 522 else { 523 value = xyData.getYValue(series, item); 524 } 525 if (value != null) { 526 minimum = Math.min(minimum, value.doubleValue()); 527 } 528 529 } 530 } 531 if (minimum == Double.POSITIVE_INFINITY) { 532 return null; 533 } 534 else { 535 return new Double (minimum); 536 } 537 538 } 539 else { 540 return null; 541 } 542 543 } 544 545 558 public static Number getMaximumRangeValue(Dataset data) { 559 560 if (data == null) { 562 throw new IllegalArgumentException ( 563 "Datasets.getMinimumRangeValue: null dataset not allowed."); 564 } 565 566 if (data instanceof RangeInfo) { 568 RangeInfo info = (RangeInfo) data; 569 return info.getMaximumRangeValue(); 570 } 571 572 else if (data instanceof CategoryDataset) { 574 575 CategoryDataset categoryData = (CategoryDataset) data; 576 double maximum = Double.NEGATIVE_INFINITY; 577 int seriesCount = categoryData.getRowCount(); 578 int itemCount = categoryData.getColumnCount(); 579 for (int series = 0; series < seriesCount; series++) { 580 for (int item = 0; item < itemCount; item++) { 581 Number value = null; 582 if (data instanceof IntervalCategoryDataset) { 583 IntervalCategoryDataset icd = (IntervalCategoryDataset) data; 584 value = icd.getEndValue(series, item); 585 } 586 else { 587 value = categoryData.getValue(series, item); 588 } 589 if (value != null) { 590 maximum = Math.max(maximum, value.doubleValue()); 591 } 592 } 593 } 594 if (maximum == Double.NEGATIVE_INFINITY) { 595 return null; 596 } 597 else { 598 return new Double (maximum); 599 } 600 601 } 602 else if (data instanceof XYDataset) { 603 604 XYDataset xyData = (XYDataset) data; 605 double maximum = Double.NEGATIVE_INFINITY; 606 int seriesCount = xyData.getSeriesCount(); 607 for (int series = 0; series < seriesCount; series++) { 608 int itemCount = xyData.getItemCount(series); 609 for (int item = 0; item < itemCount; item++) { 610 Number value = null; 611 if (data instanceof IntervalXYDataset) { 612 IntervalXYDataset intervalXYData = (IntervalXYDataset) data; 613 value = intervalXYData.getEndYValue(series, item); 614 } 615 else if (data instanceof HighLowDataset) { 616 HighLowDataset highLowData = (HighLowDataset) data; 617 value = highLowData.getHighValue(series, item); 618 } 619 else { 620 value = xyData.getYValue(series, item); 621 } 622 if (value != null) { 623 maximum = Math.max(maximum, value.doubleValue()); 624 } 625 } 626 } 627 if (maximum == Double.NEGATIVE_INFINITY) { 628 return null; 629 } 630 else { 631 return new Double (maximum); 632 } 633 634 } 635 else { 636 return null; 637 } 638 639 } 640 641 650 public static PieDataset createPieDatasetForRow(CategoryDataset data, Comparable rowKey) { 651 652 int row = data.getRowIndex(rowKey); 653 return createPieDatasetForRow(data, row); 654 655 } 656 657 666 public static PieDataset createPieDatasetForRow(CategoryDataset data, int row) { 667 668 DefaultPieDataset result = new DefaultPieDataset(); 669 int columnCount = data.getColumnCount(); 670 for (int current = 0; current < columnCount; current++) { 671 Comparable columnKey = data.getColumnKey(current); 672 result.setValue(columnKey, data.getValue(row, current)); 673 } 674 return result; 675 676 } 677 678 687 public static PieDataset createPieDatasetForColumn(CategoryDataset data, 688 Comparable columnKey) { 689 690 int column = data.getColumnIndex(columnKey); 691 return createPieDatasetForColumn(data, column); 692 693 } 694 695 704 public static PieDataset createPieDatasetForColumn(CategoryDataset data, int column) { 705 706 DefaultPieDataset result = new DefaultPieDataset(); 707 int rowCount = data.getRowCount(); 708 for (int i = 0; i < rowCount; i++) { 709 Comparable rowKey = data.getRowKey(i); 710 result.setValue(rowKey, data.getValue(i, column)); 711 } 712 return result; 713 714 } 715 716 723 public static double getPieDatasetTotal(PieDataset data) { 724 725 List categories = data.getKeys(); 727 728 double totalValue = 0; 730 Iterator iterator = categories.iterator(); 731 while (iterator.hasNext()) { 732 Comparable current = (Comparable ) iterator.next(); 733 if (current != null) { 734 Number value = data.getValue(current); 735 double v = 0.0; 736 if (value != null) { 737 v = value.doubleValue(); 738 } 739 if (v > 0) { 740 totalValue = totalValue + v; 741 } 742 } 743 } 744 return totalValue; 745 } 746 747 755 public static Range getStackedRangeExtent(CategoryDataset data) { 756 757 Range result = null; 758 759 if (data != null) { 760 761 double minimum = 0.0; 762 double maximum = 0.0; 763 764 int categoryCount = data.getColumnCount(); 765 for (int item = 0; item < categoryCount; item++) { 766 double positive = 0.0; 767 double negative = 0.0; 768 int seriesCount = data.getRowCount(); 769 for (int series = 0; series < seriesCount; series++) { 770 Number number = data.getValue(series, item); 771 if (number != null) { 772 double value = number.doubleValue(); 773 if (value > 0.0) { 774 positive = positive + value; 775 } 776 if (value < 0.0) { 777 negative = negative + value; } 779 } 780 } 781 minimum = Math.min(minimum, negative); 782 maximum = Math.max(maximum, positive); 783 784 } 785 786 result = new Range(minimum, maximum); 787 788 } 789 790 return result; 791 792 } 793 794 802 public static Number getMinimumStackedRangeValue(CategoryDataset data) { 803 804 Number result = null; 805 806 if (data != null) { 807 808 double minimum = 0.0; 809 810 int categoryCount = data.getRowCount(); 811 for (int item = 0; item < categoryCount; item++) { 812 double total = 0.0; 813 814 int seriesCount = data.getColumnCount(); 815 for (int series = 0; series < seriesCount; series++) { 816 Number number = data.getValue(series, item); 817 if (number != null) { 818 double value = number.doubleValue(); 819 if (value < 0.0) { 820 total = total + value; } 822 } 823 } 824 minimum = Math.min(minimum, total); 825 826 } 827 828 result = new Double (minimum); 829 830 } 831 832 return result; 833 834 } 835 836 844 public static Number getMaximumStackedRangeValue(CategoryDataset data) { 845 846 Number result = null; 847 848 if (data != null) { 849 850 double maximum = 0.0; 851 852 int categoryCount = data.getRowCount(); 853 for (int item = 0; item < categoryCount; item++) { 854 double total = 0.0; 855 856 int seriesCount = data.getColumnCount(); 857 for (int series = 0; series < seriesCount; series++) { 858 Number number = data.getValue(series, item); 859 if (number != null) { 860 double value = number.doubleValue(); 861 if (value > 0.0) { 862 total = total + value; 863 } 864 } 865 } 866 maximum = Math.max(maximum, total); 867 868 } 869 870 result = new Double (maximum); 871 872 } 873 874 return result; 875 876 } 877 878 889 public static XYDataset sampleFunction2D(Function2D f, 890 double start, double end, int samples, 891 String seriesName) { 892 893 if (start >= end) { 894 throw new IllegalArgumentException ("DatasetUtilities.createXYDataset(...): " 895 + "start must be before end."); 896 } 897 898 if (samples < 2) { 899 throw new IllegalArgumentException ("DatasetUtilities.createXYDataset(...): " 900 + "samples must be at least 2."); 901 } 902 903 XYSeries series = new XYSeries(seriesName); 904 905 double step = (end - start) / samples; 906 for (int i = 0; i <= samples; i++) { 907 double x = start + (step * i); 908 series.add(x, f.getValue(x)); 909 } 910 911 XYSeriesCollection collection = new XYSeriesCollection(series); 912 return collection; 913 914 } 915 916 928 public static CategoryDataset createCategoryDataset(String rowKeyPrefix, 929 String columnKeyPrefix, 930 double[][] data) { 931 932 DefaultCategoryDataset result = new DefaultCategoryDataset(); 933 for (int r = 0; r < data.length; r++) { 934 String rowKey = rowKeyPrefix + (r + 1); 935 for (int c = 0; c < data[r].length; c++) { 936 String columnKey = columnKeyPrefix + (c + 1); 937 result.addValue(new Double (data[r][c]), rowKey, columnKey); 938 } 939 } 940 return result; 941 942 } 943 944 955 public static CategoryDataset createCategoryDataset(String rowKeyPrefix, 956 String columnKeyPrefix, 957 Number [][] data) { 958 959 DefaultCategoryDataset result = new DefaultCategoryDataset(); 960 for (int r = 0; r < data.length; r++) { 961 String rowKey = rowKeyPrefix + (r + 1); 962 for (int c = 0; c < data[r].length; c++) { 963 String columnKey = columnKeyPrefix + (c + 1); 964 result.addValue(data[r][c], rowKey, columnKey); 965 } 966 } 967 return result; 968 969 } 970 971 983 public static CategoryDataset createCategoryDataset(String [] rowKeys, 984 String [] columnKeys, 985 double[][] data) { 986 987 DefaultCategoryDataset result = new DefaultCategoryDataset(); 988 for (int r = 0; r < data.length; r++) { 989 String rowKey = rowKeys[r]; 990 for (int c = 0; c < data[r].length; c++) { 991 String columnKey = columnKeys[c]; 992 result.addValue(new Double (data[r][c]), rowKey, columnKey); 993 } 994 } 995 return result; 996 997 } 998 999 1008 public static CategoryDataset createCategoryDataset(String rowKey, KeyedValues rowData) { 1009 1010 DefaultCategoryDataset result = new DefaultCategoryDataset(); 1011 for (int i = 0; i < rowData.getItemCount(); i++) { 1012 result.addValue(rowData.getValue(i), rowKey, rowData.getKey(i)); 1013 } 1014 return result; 1015 1016 } 1017 1018 1026 public static boolean isEmptyOrNull(XYDataset data) { 1027 1028 boolean result = true; 1029 1030 if (data != null) { 1031 for (int s = 0; s < data.getSeriesCount(); s++) { 1032 if (data.getItemCount(s) > 0) { 1033 result = false; 1034 continue; 1035 } 1036 } 1037 } 1038 1039 return result; 1040 1041 } 1042 1043 1051 public static boolean isEmptyOrNull(PieDataset dataset) { 1052 1053 if (dataset == null) { 1054 return true; 1055 } 1056 1057 int itemCount = dataset.getItemCount(); 1058 if (itemCount == 0) { 1059 return true; 1060 } 1061 1062 for (int item = 0; item < itemCount; item++) { 1063 Number y = dataset.getValue(item); 1064 if (y != null) { 1065 double yy = y.doubleValue(); 1066 if (yy > 0.0) { 1067 return false; 1068 } 1069 } 1070 } 1071 1072 return true; 1073 1074 } 1075 1076 1084 public static boolean isEmptyOrNull(CategoryDataset data) { 1085 1086 if (data == null) { 1087 return true; 1088 } 1089 1090 int rowCount = data.getRowCount(); 1091 int columnCount = data.getColumnCount(); 1092 if (rowCount == 0 || columnCount == 0) { 1093 return true; 1094 } 1095 1096 for (int r = 0; r < rowCount; r++) { 1097 for (int c = 0; c < columnCount; c++) { 1098 if (data.getValue(r, c) != null) { 1099 return false; 1100 } 1101 1102 } 1103 } 1104 1105 return true; 1106 1107 } 1108 1109 1116 public static PieDataset limitPieDataset(PieDataset data, double percentThreshold) { 1117 return DatasetUtilities.limitPieDataset(data, percentThreshold, 1, "Other"); 1118 } 1119 1120 1129 public static PieDataset limitPieDataset(PieDataset data, 1130 double percentThreshold, int sliceThreshold) { 1131 return DatasetUtilities.limitPieDataset(data, percentThreshold, sliceThreshold, "Other"); 1132 } 1133 1134 1145 public static PieDataset limitPieDataset(PieDataset data, 1146 double percentThreshold, int sliceThreshold, 1147 String label) { 1148 DefaultPieDataset newDataset = new DefaultPieDataset(); 1149 double total = DatasetUtilities.getPieDatasetTotal(data); 1150 1151 List keys = data.getKeys(); 1153 ArrayList otherKeys = new ArrayList (); 1154 Iterator kIter = keys.iterator(); 1155 while (kIter.hasNext()) { 1156 Comparable key = (Comparable ) kIter.next(); 1157 Number dataValue = data.getValue(key); 1158 if (dataValue != null) { 1159 double value = dataValue.doubleValue(); 1160 if (value / total < percentThreshold / 100) { 1161 otherKeys.add(key); 1162 } 1163 } 1164 } 1165 1166 kIter = keys.iterator(); 1168 double otherValue = 0; 1169 while (kIter.hasNext()) { 1170 Comparable key = (Comparable ) kIter.next(); 1171 Number dataValue = data.getValue(key); 1172 if (dataValue != null) { 1173 if (otherKeys.contains(key) && otherKeys.size() > sliceThreshold) { 1174 otherValue += dataValue.doubleValue(); 1176 } 1177 else { 1178 newDataset.setValue(key, dataValue); 1180 } 1181 } 1182 if (otherKeys.size() > sliceThreshold) { 1184 newDataset.setValue(label, otherValue); 1185 } 1186 } 1187 return newDataset; 1188 } 1189 1190 1197 public static Range getStackedRangeExtent(TableXYDataset data) { 1198 if (data == null) { 1200 return null; 1201 } 1202 double minimum = Double.POSITIVE_INFINITY; 1203 double maximum = Double.NEGATIVE_INFINITY; 1204 for (int itemNo = 0; itemNo < data.getItemCount(); itemNo++) { 1205 double value = 0; 1206 for (int seriesNo = 0; seriesNo < data.getSeriesCount(); seriesNo++) { 1207 if (data.getYValue(seriesNo, itemNo) != null) { 1208 value += (data.getYValue(seriesNo, itemNo).doubleValue()); 1209 } 1210 } 1211 if (value > maximum) { 1212 maximum = value; 1213 } 1214 if (value < minimum) { 1215 minimum = value; 1216 } 1217 } 1218 if (minimum == Double.POSITIVE_INFINITY) { 1219 return null; 1220 } 1221 else { 1222 return new Range(minimum, maximum); 1223 } 1224 } 1225 1226 1234 public static Range getCumulativeRangeExtent(CategoryDataset dataset) { 1235 1236 if (dataset == null) { 1237 return null; 1238 } 1239 1240 boolean allItemsNull = true; double minimum = 0.0; 1243 double maximum = 0.0; 1244 for (int row = 0; row < dataset.getRowCount(); row++) { 1245 double runningTotal = 0.0; 1246 for (int column = 0; column < dataset.getColumnCount() - 1; column++) { 1247 Number n = dataset.getValue(row, column); 1248 if (n != null) { 1249 allItemsNull = false; 1250 double value = n.doubleValue(); 1251 runningTotal = runningTotal + value; 1252 minimum = Math.min(minimum, runningTotal); 1253 maximum = Math.max(maximum, runningTotal); 1254 } 1255 } 1256 } 1257 if (!allItemsNull) { 1258 return new Range(minimum, maximum); 1259 } 1260 else { 1261 return null; 1262 } 1263 1264 } 1265 1266} 1267 | Popular Tags |