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

The following examples show how to use org.jfree.chart.renderer.xy.StackedXYBarRenderer. 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: StackedXYBarRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart("Test Chart",
            "X", "Y", dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example #2
Source File: StackedXYBarRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
public void testFindDomainBounds() {
    TableXYDataset dataset 
            = RendererXYPackageTests.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createStackedXYAreaChart(
            "Test Chart", "X", "Y", dataset, 
            PlotOrientation.VERTICAL, false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.3));
    assertTrue(bounds.contains(0.5));
    assertTrue(bounds.contains(2.5));
    assertFalse(bounds.contains(2.8));
}
 
Example #3
Source File: StackedXYBarRendererTests.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() {
    StackedXYBarRenderer r1 = new StackedXYBarRenderer();
    StackedXYBarRenderer r2 = new StackedXYBarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));

    r1.setRenderAsPercentages(true);
    assertFalse(r1.equals(r2));
    r2.setRenderAsPercentages(true);
    assertTrue(r1.equals(r2));
}
 
Example #4
Source File: StackedXYBarRendererTests.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() {
    StackedXYBarRenderer r1 = new StackedXYBarRenderer();
    StackedXYBarRenderer r2 = new StackedXYBarRenderer();
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);

    r1.setRenderAsPercentages(true);
    h1 = r1.hashCode();
    h2 = r2.hashCode();
    assertFalse(h1 == h2);
}
 
Example #5
Source File: StackedXYBarRendererTests.java    From astor with GNU General Public License v2.0 5 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();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));
}
 
Example #6
Source File: StackedXYBarRendererTests.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() {
    StackedXYBarRenderer r1 = new StackedXYBarRenderer();
    StackedXYBarRenderer r2 = new StackedXYBarRenderer();
    assertTrue(r1.equals(r2));
    assertTrue(r2.equals(r1));
    
    r1.setRenderAsPercentages(true);
    assertFalse(r1.equals(r2));
    r2.setRenderAsPercentages(true);
    assertTrue(r1.equals(r2));
}
 
Example #7
Source File: StackedXYBarRendererTests.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() {
    StackedXYBarRenderer r1 = new StackedXYBarRenderer();
    StackedXYBarRenderer r2 = new StackedXYBarRenderer();
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);
    
    r1.setRenderAsPercentages(true);
    h1 = r1.hashCode();
    h2 = r2.hashCode();
    assertFalse(h1 == h2);
}
 
Example #8
Source File: StackedXYBarRendererTests.java    From astor with GNU General Public License v2.0 5 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();
    plot.setRenderer(new StackedXYBarRenderer());
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    Range bounds = rangeAxis.getRange();
    assertTrue(bounds.contains(6.0));
    assertTrue(bounds.contains(8.0));
}
 
Example #9
Source File: StackedXYBarRendererTests.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() {
    StackedXYBarRenderer r1 = new StackedXYBarRenderer();
    assertTrue(r1 instanceof PublicCloneable);
}
 
Example #10
Source File: XYBarChartExpression.java    From pentaho-reporting with GNU Lesser General Public License v2.1 4 votes vote down vote up
protected void configureChart( final JFreeChart chart ) {
  super.configureChart( chart );

  final XYPlot xypl = chart.getXYPlot();
  final XYItemRenderer renderer = xypl.getRenderer();
  final XYBarRenderer br = (XYBarRenderer) renderer;
  br.setDrawBarOutline( isChartSectionOutline() );
  if ( margin != null ) {
    br.setMargin( margin.doubleValue() );
  }

  br.setShadowVisible( shadowVisible );
  br.setShadowXOffset( shadowXOffset );
  br.setShadowYOffset( shadowYOffset );

  if ( ( isStacked() ) && renderPercentages && ( br instanceof StackedXYBarRenderer ) ) {
    final StackedXYBarRenderer sbr = (StackedXYBarRenderer) br;
    sbr.setRenderAsPercentages( true );

    final ValueAxis rangeAxis = xypl.getRangeAxis();
    final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
    if ( ClassicEngineBoot.isEnforceCompatibilityFor( level, 3, 8 ) ) {
      if ( getRangeMinimum() != 0 ) {
        rangeAxis.setLowerBound( getRangeMinimum() );
      }
      if ( getRangeMaximum() != 1 ) {
        rangeAxis.setUpperBound( getRangeMaximum() );
      }
      if ( getRangeMinimum() == 0 && getRangeMaximum() == 0 ) {
        rangeAxis.setLowerBound( 0 );
        rangeAxis.setUpperBound( 1 );
        rangeAxis.setAutoRange( true );
      }
    } else {
      rangeAxis.setLowerBound( getRangeMinimum() );
      rangeAxis.setUpperBound( getRangeMaximum() );
      rangeAxis.setAutoRange( isRangeAxisAutoRange() );
    }
  }

}