List of usage examples for org.jfree.data.statistics HistogramDataset addSeries
public void addSeries(Comparable key, double[] values, int bins)
From source file:org.jfree.data.statistics.HistogramDatasetTest.java
/** * Confirm that cloning works./*from ww w.j av a 2s .c o m*/ */ @Test public void testCloning() throws CloneNotSupportedException { double[] values = { 1.0, 2.0, 3.0, 4.0, 6.0, 12.0, 5.0, 6.3, 4.5 }; HistogramDataset d1 = new HistogramDataset(); d1.addSeries("Series 1", values, 5); HistogramDataset d2 = (HistogramDataset) d1.clone(); assertTrue(d1 != d2); assertTrue(d1.getClass() == d2.getClass()); assertTrue(d1.equals(d2)); // simple check for independence d1.addSeries("Series 2", new double[] { 1.0, 2.0, 3.0 }, 2); assertFalse(d1.equals(d2)); d2.addSeries("Series 2", new double[] { 1.0, 2.0, 3.0 }, 2); assertTrue(d1.equals(d2)); }
From source file:org.jfree.data.statistics.HistogramDatasetTest.java
/** * Another check for the addSeries() method. */// w w w . j av a 2s.co m @Test public void testAddSeries2() { double[] values = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; HistogramDataset hd = new HistogramDataset(); hd.addSeries("S1", values, 5); assertEquals(0.0, hd.getStartXValue(0, 0), EPSILON); assertEquals(1.0, hd.getEndXValue(0, 0), EPSILON); assertEquals(1.0, hd.getYValue(0, 0), EPSILON); assertEquals(1.0, hd.getStartXValue(0, 1), EPSILON); assertEquals(2.0, hd.getEndXValue(0, 1), EPSILON); assertEquals(1.0, hd.getYValue(0, 1), EPSILON); assertEquals(2.0, hd.getStartXValue(0, 2), EPSILON); assertEquals(3.0, hd.getEndXValue(0, 2), EPSILON); assertEquals(1.0, hd.getYValue(0, 2), EPSILON); assertEquals(3.0, hd.getStartXValue(0, 3), EPSILON); assertEquals(4.0, hd.getEndXValue(0, 3), EPSILON); assertEquals(1.0, hd.getYValue(0, 3), EPSILON); assertEquals(4.0, hd.getStartXValue(0, 4), EPSILON); assertEquals(5.0, hd.getEndXValue(0, 4), EPSILON); assertEquals(2.0, hd.getYValue(0, 4), EPSILON); }
From source file:tarea1.histogram.java
private ChartPanel createChartPanel() { // dataset//w ww .j av a 2s . c o m HistogramDataset dataset = new HistogramDataset(); Raster raster = image.getRaster(); final int w = image.getWidth(); final int h = image.getHeight(); double[] r = new double[w * h]; r = raster.getSamples(0, 0, w, h, 0, r); dataset.addSeries("Red", r, BINS); r = raster.getSamples(0, 0, w, h, 1, r); dataset.addSeries("Green", r, BINS); r = raster.getSamples(0, 0, w, h, 2, r); dataset.addSeries("Blue", r, BINS); // chart JFreeChart chart = ChartFactory.createHistogram("Histogram", "Value", "Count", dataset, PlotOrientation.VERTICAL, true, true, false); XYPlot plot = (XYPlot) chart.getPlot(); XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setBarPainter(new StandardXYBarPainter()); // translucent red, green & blue Paint[] paintArray = { new Color(0x80ff0000, true), new Color(0x8000ff00, true), new Color(0x800000ff, true) }; plot.setDrawingSupplier( new DefaultDrawingSupplier(paintArray, DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE, DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE, DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE)); ChartPanel panel = new ChartPanel(chart); panel.setMouseWheelEnabled(true); return panel; }
From source file:org.jfree.data.statistics.HistogramDatasetTest.java
/** * A test to show the limitation addressed by patch 2902842. *//*from w ww . j a v a2s . co m*/ @Test public void test2902842() { this.lastEvent = null; double[] values = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0 }; HistogramDataset hd = new HistogramDataset(); hd.addChangeListener(this); hd.addSeries("S1", values, 5); assertNotNull(this.lastEvent); }
From source file:agentlogfileanalyzer.histogram.AbstractHistogram.java
/** * Returns a panel containing a histogram. The data displayed in the * histogram is given as parameter. Data not inside the given limits is * discarded.//from w w w . j a v a2 s. c o m * * @param _histogramData * the data displayed in the histogram * @param _lowerLimit * the lower limit that was entered by the user * @param _upperLimit * the upper limit that was entered by the user * @return a <code>JPanel</code> containing the histogram */ JPanel createHistogram(Vector<Double> _histogramData, double _lowerLimit, double _upperLimit) { // Remove values outside the given limits... Vector<Double> vectorHistogramDataWithinLimits = new Vector<Double>(); for (Iterator<Double> iterator = _histogramData.iterator(); iterator.hasNext();) { double d = ((Double) iterator.next()).doubleValue(); if (valueWithinLimits(d, _lowerLimit, _upperLimit)) { vectorHistogramDataWithinLimits.add(d); } } // Store number of elements shown in histogram... this.numberOfVisibleClassifiers = vectorHistogramDataWithinLimits.size(); // Convert vector to array... double[] arrayHistogramDataWithinLimits = new double[vectorHistogramDataWithinLimits.size()]; for (int i = 0; i < vectorHistogramDataWithinLimits.size(); i++) { double d = vectorHistogramDataWithinLimits.get(i).doubleValue(); arrayHistogramDataWithinLimits[i] = d; } if (arrayHistogramDataWithinLimits.length > 0) { // Create // histogram... HistogramDataset data = new HistogramDataset(); data.addSeries("Suchwert", // key arrayHistogramDataWithinLimits, // data Math.max(100, arrayHistogramDataWithinLimits.length) // #bins ); JFreeChart chart = ChartFactory.createHistogram(description, // title description, // x axis label "frequency", // y axis label data, // data PlotOrientation.VERTICAL, // orientation false, // legend true, // tooltips false // URL ); return new ChartPanel(chart); } else { return createErrorPanel("No data available (within the given limits)."); } }
From source file:org.utgenome.core.cui.DrawHistogram.java
public void execute() throws Exception { InputStream in = null;//from w w w.j a v a 2 s. c o m if ("-".equals(input)) { _logger.info("reading from STDIN"); in = new StandardInputStream(); } else { _logger.info("reading from " + input); in = new FileInputStream(input); } List<Double> data = new ArrayList<Double>(); BufferedReader dataSetInput = new BufferedReader(new InputStreamReader(in)); int lineCount = 1; try { // read data set boolean cutOffTail = !Double.isNaN(xMax); boolean cutOffHead = !Double.isNaN(xMin); for (String line; (line = dataSetInput.readLine()) != null; lineCount++) { if (lineCount % 100000 == 0) _logger.info(String.format("read %,d data points", lineCount)); if (line.startsWith("#")) continue; double v = Double.parseDouble(line); if (cutOffTail && v > xMax) continue; if (cutOffHead && v < xMin) continue; data.add(v); } double[] value = new double[data.size()]; for (int i = 0; i < data.size(); ++i) { value[i] = data.get(i); } // draw histogram HistogramDataset dataSet = new HistogramDataset(); dataSet.setType(HistogramType.FREQUENCY); dataSet.addSeries("data", value, numBins); JFreeChart chart = ChartFactory.createHistogram(null, null, "Frequency", dataSet, PlotOrientation.VERTICAL, false, false, false); if (title != null) { chart.setTitle(title); } ValueAxis domainAxis = chart.getXYPlot().getDomainAxis(); if (cutOffHead) { domainAxis.setLowerBound(xMin); } if (cutOffTail) { domainAxis.setUpperBound(xMax); } if (xLabel != null) { domainAxis.setLabel(xLabel); } if (yLog) { LogarithmicAxis logAxis = new LogarithmicAxis("Frequency"); logAxis.setAllowNegativesFlag(true); logAxis.setAutoRangeIncludesZero(true); chart.getXYPlot().setRangeAxis(logAxis); } if (!Double.isNaN(yMin)) { chart.getXYPlot().getRangeAxis().setLowerBound(yMin); } if (!Double.isNaN(yMax)) { chart.getXYPlot().getRangeAxis().setUpperBound(yMax); } File outputFile = new File(output); _logger.info("output to " + outputFile); ChartUtilities.saveChartAsPNG(outputFile, chart, width, height); } catch (Exception e) { throw new Exception(String.format("error at line %d: %s", lineCount, e)); } }
From source file:ch.zhaw.ias.dito.ui.util.HistogramFrame.java
public HistogramFrame(Question q) { String title = Translation.INSTANCE.get("misc.graphic.histogram") + " " + q.getName(); setTitle(title);//from w w w. j a v a 2 s.c o m HistogramDataset hist = new HistogramDataset(); hist.setType(HistogramType.FREQUENCY); Set<Double> values = new TreeSet<Double>(); q.getData().addValuesToCollection(values); int numOfBins = Math.min(values.size(), (q.getData().filteredLength() / 20) + 10); hist.addSeries(q.getName(), q.getData().getValues(), numOfBins); JFreeChart chart = ChartFactory.createHistogram(title, Translation.INSTANCE.get("misc.graphic.value"), Translation.INSTANCE.get("misc.graphic.frequency"), hist, PlotOrientation.VERTICAL, false, true, false); this.add(new ChartPanel(chart), BorderLayout.CENTER); this.setSize(300, 300); this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); this.setVisible(true); }
From source file:net.imglib2.script.analysis.Histogram.java
/** Return the JFreeChart with this histogram, and as a side effect, show it in a JFrame * that provides the means to edit the dimensions and also the plot properties via a popup menu. */ public JFreeChart asChart(final boolean show) { double[] d = new double[this.size()]; int i = 0;//from w w w .ja v a 2s .co m for (Number num : this.values()) d[i++] = num.doubleValue(); HistogramDataset hd = new HistogramDataset(); hd.setType(HistogramType.RELATIVE_FREQUENCY); String title = "Histogram"; hd.addSeries(title, d, d.length); JFreeChart chart = ChartFactory.createHistogram(title, "", "", hd, PlotOrientation.VERTICAL, false, false, false); setTheme(chart); if (show) { JFrame frame = new JFrame(title); frame.getContentPane().add(new ChartPanel(chart)); frame.pack(); frame.setVisible(true); } return chart; }
From source file:biz.ixnay.pivot.charts.skin.jfree.HistogramViewSkin.java
private HistogramDataset createDataSet(HistogramView chartView) { HistogramDataset dataset = new HistogramDataset(); dataset.setType(HistogramType.FREQUENCY); for (Object object : chartView.getChartData()) { HistogramSeries<?> histogramSeries = (HistogramSeries<?>) object; dataset.addSeries(histogramSeries.getName(), getValues(histogramSeries), histogramSeries.getBinCount()); }//from w ww. j a v a 2 s. com /*double[] values = getValues(chartView.getChartData()); int binCount = chartView.getBinCount(); dataset.addSeries("", values, binCount);*/ return dataset; }
From source file:sim.util.media.chart.HistogramGenerator.java
/** Adds a series, plus a (possibly null) SeriesChangeListener which will receive a <i>single</i> event if/when the series is deleted from the chart by the user. Returns the series attributes. */ public SeriesAttributes addSeries(double[] vals, int bins, String name, SeriesChangeListener stopper) { if (vals == null || vals.length == 0) vals = new double[] { 0 }; // ya gotta have at least one val HistogramDataset dataset = (HistogramDataset) (getSeriesDataset()); int i = dataset.getSeriesCount(); dataset.setType(histogramType); // It looks like the histograms reset dataset.addSeries(new UniqueString(name), vals, bins); // need to have added the dataset BEFORE calling this since it'll try to change the name of the series HistogramSeriesAttributes csa = new HistogramSeriesAttributes(this, name, i, vals, bins, stopper); seriesAttributes.add(csa);/* w w w. ja va 2 s. c o m*/ revalidate(); // display the new series panel update(); // won't update properly unless I force it here by letting all the existing scheduled events to go through. Dumb design. :-( SwingUtilities.invokeLater(new Runnable() { public void run() { update(); } }); return csa; }