List of usage examples for org.jfree.data.statistics HistogramDataset getYValue
@Override public double getYValue(int series, int item)
From source file:org.jfree.data.statistics.HistogramDatasetTest.java
/** * Some checks that the correct values are assigned to bins. *//*from w ww .j a va 2 s .co m*/ @Test public void testBins() { double[] values = { 1.0, 2.0, 3.0, 4.0, 6.0, 12.0, 5.0, 6.3, 4.5 }; HistogramDataset hd = new HistogramDataset(); hd.addSeries("Series 1", values, 5); assertEquals(hd.getYValue(0, 0), 3.0, EPSILON); assertEquals(hd.getYValue(0, 1), 3.0, EPSILON); assertEquals(hd.getYValue(0, 2), 2.0, EPSILON); assertEquals(hd.getYValue(0, 3), 0.0, EPSILON); assertEquals(hd.getYValue(0, 4), 1.0, EPSILON); }
From source file:org.jfree.data.statistics.HistogramDatasetTest.java
/** * This test is derived from a reported bug. *//* w w w . jav a 2s . c o m*/ @Test public void testBinBoundaries() { double[] values = { -5.000000000000286E-5 }; int bins = 1260; double minimum = -0.06307522528160199; double maximum = 0.06297522528160199; HistogramDataset d = new HistogramDataset(); d.addSeries("S1", values, bins, minimum, maximum); assertEquals(0.0, d.getYValue(0, 629), EPSILON); assertEquals(1.0, d.getYValue(0, 630), EPSILON); assertEquals(0.0, d.getYValue(0, 631), EPSILON); assertTrue(values[0] > d.getStartXValue(0, 630)); assertTrue(values[0] < d.getEndXValue(0, 630)); }
From source file:org.jfree.data.statistics.HistogramDatasetTest.java
/** * Some checks for the addSeries() method. *//*from w w w . j a v a2s . c o m*/ @Test public void testAddSeries() { double[] values = { -1.0, 0.0, 0.1, 0.9, 1.0, 1.1, 1.9, 2.0, 3.0 }; HistogramDataset d = new HistogramDataset(); d.addSeries("S1", values, 2, 0.0, 2.0); assertEquals(0.0, d.getStartXValue(0, 0), EPSILON); assertEquals(1.0, d.getEndXValue(0, 0), EPSILON); assertEquals(4.0, d.getYValue(0, 0), EPSILON); assertEquals(1.0, d.getStartXValue(0, 1), EPSILON); assertEquals(2.0, d.getEndXValue(0, 1), EPSILON); assertEquals(5.0, d.getYValue(0, 1), EPSILON); }
From source file:org.jfree.data.statistics.HistogramDatasetTest.java
/** * Another check for the addSeries() method. */// ww w . j a va 2s . c o 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:org.jfree.data.statistics.HistogramDatasetTest.java
/** * Some checks for bug 1553088. An IndexOutOfBoundsException is thrown * when a data value is *very* close to the upper limit of the last bin. *//*from w ww . j av a 2 s .c o m*/ @Test public void test1553088() { double[] values = { -1.0, 0.0, -Double.MIN_VALUE, 3.0 }; HistogramDataset d = new HistogramDataset(); d.addSeries("S1", values, 2, -1.0, 0.0); assertEquals(-1.0, d.getStartXValue(0, 0), EPSILON); assertEquals(-0.5, d.getEndXValue(0, 0), EPSILON); assertEquals(1.0, d.getYValue(0, 0), EPSILON); assertEquals(-0.5, d.getStartXValue(0, 1), EPSILON); assertEquals(0.0, d.getEndXValue(0, 1), EPSILON); assertEquals(3.0, d.getYValue(0, 1), EPSILON); }
From source file:biz.ixnay.pivot.charts.skin.jfree.HistogramViewSkin.java
public Element getElementAt(int x, int y) { ChartView.Element element = null; ChartEntity chartEntity = getChartEntityAt(x, y); if (chartEntity instanceof XYItemEntity) { XYItemEntity xyItemEntity = (XYItemEntity) chartEntity; HistogramDataset dataSet = (HistogramDataset) ((XYItemEntity) chartEntity).getDataset(); int series = xyItemEntity.getSeriesIndex(); int item = xyItemEntity.getItem(); double binStart = dataSet.getStartXValue(series, item); double binEnd = dataSet.getEndXValue(series, item); double binValue = dataSet.getXValue(series, item); double frequency = dataSet.getYValue(series, item); element = new HistogramView.HistogramBin(series, item, binStart, binValue, binEnd, frequency); }//from w w w .j a v a 2 s .c o m return element; }
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);/* w w w . j a v a 2 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(); }