Skip to content
Snippets Groups Projects
Commit 55e6da38 authored by Hwaipy Li's avatar Hwaipy Li
Browse files

Fix Histogram

1. Improved the constructor. Now it has better performance when data is
vary large (e.g. >1M).
2. Fixed line 99. When bin==numBins, the value falls on the next bin of
the max bin, not right on the edge.
parent 1cfc7c79
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,6 @@ package com.xeiam.xchart;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
......@@ -46,14 +45,19 @@ public class Histogram {
this.numBins = numBins;
this.originalData = data;
List<Double> dataAsList = new ArrayList<Double>();
Iterator<? extends Number> itr = data.iterator();
while (itr.hasNext()) {
dataAsList.add(((Number) itr.next()).doubleValue());
Double tempMax = Double.MIN_VALUE;
Double tempMin = Double.MAX_VALUE;
for (Number number : data) {
double value = number.doubleValue();
if (value > tempMax) {
tempMax = value;
}
if (value < tempMin) {
tempMin = value;
}
}
Collections.sort(dataAsList);
this.min = dataAsList.get(0);
this.max = dataAsList.get(dataAsList.size() - 1);
max = tempMax;
min = tempMin;
init();
}
......@@ -92,8 +96,7 @@ public class Histogram {
else if (bin > numBins) { /* this data point is bigger than max */
// System.out.println("greater than");
}
else if (bin == numBins) { // this falls right on the edge of the max bin
tempYAxisData[bin - 1] += 1;
else if (bin == numBins) { // this falls on the next bin of the max bin
}
else {
tempYAxisData[bin] += 1;
......@@ -101,7 +104,7 @@ public class Histogram {
}
yAxisData = new ArrayList<Double>(numBins);
for (double d : tempYAxisData) {
yAxisData.add(new Double(d));
yAxisData.add(d);
}
// x axis data
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment