Java Code Examples for org.jfree.data.statistics.HistogramDataset#addSeries()

The following examples show how to use org.jfree.data.statistics.HistogramDataset#addSeries() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HistogramChartFactory.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 2
Source File: HistogramChartFactory.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
public static JFreeChart createHistogramOld(double[] data, int bin, String yAxisLabel, double min,
    double max) {
  if (data != null && data.length > 0) {
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("histo", data, bin, min, max);

    JFreeChart chart = ChartFactory.createHistogram("", yAxisLabel, "n", dataset,
        PlotOrientation.VERTICAL, true, false, false);

    chart.setBackgroundPaint(new Color(230, 230, 230));
    chart.getLegend().setVisible(false);
    XYPlot xyplot = chart.getXYPlot();
    xyplot.setForegroundAlpha(0.7F);
    xyplot.setBackgroundPaint(Color.WHITE);
    xyplot.setDomainGridlinePaint(new Color(150, 150, 150));
    xyplot.setRangeGridlinePaint(new Color(150, 150, 150));
    xyplot.getDomainAxis().setVisible(true);
    xyplot.getRangeAxis().setVisible(yAxisLabel != null);
    XYBarRenderer xybarrenderer = (XYBarRenderer) xyplot.getRenderer();
    xybarrenderer.setShadowVisible(false);
    xybarrenderer.setBarPainter(new StandardXYBarPainter());
    // xybarrenderer.setDrawBarOutline(false);
    return chart;
  } else
    return null;
}
 
Example 3
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Another check for the addSeries() method.
 */
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);
}
 
Example 4
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    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 = new HistogramDataset();
    d2.addSeries("Series 1", values, 5);

    assertTrue(d1.equals(d2));
    assertTrue(d2.equals(d1));

    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));
}
 
Example 5
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the addSeries() method.
 */
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);
}
 
Example 6
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for a bug reported in the forum where the series name isn't being
 * returned correctly.
 */
public void testGetSeriesKey() {
    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);   
    assertEquals("Series 1", d1.getSeriesKey(0));
}
 
Example 7
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Confirm that the equals method can distinguish all the required fields.
 */
public void testEquals() {
    
    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 = new HistogramDataset();
    d2.addSeries("Series 1", values, 5);
    
    assertTrue(d1.equals(d2));
    assertTrue(d2.equals(d1));

}
 
Example 8
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks that the correct values are assigned to bins.
 */
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);        
}
 
Example 9
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for bug 1553088.  An IndexOutOfBoundsException is thrown
 * when a data value is *very* close to the upper limit of the last bin.
 */
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);
}
 
Example 10
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This test is derived from a reported bug.
 */
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));
}
 
Example 11
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the addSeries() method.
 */
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);
}
 
Example 12
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A test for a bug reported in the forum where the series name isn't being
 * returned correctly.
 */
public void testGetSeriesKey() {
    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);
    assertEquals("Series 1", d1.getSeriesKey(0));
}
 
Example 13
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks that the correct values are assigned to bins.
 */
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);
}
 
Example 14
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for bug 1553088.  An IndexOutOfBoundsException is thrown 
 * when a data value is *very* close to the upper limit of the last bin.
 */
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);
}
 
Example 15
Source File: NumericalAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a {@link HistogramDataset} for this {@link Attribute}.
 *
 * @param exampleSet
 * @return
 */
private HistogramDataset createHistogramDataset(ExampleSet exampleSet) {
	HistogramDataset dataset = new HistogramDataset();

	double[] array = new double[exampleSet.size()];
	int count = 0;

	for (Example example : exampleSet) {
		double value = example.getDataRow().get(getAttribute());
		// don't use missing values because otherwise JFreeChart tries to plot them too which
		// can lead to false histograms
		if (!Double.isNaN(value)) {
			array[count++] = value;
		}
	}

	// add points to data set (if any)
	if (count > 0) {
		// truncate array if necessary
		if (count < array.length) {
			array = Arrays.copyOf(array, count);
		}
		dataset.addSeries(getAttribute().getName(), array, Math.min(array.length, MAX_BINS_HISTOGRAM));
	}

	return dataset;
}
 
Example 16
Source File: DateTimeAttributeStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a {@link HistogramDataset} for this {@link Attribute}.
 *
 * @param exampleSet
 * @return
 */
