ingo@617: package de.intevation.gnv.chart; ingo@617: ingo@617: import org.apache.log4j.Logger; ingo@617: ingo@617: import org.jfree.chart.ChartTheme; sascha@623: ingo@617: import org.jfree.chart.plot.XYPlot; ingo@617: ingo@617: import org.jfree.data.statistics.HistogramDataset; ingo@617: ingo@617: /** ingo@617: * @author Ingo Weinzierl (ingo.weinzierl@intevation.de) ingo@617: */ ingo@617: public class DefaultHistogram ingo@617: extends AbstractHistogram ingo@617: { ingo@617: // TODO take a better default value ingo@617: public static final int DEFAULT_BINS = 15; ingo@617: ingo@617: private static Logger logger = Logger.getLogger(DefaultHistogram.class); ingo@617: ingo@617: ingo@617: public DefaultHistogram( ingo@617: ChartLabels labels, Object[] data, ChartTheme theme ingo@617: ) { ingo@617: super(labels, data, theme); ingo@617: } ingo@617: ingo@617: ingo@617: protected void applyDatasets() { ingo@617: XYPlot plot = (XYPlot) chart.getPlot(); ingo@617: ingo@617: // prepare data and create add them to histogram dataset ingo@617: String name = (String) data[0]; ingo@617: double[] values = toDouble((Double[]) data[1]); ingo@617: ingo@617: HistogramDataset dataset = new HistogramDataset(); ingo@617: dataset.addSeries(name, values, DEFAULT_BINS); ingo@617: ingo@617: plot.setDataset(0, dataset); ingo@617: } ingo@617: ingo@617: ingo@617: protected double[] toDouble(Double[] array) { ingo@617: int length = array.length; ingo@617: double[] values = new double[length]; ingo@617: ingo@617: for(int i = 0; i < length; i++) { ingo@617: values[i] = array[i].doubleValue(); ingo@617: } ingo@617: ingo@617: return values; ingo@617: } ingo@617: } ingo@617: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :