List of usage examples for org.jfree.data.statistics HistogramDataset getItemCount
@Override public int getItemCount(int series)
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.SingleCellAnalysisController.java
/** * Create a polar series for a well, given the data we want to make the * series (and downstream the plot) for. * * @param singleCellWellDataHolder/*from w ww .j a v a 2 s . c o m*/ * @param data * @return the series. */ private XYSeries createPolarSeries(SingleCellConditionDataHolder singleCellConditionDataHolder) { XYSeries series = new XYSeries(singleCellConditionDataHolder.getPlateCondition().toString(), false); HistogramDataset histogramDataset = getHistogramDatasetForACondition(singleCellConditionDataHolder, singleCellConditionDataHolder.getPlateCondition().toString(), getNumberOfBins(singleCellConditionDataHolder)); // iterate through the series, even though we normally only have one here for (int i = 0; i < histogramDataset.getSeriesCount(); i++) { int itemCount = histogramDataset.getItemCount(i); // this is the number of bins for (int j = 0; j < itemCount; j++) { double startX = (double) histogramDataset.getStartX(i, j); double endX = (double) histogramDataset.getEndX(i, j); // the angle in the middle of the bin double theta = (startX + endX) / 2; // the frequency of this angle in the histogram Double radius = (Double) histogramDataset.getY(i, j); series.add(theta, radius); } } return series; }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.AngleDirectController.java
/** * Create a polar series for a well, given the data we want to make the * series (and downstream the plot) for. * * @param singleCellWellDataHolder//from w ww. java2 s. c o m * @param data * @return the series. */ private XYSeries createPolarSeries(SingleCellWellDataHolder singleCellWellDataHolder, Double[] data) { XYSeries series = new XYSeries(singleCellWellDataHolder.getWell().toString(), false); HistogramDataset histogramDataset = getHistogramDatasetForAWell( singleCellWellDataHolder.getWell().toString(), data, getNumberOfBins(singleCellWellDataHolder), HistogramType.FREQUENCY, true); // iterate through the series, even though we normally only have one here for (int i = 0; i < histogramDataset.getSeriesCount(); i++) { int itemCount = histogramDataset.getItemCount(i); // this is the number of bins for (int j = 0; j < itemCount; j++) { double startX = (double) histogramDataset.getStartX(i, j); double endX = (double) histogramDataset.getEndX(i, j); // the angle in the middle of the bin double theta = (startX + endX) / 2; // the frequency of this angle in the histogram Double radius = (Double) histogramDataset.getY(i, j); series.add(theta, radius); } } return series; }
From source file:org.locationtech.udig.processingtoolbox.tools.HistogramDialog.java
private void updateChart(SimpleFeatureCollection features, String field) { int bin = spinner.getSelection(); double[] values = getValues(features, field); HistogramDataset dataset = new HistogramDataset(); dataset.addSeries(field, values, bin, minMaxVisitor.getMinX(), minMaxVisitor.getMaxX()); dataset.setType(histogramType);/*from w ww. ja va2 s .com*/ JFreeChart chart = ChartFactory.createHistogram(EMPTY, null, null, dataset, PlotOrientation.VERTICAL, false, false, false); // 1. Create a single plot containing both the scatter and line chart.setBackgroundPaint(java.awt.Color.WHITE); chart.setBorderVisible(false); XYPlot plot = (XYPlot) chart.getPlot(); plot.setForegroundAlpha(0.85F); plot.setBackgroundPaint(java.awt.Color.WHITE); plot.setOrientation(PlotOrientation.VERTICAL); plot.setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY); plot.setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY); int fontStyle = java.awt.Font.BOLD; FontData fontData = getShell().getDisplay().getSystemFont().getFontData()[0]; NumberAxis valueAxis = new NumberAxis(cboField.getText()); valueAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); valueAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); valueAxis.setAutoRange(false); valueAxis.setRange(minMaxVisitor.getMinX(), minMaxVisitor.getMaxX()); String rangeAxisLabel = histogramType == HistogramType.FREQUENCY ? "Frequency" : "Ratio"; //$NON-NLS-1$ //$NON-NLS-2$ NumberAxis rangeAxis = new NumberAxis(rangeAxisLabel); rangeAxis.setLabelFont(new Font(fontData.getName(), fontStyle, 12)); rangeAxis.setTickLabelFont(new Font(fontData.getName(), fontStyle, 10)); if (histogramType == HistogramType.FREQUENCY) { rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); } XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer(); renderer.setShadowVisible(false); CustomXYBarPainter.selectedColumn = -1; // init renderer.setBarPainter(new CustomXYBarPainter()); renderer.setAutoPopulateSeriesFillPaint(true); renderer.setAutoPopulateSeriesPaint(true); renderer.setShadowXOffset(3); renderer.setMargin(0.01); renderer.setBaseItemLabelsVisible(true); ItemLabelPosition pos = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.TOP_CENTER); renderer.setBasePositiveItemLabelPosition(pos); XYToolTipGenerator plotToolTip = new StandardXYToolTipGenerator(); renderer.setBaseToolTipGenerator(plotToolTip); // color GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, java.awt.Color.GRAY, 0.0f, 0.0f, java.awt.Color.LIGHT_GRAY); renderer.setSeriesPaint(0, gp0); plot.setDomainAxis(0, valueAxis); plot.setRangeAxis(0, rangeAxis); // 3. Setup line // Create the line data, renderer, and axis XYItemRenderer lineRenderer = new XYLineAndShapeRenderer(true, false); // Lines only lineRenderer.setSeriesPaint(0, java.awt.Color.RED); lineRenderer.setSeriesStroke(0, new BasicStroke(2f)); // Set the line data, renderer, and axis into plot NumberAxis xLineAxis = new NumberAxis(EMPTY); xLineAxis.setTickMarksVisible(false); xLineAxis.setTickLabelsVisible(false); xLineAxis.setAutoRange(false); NumberAxis yLineAxis = new NumberAxis(EMPTY); yLineAxis.setTickMarksVisible(false); yLineAxis.setTickLabelsVisible(false); yLineAxis.setAutoRange(false); double maxYValue = Double.MIN_VALUE; for (int i = 0; i < dataset.getItemCount(0); i++) { maxYValue = Math.max(maxYValue, dataset.getYValue(0, i)); } XYSeriesCollection lineDatset = new XYSeriesCollection(); // Vertical Average XYSeries vertical = new XYSeries("Average"); //$NON-NLS-1$ vertical.add(minMaxVisitor.getAverageX(), 0); vertical.add(minMaxVisitor.getAverageX(), maxYValue); lineDatset.addSeries(vertical); plot.setDataset(1, lineDatset); plot.setRenderer(1, lineRenderer); plot.setDomainAxis(1, xLineAxis); plot.setRangeAxis(1, yLineAxis); // Map the line to the second Domain and second Range plot.mapDatasetToDomainAxis(1, 0); plot.mapDatasetToRangeAxis(1, 0); chartComposite.setChart(chart); chartComposite.forceRedraw(); }