List of usage examples for org.jfree.data.statistics SimpleHistogramBin setItemCount
public void setItemCount(int count)
From source file:org.jfree.data.statistics.SimpleHistogramBinTest.java
/** * Serialize an instance, restore it, and check for equality. *///from w w w . ja v a2 s .c o m @Test public void testSerialization() { SimpleHistogramBin b1 = new SimpleHistogramBin(1.0, 2.0, false, true); b1.setItemCount(123); SimpleHistogramBin b2 = (SimpleHistogramBin) TestUtilities.serialised(b1); assertEquals(b1, b2); }
From source file:org.jfree.data.statistics.SimpleHistogramBinTest.java
/** * Some checks for the clone() method.//from w ww . j a v a 2s .c o m */ @Test public void testCloning() throws CloneNotSupportedException { SimpleHistogramBin b1 = new SimpleHistogramBin(1.1, 2.2, false, true); b1.setItemCount(99); SimpleHistogramBin b2 = (SimpleHistogramBin) b1.clone(); assertTrue(b1 != b2); assertTrue(b1.getClass() == b2.getClass()); assertTrue(b1.equals(b2)); // check that clone is independent of the original b2.setItemCount(111); assertFalse(b1.equals(b2)); }
From source file:imageviewer.tools.HistogramTool.java
public void plot(MouseEvent e) { if (e.getSource() instanceof ImagePanel) { Image image = ((ImagePanel) e.getSource()).getSource(); Histogram h = image.getHistogram(); SimpleHistogramDataset shd = new SimpleHistogramDataset("Voxel distribution"); for (int i = 0, numBands = h.getNumBands(); i < numBands; i++) { int[] binData = h.getBins(i); for (int j = 0; j < binData.length; j++) { SimpleHistogramBin shb = new SimpleHistogramBin(j - 0.5, j + 0.5, true, false); shb.setItemCount(binData[j]); shd.addBin(shb);/*w ww .j a v a 2s . c o m*/ } } double[] domainBounds = null, rangeBounds = null; if (chart != null) { ValueAxis va = chart.getXYPlot().getDomainAxis(); domainBounds = new double[] { va.getLowerBound(), va.getUpperBound() }; va = chart.getXYPlot().getRangeAxis(); rangeBounds = new double[] { va.getLowerBound(), va.getUpperBound() }; } chart = ChartFactory.createHistogram(null, "Voxel value", "Count", shd, PlotOrientation.VERTICAL, false, true, false); chart.setBackgroundPaint(new Color(20, 30, 45)); chart.setAntiAlias(true); ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); domainAxis.setLabelFont(axisFont); domainAxis.setTickLabelFont(tickFont); domainAxis.setAxisLinePaint(Color.white); domainAxis.setTickLabelPaint(Color.white); domainAxis.setLabelPaint(Color.white); if (domainBounds != null) { domainAxis.setAutoRange(false); domainAxis.setLowerBound(domainBounds[0]); domainAxis.setUpperBound(domainBounds[1]); } else { domainAxis.setLowerBound(0); } ValueAxis rangeAxis = chart.getXYPlot().getRangeAxis(); rangeAxis.setLabelFont(axisFont); rangeAxis.setTickLabelFont(tickFont); rangeAxis.setAxisLinePaint(Color.white); rangeAxis.setTickLabelPaint(Color.white); rangeAxis.setLabelPaint(Color.white); if (rangeBounds != null) { rangeAxis.setAutoRange(false); rangeAxis.setLowerBound(rangeBounds[0]); rangeAxis.setUpperBound(rangeBounds[1]); } chart.getXYPlot().getRenderer().setSeriesPaint(0, new Color(0, 51, 113)); ((XYBarRenderer) chart.getXYPlot().getRenderer()).setDrawBarOutline(false); chart.getXYPlot().setBackgroundAlpha(0.05f); double[] mean = h.getMean(); double[] sd = h.getStandardDeviation(); IntervalMarker im = new IntervalMarker(mean[0] - sd[0] / 2, mean[0] + sd[0] / 2); im.setPaint(new Color(200, 200, 200, 128)); chart.getXYPlot().addDomainMarker(0, im, Layer.BACKGROUND); cp.setChart(chart); } }
From source file:org.jfree.data.statistics.SimpleHistogramDataset.java
/** * Removes all current observation data and sends a * {@link DatasetChangeEvent} to all registered listeners. * * @since 1.0.6/* ww w.ja v a 2 s.c o m*/ * * @see #addObservations(double[]) * @see #removeAllBins() */ public void clearObservations() { Iterator iterator = this.bins.iterator(); while (iterator.hasNext()) { SimpleHistogramBin bin = (SimpleHistogramBin) iterator.next(); bin.setItemCount(0); } notifyListeners(new DatasetChangeEvent(this, this)); }
From source file:org.jfree.data.statistics.SimpleHistogramDataset.java
/** * Adds an observation to the dataset (by incrementing the item count for * the appropriate bin). A runtime exception is thrown if the value does * not fit into any bin./*from www .j a va 2s .c om*/ * * @param value the value. * @param notify send {@link DatasetChangeEvent} to listeners? */ public void addObservation(double value, boolean notify) { boolean placed = false; Iterator iterator = this.bins.iterator(); while (iterator.hasNext() && !placed) { SimpleHistogramBin bin = (SimpleHistogramBin) iterator.next(); if (bin.accepts(value)) { bin.setItemCount(bin.getItemCount() + 1); placed = true; } } if (!placed) { throw new RuntimeException("No bin."); } if (notify) { notifyListeners(new DatasetChangeEvent(this, this)); } }
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 w w w. j a v a 2s .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; }
From source file:org.jfree.data.statistics.SimpleHistogramBinTest.java
/** * Ensure that the equals() method can distinguish all fields. *///from ww w . jav a2 s . c o m @Test public void testEquals() { SimpleHistogramBin b1 = new SimpleHistogramBin(1.0, 2.0); SimpleHistogramBin b2 = new SimpleHistogramBin(1.0, 2.0); assertTrue(b1.equals(b2)); assertTrue(b2.equals(b1)); b1 = new SimpleHistogramBin(1.1, 2.0, true, true); assertFalse(b1.equals(b2)); b2 = new SimpleHistogramBin(1.1, 2.0, true, true); assertTrue(b1.equals(b2)); b1 = new SimpleHistogramBin(1.1, 2.2, true, true); assertFalse(b1.equals(b2)); b2 = new SimpleHistogramBin(1.1, 2.2, true, true); assertTrue(b1.equals(b2)); b1 = new SimpleHistogramBin(1.1, 2.2, false, true); assertFalse(b1.equals(b2)); b2 = new SimpleHistogramBin(1.1, 2.2, false, true); assertTrue(b1.equals(b2)); b1 = new SimpleHistogramBin(1.1, 2.2, false, false); assertFalse(b1.equals(b2)); b2 = new SimpleHistogramBin(1.1, 2.2, false, false); assertTrue(b1.equals(b2)); b1.setItemCount(99); assertFalse(b1.equals(b2)); b2.setItemCount(99); assertTrue(b1.equals(b2)); }