List of usage examples for org.jfree.data.statistics HistogramBin incrementCount
public void incrementCount()
From source file:org.jfree.data.statistics.HistogramDataset.java
/** * Adds a series to the dataset. Any data value less than minimum will be * assigned to the first bin, and any data value greater than maximum will * be assigned to the last bin. Values falling on the boundary of * adjacent bins will be assigned to the higher indexed bin. * * @param key the series key (<code>null</code> not permitted). * @param values the raw observations./*from w w w .j a v a 2 s. co m*/ * @param bins the number of bins (must be at least 1). * @param minimum the lower bound of the bin range. * @param maximum the upper bound of the bin range. */ public void addSeries(Comparable key, double[] values, int bins, double minimum, double maximum) { ParamChecks.nullNotPermitted(key, "key"); ParamChecks.nullNotPermitted(values, "values"); if (bins < 1) { throw new IllegalArgumentException("The 'bins' value must be at least 1."); } double binWidth = (maximum - minimum) / bins; double lower = minimum; double upper; List binList = new ArrayList(bins); for (int i = 0; i < bins; i++) { HistogramBin bin; // make sure bins[bins.length]'s upper boundary ends at maximum // to avoid the rounding issue. the bins[0] lower boundary is // guaranteed start from min if (i == bins - 1) { bin = new HistogramBin(lower, maximum); } else { upper = minimum + (i + 1) * binWidth; bin = new HistogramBin(lower, upper); lower = upper; } binList.add(bin); } // fill the bins for (int i = 0; i < values.length; i++) { int binIndex = bins - 1; if (values[i] < maximum) { double fraction = (values[i] - minimum) / (maximum - minimum); if (fraction < 0.0) { fraction = 0.0; } binIndex = (int) (fraction * bins); // rounding could result in binIndex being equal to bins // which will cause an IndexOutOfBoundsException - see bug // report 1553088 if (binIndex >= bins) { binIndex = bins - 1; } } HistogramBin bin = (HistogramBin) binList.get(binIndex); bin.incrementCount(); } // generic map for each series Map map = new HashMap(); map.put("key", key); map.put("bins", binList); map.put("values.length", new Integer(values.length)); map.put("bin width", new Double(binWidth)); this.list.add(map); fireDatasetChanged(); }