Niek Tax
Niek Tax

Reputation: 841

Setting histogram breaks in JFreeChart

I am using JFreeChart to draw histograms by filling a HistogramDataset object with my data and using the ChartFactory.createHistogram(). However, So far I have not been able to find anything in the documentation on how to set the breaks of the histogram. Am I missing anything, or does JFreeChart nog offer this functionality?

To illustrate what I mean with breaks, see the following two histograms generated from the same data with identical number of bins, but with different breaks. Note how the shapes of the distribution are very different between the two histograms, therefore it is important to be able to control the breaks.

enter image description here | height = 50px enter image description here | height = 50px]

Upvotes: 3

Views: 434

Answers (1)

trashgod
trashgod

Reputation: 205855

SimpleHistogramBin is a good choice for this, as it allows specifying the bin bounds. Add the resulting bins to a SimpleHistogramDataset for use with ChartFactory.createHistogram(). Invoke setAdjustForBinSize() as needed.

SimpleHistogramDataset data = new SimpleHistogramDataset("Time");
for (int i = 10; i < 70; i += 10) {
    data.addBin(new SimpleHistogramBin(i, i + 10, true, false));
}
data.setAdjustForBinSize(false);

image

Upvotes: 2

Related Questions