private HistogramDataset createHistogramDataset(final ExampleSet exampleSet) {
	HistogramDataset dataset = new HistogramDataset();

	double[] array = new double[exampleSet.size()];
	int count = 0;

	for (Example example : exampleSet) {
		double value = example.getDataRow().get(getAttribute());
		// don't use missing values because otherwise JFreeChart tries to plot them too which
		// can lead to false histograms
		if (!Double.isNaN(value)) {
			array[count++] = value;
		}
	}

	// add points to data set (if any)
	if (count > 0) {
		// truncate array if necessary
		if (count < array.length) {
			array = Arrays.copyOf(array, count);
		}
		dataset.addSeries(getAttribute().getName(), array, Math.min(array.length, MAX_BINS_HISTOGRAM));
	}

	return dataset;
}
 
Example 17
Source File: BeltTimeColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a {@link HistogramDataset} for this column.
 */
private HistogramDataset createHistogramDataset(final Table table) {
	HistogramDataset dataset = new HistogramDataset();

	double[] array = new double[table.height()];
	int count = 0;

	ObjectReader<LocalTime> reader = Readers.objectReader(table.column(getColumnName()),
			LocalTime.class);
	while (reader.hasRemaining()) {
		LocalTime localTime = reader.read();
		// don't use missing values because otherwise JFreeChart tries to plot them too which
		// can lead to false histograms
		if (localTime != null) {
				//charts can plot only as milliseconds since epoch, so convert
			Instant instant = localTime.atDate(EPOCH).atZone(Tools.getPreferredTimeZone().toZoneId()).toInstant();
			array[count++] = instant.getEpochSecond() * SECONDS_TO_MILLIS + instant.getNano() / MILLIS_TO_NANOS;
		}
	}

	// add points to data set (if any)
	if (count > 0) {
		// truncate array if necessary
		if (count < array.length) {
			array = Arrays.copyOf(array, count);
		}
		dataset.addSeries(getColumnName(), array, Math.min(array.length, MAX_BINS_HISTOGRAM));
	}

	return dataset;
}
 
Example 18
Source File: HistogramDatasetTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * This test is derived from a reported bug.
 */
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));        
}
 
Example 19
Source File: BeltDateTimeColumnStatisticsModel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a {@link HistogramDataset} for this {@link com.rapidminer.belt.column.Column}.
 */
private HistogramDataset createHistogramDataset(final Table table) {
	HistogramDataset dataset = new HistogramDataset();

	double[] array = new double[table.height()];
	int count = 0;

	ObjectReader<Instant> reader = Readers.objectReader(table.column(getColumnName()),
			Instant.class);
	while(reader.hasRemaining()){
		Instant instant = reader.read();
		// don't use missing values because otherwise JFreeChart tries to plot them too which
		// can lead to false histograms
		if (instant !=null) {
			array[count++] = instant.getEpochSecond() * SECONDS_TO_MILLIS + instant.getNano() / MILLIS_TO_NANOS;
		}
	}

	// add points to data set (if any)
	if (count > 0) {
		// truncate array if necessary
		if (count < array.length) {
			array = Arrays.copyOf(array, count);
		}
		dataset.addSeries(getColumnName(), array, Math.min(array.length, MAX_BINS_HISTOGRAM));
	}

	return dataset;
}
 
Example 20
Source File: AdvancedLtmStatsPanel.java    From opencards with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void rebuildPanel(Collection<CardFile> currentFiles) {
        removeAll();

        // setup the stacked bar chart
        dataset = new HistogramDataset();
//        dataset.addSeries("test", new double[]{1,2,3},1);
        final JFreeChart chart = ChartFactory.createHistogram(
                null,  // chart title
                Utils.getRB().getString("CardTableModel.stats.weekSchedule"),                  // domain axis label
//                "# cards",                     // range axis label
                null,                     // range axis label
                dataset,                     // data
                PlotOrientation.VERTICAL,    // the plot orientation
                false,                        // legend
                true,                        // tooltips
                false                        // urls
        );

        add(new ChartPanel(chart), BorderLayout.CENTER);
//        rebuildPanel(new HashSet<CardFile>());

        if (currentFiles != null)
            this.currentFiles = currentFiles;

//        dataset.setGroup(null);

        if (this.currentFiles == null)
            return;

        List<Double> eValues = new ArrayList<Double>();

        for (CardFile currentFile : currentFiles) {
            for (Item item : currentFile.getFlashCards().getLTMItems()) {
                LTMItem ltmItem = (LTMItem) item;
                eValues.add(ltmItem.getEFactor());
            }
        }
        double[] eVals = new double[eValues.size()];
        for (int i = 0; i < eValues.size(); i++) {
            eVals[i] = eValues.get(i);

        }


        if (eVals.length > 0)
            dataset.addSeries("test", eVals, 10);

        HistogramDataset dataset1 = new HistogramDataset();
        dataset1.addSeries("test", eVals, 10);

        repaint();

//        computeScheduleHist(this.currentFiles);
//        set2EDistribution(currentFiles);
    }