org.jfree.chart.renderer.xy.StackedXYAreaRenderer2 Java Examples

The following examples show how to use org.jfree.chart.renderer.xy.StackedXYAreaRenderer2. 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: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Test chart drawing with an empty dataset to ensure that this special
 * case doesn't cause any exceptions.
 */
public void testDrawWithEmptyDataset() {
    boolean success = false;
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("title", "x",
            "y", new DefaultTableXYDataset(), true);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYAreaRenderer2());
    try {
        BufferedImage image = new BufferedImage(200 , 100,
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example #2
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));

    // try null argument
    assertNull(renderer.findRangeBounds(null));

    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
 
Example #3
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a stacked XY area plot.  The chart object returned by this
 * method uses an {@link XYPlot} instance as the plot, with a
 * {@link NumberAxis} for the domain axis, a {@link NumberAxis} as the
 * range axis, and a {@link StackedXYAreaRenderer2} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param xAxisLabel  a label for the X-axis (<code>null</code> permitted).
 * @param yAxisLabel  a label for the Y-axis (<code>null</code> permitted).
 * @param dataset  the dataset for the chart (<code>null</code> permitted).
 * @param legend  a flag specifying whether or not a legend is required.

 *
 * @return A stacked XY area chart.
 */
public static JFreeChart createStackedXYAreaChart(String title,
        String xAxisLabel, String yAxisLabel, TableXYDataset dataset,
        boolean legend) {

    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setLowerMargin(0.0);
    xAxis.setUpperMargin(0.0);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setOutline(true);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setRangeAxis(yAxis);  // forces recalculation of the axis range
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #4
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
public void testFindRangeBounds() {
    TableXYDataset dataset 
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL, 
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    StackedXYAreaRenderer2 renderer = new StackedXYAreaRenderer2();
    plot.setRenderer(renderer);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));
    
    // try null argument
    assertNull(renderer.findRangeBounds(null));
    
    // try empty dataset
    assertNull(renderer.findRangeBounds(new DefaultTableXYDataset()));
}
 
Example #5
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2();
    StackedXYAreaRenderer2 r2 = new StackedXYAreaRenderer2();
    assertEquals(r1, r2);
    assertEquals(r2, r1);

    r1.setRoundXCoordinates(!r1.getRoundXCoordinates());
    assertFalse(r1.equals(r2));
    r2.setRoundXCoordinates(r1.getRoundXCoordinates());
    assertTrue(r1.equals(r2));
}
 
Example #6
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode.
 */
public void testHashcode() {
    StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2();
    StackedXYAreaRenderer2 r2 = new StackedXYAreaRenderer2();
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);
}
 
Example #7
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test chart drawing with an empty dataset to ensure that this special
 * case doesn't cause any exceptions.
 */
public void testDrawWithEmptyDataset() {
    boolean success = false;
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("title", "x",
            "y", new DefaultTableXYDataset(), PlotOrientation.VERTICAL,
            true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYAreaRenderer2());
    try {
        BufferedImage image = new BufferedImage(200 , 100, 
                BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = image.createGraphics();
        chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, null);
        g2.dispose();
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example #8
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Test that the equals() method distinguishes all fields.
 */
public void testEquals() {
    StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2();
    StackedXYAreaRenderer2 r2 = new StackedXYAreaRenderer2();
    assertEquals(r1, r2);
    assertEquals(r2, r1);
    
    r1.setRoundXCoordinates(!r1.getRoundXCoordinates());
    assertFalse(r1.equals(r2));
    r2.setRoundXCoordinates(r1.getRoundXCoordinates());
    assertTrue(r1.equals(r2));
}
 
Example #9
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Two objects that are equal are required to return the same hashCode. 
 */
public void testHashcode() {
    StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2();
    StackedXYAreaRenderer2 r2 = new StackedXYAreaRenderer2();
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);
}
 
Example #10
Source File: LineChartBuilder.java    From nmonvisualizer with Apache License 2.0 5 votes vote down vote up
protected void formatChart() {
    super.formatChart();

    XYPlot plot = chart.getXYPlot();

    plot.getDomainAxis().setLabel(definition.getXAxisLabel());
    plot.getRangeAxis().setLabel(definition.getYAxisLabel());

    if (definition.usePercentYAxis()) {
        LineChartBuilder.setPercentYAxis(chart);
    }

    if (definition.isStacked()) {
        StackedXYAreaRenderer2 renderer = (StackedXYAreaRenderer2) plot.getRenderer();
        renderer.setLegendArea(new java.awt.Rectangle(10, 10));

        renderer.setBaseToolTipGenerator(tooltipGenerator);

        if (!definition.showDataPoints()) {
            renderer.setAutoPopulateSeriesShape(false);
            renderer.setBaseShape(new java.awt.Rectangle(), false);
        }
    }
    else {
        formatRenderer(0);
    }

    if (definition.hasSecondaryYAxis()) {
        plot.getRangeAxis(1).setLabel(definition.getSecondaryYAxisLabel());
        formatRenderer(1);
    }
}
 
Example #11
Source File: StackedXYAreaRenderer2Tests.java    From astor with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Verify that this class implements {@link PublicCloneable}.
 */
public void testPublicCloneable() {
    StackedXYAreaRenderer2 r1 = new StackedXYAreaRenderer2();
    assertTrue(r1 instanceof PublicCloneable);
}