Following is a code to arrange 4 Bins in SimpleHistogramDataset.
public class SimpleHistogramDemo extends JFrame{
private SimpleHistogramDataset dataset;
public SimpleHistogramDemo(String title) {
super(title);
// create the dataset with appropriate bins and some initial data
this.dataset = new SimpleHistogramDataset("Key");
dataset.addBin(new SimpleHistogramBin(10, 15, true, false));
dataset.addBin(new SimpleHistogramBin(15, 20, true, false));
dataset.addBin(new SimpleHistogramBin(20, 25, true, false));
dataset.addBin(new SimpleHistogramBin(25, 30, true, false));
try{
dataset.addObservations(new double[] {10,12,13,17,16,18,22,25,24,23,21});
}catch(java.lang.RuntimeException rte){
System.out.println("some value Out of bin");
}
JFreeChart chart = ChartFactory.createHistogram("",
"Covers Passed", "Count", dataset, PlotOrientation.VERTICAL,
false, false, false);
XYPlot plot = (XYPlot) chart.getPlot();
plot.setDomainZeroBaselineVisible(false);
plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
plot.getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
ChartPanel panel = new ChartPanel(chart);
getContentPane().setLayout(new BorderLayout());
getContentPane().add(panel);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
SimpleHistogramDemo demo = new SimpleHistogramDemo(
"JFreeChart: SimpleHistogramDemo");
demo.pack();
demo.setVisible(true);
}
});
}
}
This example displays all integer numbers from 9 to 30 on x axis ,whereas I want to display only Bin ranges on x axis in such a way that each bin can be identified by its lower and upper bounds,i.e. Bin 1 should start from 10 and end at 15 similarly Bin 2 starts from 15 and end at 20 and so on. Also range labels on the Y axis are not displaying. How to solve these 2 problems?