1 41 42 package org.jfree.chart.demo; 43 44 import org.jfree.data.AbstractSeriesDataset; 45 import org.jfree.data.DomainInfo; 46 import org.jfree.data.Range; 47 import org.jfree.data.RangeInfo; 48 import org.jfree.data.XYDataset; 49 50 58 public class SampleXYDataset2 extends AbstractSeriesDataset implements XYDataset, 59 DomainInfo, RangeInfo { 60 61 62 private static final int DEFAULT_SERIES_COUNT = 4; 63 64 65 private static final int DEFAULT_ITEM_COUNT = 100; 66 67 68 private static final double DEFAULT_RANGE = 200; 69 70 71 private Double [][] xValues; 72 73 74 private Double [][] yValues; 75 76 77 private int seriesCount; 78 79 80 private int itemCount; 81 82 83 private Number domainMin; 84 85 86 private Number domainMax; 87 88 89 private Number rangeMin; 90 91 92 private Number rangeMax; 93 94 95 private Range domainRange; 96 97 98 private Range range; 99 100 104 public SampleXYDataset2() { 105 this(DEFAULT_SERIES_COUNT, DEFAULT_ITEM_COUNT); 106 } 107 108 114 public SampleXYDataset2(int seriesCount, int itemCount) { 115 116 this.xValues = new Double [seriesCount][itemCount]; 117 this.yValues = new Double [seriesCount][itemCount]; 118 this.seriesCount = seriesCount; 119 this.itemCount = itemCount; 120 121 double minX = Double.POSITIVE_INFINITY; 122 double maxX = Double.NEGATIVE_INFINITY; 123 double minY = Double.POSITIVE_INFINITY; 124 double maxY = Double.NEGATIVE_INFINITY; 125 126 for (int series = 0; series < seriesCount; series++) { 127 for (int item = 0; item < itemCount; item++) { 128 129 double x = (Math.random() - 0.5) * DEFAULT_RANGE; 130 xValues[series][item] = new Double (x); 131 if (x < minX) { 132 minX = x; 133 } 134 if (x > maxX) { 135 maxX = x; 136 } 137 138 double y = (Math.random() + 0.5) * 6 * x + x; 139 yValues[series][item] = new Double (y); 140 if (y < minY) { 141 minY = y; 142 } 143 if (y > maxY) { 144 maxY = y; 145 } 146 147 } 148 } 149 150 this.domainMin = new Double (minX); 151 this.domainMax = new Double (maxX); 152 this.domainRange = new Range(minX, maxX); 153 154 this.rangeMin = new Double (minY); 155 this.rangeMax = new Double (maxY); 156 this.range = new Range(minY, maxY); 157 158 } 159 160 168 public Number getXValue(int series, int item) { 169 return xValues[series][item]; 170 } 171 172 180 public Number getYValue(int series, int item) { 181 return yValues[series][item]; 182 } 183 184 189 public int getSeriesCount() { 190 return this.seriesCount; 191 } 192 193 200 public String getSeriesName(int series) { 201 return "Sample " + series; 202 } 203 204 211 public int getItemCount(int series) { 212 return this.itemCount; 213 } 214 215 220 public Number getMinimumDomainValue() { 221 return this.domainMin; 222 } 223 224 229 public Number getMaximumDomainValue() { 230 return this.domainMax; 231 } 232 233 238 public Range getDomainRange() { 239 return this.domainRange; 240 } 241 242 247 public Number getMinimumRangeValue() { 248 return this.rangeMin; 249 } 250 251 256 public Number getMaximumRangeValue() { 257 return this.rangeMax; 258 } 259 260 265 public Range getValueRange() { 266 return this.range; 267 } 268 269 } 270 | Popular Tags |