List of usage examples for org.jfree.data.statistics SimpleHistogramDataset SimpleHistogramDataset
public SimpleHistogramDataset(Comparable key)
From source file:info.financialecology.finance.utilities.datastruct.VersatileChart.java
public JFreeChart drawSimpleHistogram(String name, ArrayList<VersatileTimeSeries> atsArray) { JFreeChart chart;/* ww w .j a va 2 s.c o m*/ int count = 0; double min = 0, max = 0, tmpMin, tmpMax; for (VersatileTimeSeries ats : atsArray) { if (count == 0) { min = ats.getMinY(); max = ats.getMaxY(); } else { tmpMin = ats.getMinY(); tmpMax = ats.getMaxY(); min = tmpMin < min ? tmpMin : min; max = tmpMax > max ? tmpMax : max; } } max = max > 0 ? max * 1.05 : max / 1.05; min = min > 0 ? min / 1.05 : min * 1.05; SimpleHistogramDataset dataSet = new SimpleHistogramDataset(name); for (int i = 0; i < params.numBins; i++) { double start = min + i * ((max - min) / params.numBins); double end = start + ((max - min) / params.numBins) * 0.999999999999; SimpleHistogramBin histBin = new SimpleHistogramBin(start, end, true, true); dataSet.addBin(histBin); } for (VersatileTimeSeries ats : atsArray) { for (int i = 0; i < ats.getItemCount(); i++) { double value = ats.getValue(i).doubleValue(); try { dataSet.addObservation(ats.getValue(i).doubleValue()); } catch (Throwable t) { // sometimes this throws an exception when the value falls within the narrow gaps of the bins } } } chart = ChartFactory.createHistogram(params.title, params.xLabel, params.yLabel, dataSet, PlotOrientation.VERTICAL, params.legend, params.toolTips, false); return chart; }
From source file:jchrest.gui.Shell.java
private JPanel getHistogramPane(Map<Integer, Integer> contentSizes, String label, String title, String xAxis) { int largest = 0; for (Integer key : contentSizes.keySet()) { if (key > largest) largest = key;/*from ww w . j ava2s . c o m*/ } SimpleHistogramDataset dataset = new SimpleHistogramDataset(label); for (int i = 0; i <= largest; ++i) { SimpleHistogramBin bin = new SimpleHistogramBin((double) i, (double) (i + 1), true, false); int count = 0; if (contentSizes.containsKey(i)) { count = contentSizes.get(i); } bin.setItemCount(count); dataset.addBin(bin); } PlotOrientation orientation = PlotOrientation.VERTICAL; boolean show = false; boolean toolTips = true; boolean urls = false; JFreeChart chart = ChartFactory.createHistogram(title, xAxis, "frequency", dataset, orientation, show, toolTips, urls); JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.add(new ChartPanel(chart, 400, 300, 200, 100, 600, 600, true, true, true, true, true, true)); JButton saveButton = new JButton("Save Data"); saveButton.setToolTipText("Save the histogram data to a CSV file"); saveButton.addActionListener(new SaveHistogramActionListener(this, contentSizes)); panel.add(saveButton, BorderLayout.SOUTH); return panel; }