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

The following examples show how to use org.jfree.chart.renderer.xy.StandardXYItemRenderer. 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: MultipleAxisChart.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void addSeries(String yaxisName, TimeSeries series) {
  NumberAxis axis2 = new NumberAxis(yaxisName);
  axis2.setAutoRangeIncludesZero(false);

  XYPlot plot = (XYPlot) chart.getPlot();
  plot.setRangeAxis(axisNum, axis2);
  plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_LEFT);

  TimeSeriesCollection dataset = new TimeSeriesCollection();
  dataset.addSeries(series);

  plot.setDataset(axisNum, dataset);
  plot.mapDatasetToRangeAxis(axisNum, axisNum);
  XYItemRenderer renderer2 = new StandardXYItemRenderer();
  plot.setRenderer(axisNum, renderer2);

  axisNum++;
}
 
Example #2
Source File: SwingCombinedChartGestureDemo.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
  // create subplot 1...
  final XYDataset data1 = createDataset();
  final XYItemRenderer renderer1 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
  final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);

  // create subplot 2...
  final XYDataset data2 = createDataset();
  final XYItemRenderer renderer2 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
  final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

  // parent plot...
  final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
  plot.setGap(10.0);

  // add the subplots...
  plot.add(subplot1, 1);
  plot.add(subplot2, 1);
  plot.setOrientation(PlotOrientation.VERTICAL);

  // return a new chart containing the overlaid plot...
  return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #3
Source File: FXCombinedChartGestureDemo.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
  // create subplot 1...
  final XYDataset data1 = createDataset();
  final XYItemRenderer renderer1 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
  final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);

  // create subplot 2...
  final XYDataset data2 = createDataset();
  final XYItemRenderer renderer2 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
  final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

  // parent plot...
  final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
  plot.setGap(10.0);

  // add the subplots...
  plot.add(subplot1, 1);
  plot.add(subplot2, 1);
  plot.setOrientation(PlotOrientation.VERTICAL);

  // return a new chart containing the overlaid plot...
  return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #4
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests cloning for a more complex plot.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));
    List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
            new Integer(1)});
    p1.mapDatasetToDomainAxes(0, axisIndices);
    p1.mapDatasetToRangeAxes(0, axisIndices);
    p1.setRenderer(1, new XYBarRenderer());
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));
}
 
Example #5
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests cloning for a plot where the fixed legend items have been
 * specified.
 */
@Test
public void testCloning3() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    LegendItemCollection c1 = new LegendItemCollection();
    p1.setFixedLegendItems(c1);
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // verify independence of fixed legend item collection
    c1.add(new LegendItem("X"));
    assertFalse(p1.equals(p2));
}
 
Example #6
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests cloning for a more complex plot.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));
    List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
            new Integer(1)});
    p1.mapDatasetToDomainAxes(0, axisIndices);
    p1.mapDatasetToRangeAxes(0, axisIndices);
    p1.setRenderer(1, new XYBarRenderer());
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));
}
 
Example #7
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests cloning for a plot where the fixed legend items have been
 * specified.
 */
@Test
public void testCloning3() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    LegendItemCollection c1 = new LegendItemCollection();
    p1.setFixedLegendItems(c1);
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // verify independence of fixed legend item collection
    c1.add(new LegendItem("X"));
    assertFalse(p1.equals(p2));
}
 
Example #8
Source File: LineChartBuilder.java    From nmonvisualizer with Apache License 2.0 6 votes vote down vote up
private void formatRenderer(int index) {
    // show filled markers at each data point
    StandardXYItemRenderer renderer = (StandardXYItemRenderer) chart.getXYPlot().getRenderer(index);

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // if no data for more than 1 granularity's time period, do not draw a connecting line
    renderer.setPlotDiscontinuous(true);
    renderer.setGapThresholdType(UnitType.ABSOLUTE);

    recalculateGapThreshold(index);

    renderer.setBaseToolTipGenerator(tooltipGenerator);

    if (!definition.showDataPoints()) {
        renderer.setAutoPopulateSeriesShape(false);
        renderer.setBaseShape(new java.awt.Rectangle(), false);
    }
}
 
Example #9
Source File: XYPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests cloning for a more complex plot.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));
    List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
            new Integer(1)});
    p1.mapDatasetToDomainAxes(0, axisIndices);
    p1.mapDatasetToRangeAxes(0, axisIndices);
    p1.setRenderer(1, new XYBarRenderer());
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));
}
 
Example #10
Source File: XYPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests cloning for a plot where the fixed legend items have been
 * specified.
 */
@Test
public void testCloning3() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    LegendItemCollection c1 = new LegendItemCollection();
    p1.setFixedLegendItems(c1);
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // verify independence of fixed legend item collection
    c1.add(new LegendItem("X"));
    assertFalse(p1.equals(p2));
}
 
Example #11
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Tests cloning for a plot where the fixed legend items have been
 * specified.
 */
@Test
public void testCloning3() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    LegendItemCollection c1 = new LegendItemCollection();
    p1.setFixedLegendItems(c1);
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // verify independence of fixed legend item collection
    c1.add(new LegendItem("X"));
    assertFalse(p1.equals(p2));
}
 
Example #12
Source File: StandardXYItemRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check to ensure that an item that falls outside the plot's data area
 * does NOT generate an item entity.
 */
public void testNoDisplayedItem() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(10.0, 10.0);
    dataset.addSeries(s1);
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StandardXYItemRenderer());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setRange(0.0, 5.0);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setRange(0.0, 5.0);
    BufferedImage image = new BufferedImage(200 , 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, info);
    g2.dispose();
    EntityCollection ec = info.getEntityCollection();
    assertFalse(TestUtilities.containsInstanceOf(ec.getEntities(),
            XYItemEntity.class));
}
 
Example #13
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Tests cloning for a more complex plot.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));
    List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
            new Integer(1)});
    p1.mapDatasetToDomainAxes(0, axisIndices);
    p1.mapDatasetToRangeAxes(0, axisIndices);
    p1.setRenderer(1, new XYBarRenderer());
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));
}
 
Example #14
Source File: SwingCombinedChartGestureDemo.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
  // create subplot 1...
  final XYDataset data1 = createDataset();
  final XYItemRenderer renderer1 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
  final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);

  // create subplot 2...
  final XYDataset data2 = createDataset();
  final XYItemRenderer renderer2 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
  final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

  // parent plot...
  final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
  plot.setGap(10.0);

  // add the subplots...
  plot.add(subplot1, 1);
  plot.add(subplot2, 1);
  plot.setOrientation(PlotOrientation.VERTICAL);

  // return a new chart containing the overlaid plot...
  return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #15
Source File: FXCombinedChartGestureDemo.java    From old-mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
      // create subplot 1...
      final XYDataset data1 = createDataset();
      final XYItemRenderer renderer1 = new StandardXYItemRenderer();
      final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
      final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
      
      // create subplot 2...
      final XYDataset data2 = createDataset();
      final XYItemRenderer renderer2 = new StandardXYItemRenderer();
      final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
      final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

      // parent plot...
      final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
      plot.setGap(10.0);
      
      // add the subplots...
      plot.add(subplot1, 1);
      plot.add(subplot2, 1);
      plot.setOrientation(PlotOrientation.VERTICAL);

      // return a new chart containing the overlaid plot...
      return new JFreeChart("CombinedDomainXYPlot Demo",
                            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #16
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests cloning for a plot where the fixed legend items have been
 * specified.
 */
@Test
public void testCloning3() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    LegendItemCollection c1 = new LegendItemCollection();
    p1.setFixedLegendItems(c1);
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // verify independence of fixed legend item collection
    c1.add(new LegendItem("X"));
    assertFalse(p1.equals(p2));
}
 
Example #17
Source File: SwingCombinedChartGestureDemo.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
  // create subplot 1...
  final XYDataset data1 = createDataset();
  final XYItemRenderer renderer1 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
  final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);

  // create subplot 2...
  final XYDataset data2 = createDataset();
  final XYItemRenderer renderer2 = new StandardXYItemRenderer();
  final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
  final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

  // parent plot...
  final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
  plot.setGap(10.0);

  // add the subplots...
  plot.add(subplot1, 1);
  plot.add(subplot2, 1);
  plot.setOrientation(PlotOrientation.VERTICAL);

  // return a new chart containing the overlaid plot...
  return new JFreeChart("CombinedDomainXYPlot Demo", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #18
Source File: FXCombinedChartGestureDemo.java    From mzmine2 with GNU General Public License v2.0 6 votes vote down vote up
private JFreeChart createCombinedChart() {
      // create subplot 1...
      final XYDataset data1 = createDataset();
      final XYItemRenderer renderer1 = new StandardXYItemRenderer();
      final NumberAxis rangeAxis1 = new NumberAxis("Range 1");
      final XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
      
      // create subplot 2...
      final XYDataset data2 = createDataset();
      final XYItemRenderer renderer2 = new StandardXYItemRenderer();
      final NumberAxis rangeAxis2 = new NumberAxis("Range 2");
      final XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);

      // parent plot...
      final CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new NumberAxis("Domain"));
      plot.setGap(10.0);
      
      // add the subplots...
      plot.add(subplot1, 1);
      plot.add(subplot2, 1);
      plot.setOrientation(PlotOrientation.VERTICAL);

      // return a new chart containing the overlaid plot...
      return new JFreeChart("CombinedDomainXYPlot Demo",
                            JFreeChart.DEFAULT_TITLE_FONT, plot, true);
}
 
Example #19
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Tests cloning for a more complex plot.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    XYPlot p1 = new XYPlot(null, new NumberAxis("Domain Axis"),
            new NumberAxis("Range Axis"), new StandardXYItemRenderer());
    p1.setRangeAxis(1, new NumberAxis("Range Axis 2"));
    List axisIndices = Arrays.asList(new Integer[] {new Integer(0),
            new Integer(1)});
    p1.mapDatasetToDomainAxes(0, axisIndices);
    p1.mapDatasetToRangeAxes(0, axisIndices);
    p1.setRenderer(1, new XYBarRenderer());
    XYPlot p2 = (XYPlot) p1.clone();
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));
}
 
Example #20
Source File: StandardXYItemRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check to ensure that an item that falls outside the plot's data area
 * does NOT generate an item entity.
 */
public void testNoDisplayedItem() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(10.0, 10.0);
    dataset.addSeries(s1);
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y", 
            dataset, PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(new StandardXYItemRenderer());
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setRange(0.0, 5.0);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setRange(0.0, 5.0);
    BufferedImage image = new BufferedImage(200 , 100, 
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    ChartRenderingInfo info = new ChartRenderingInfo();
    chart.draw(g2, new Rectangle2D.Double(0, 0, 200, 100), null, info);
    g2.dispose();
    EntityCollection ec = info.getEntityCollection();
    assertFalse(TestUtilities.containsInstanceOf(ec.getEntities(), 
            XYItemEntity.class));
}
 
Example #21
Source File: CombinedDomainXYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a sample plot.
 *
 * @return A sample plot.
 */
private CombinedDomainXYPlot createPlot() {
    // create subplot 1...
    XYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    XYTextAnnotation annotation = new XYTextAnnotation("Hello!", 50.0,
            10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    XYDataset data2 = createDataset2();
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(
            new NumberAxis("Domain"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}
 
Example #22
Source File: CombinedDomainXYPlotTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a sample plot.
 * 
 * @return A sample plot.
 */
private CombinedDomainXYPlot createPlot() {
    // create subplot 1...
    XYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    XYPlot subplot1 = new XYPlot(data1, null, rangeAxis1, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
    
    XYTextAnnotation annotation 
        = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);
    
    // create subplot 2...
    XYDataset data2 = createDataset2();
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    rangeAxis2.setAutoRangeIncludesZero(false);
    XYPlot subplot2 = new XYPlot(data2, null, rangeAxis2, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    CombinedDomainXYPlot plot 
        = new CombinedDomainXYPlot(new NumberAxis("Domain"));
    plot.setGap(10.0);
    
    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}
 
Example #23
Source File: StandardXYItemRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    StandardXYItemRenderer r = new StandardXYItemRenderer();
    XYPlot plot = new XYPlot(d1, new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example #24
Source File: StandardXYItemRendererTests.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() {
    StandardXYItemRenderer r1 = new StandardXYItemRenderer();
    StandardXYItemRenderer r2 = new StandardXYItemRenderer();
    assertTrue(r1.equals(r2));
    int h1 = r1.hashCode();
    int h2 = r2.hashCode();
    assertEquals(h1, h2);
}
 
Example #25
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Tests a bug where the plot is no longer registered as a listener
 * with the dataset(s) and axes after deserialization.  See patch 1209475
 * at SourceForge.
 */
@Test
public void testSerialization5() {
    XYSeriesCollection dataset1 = new XYSeriesCollection();
    NumberAxis domainAxis1 = new NumberAxis("Domain 1");
    NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    XYPlot p1 = new XYPlot(dataset1, domainAxis1, rangeAxis1, renderer1);
    NumberAxis domainAxis2 = new NumberAxis("Domain 2");
    NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    p1.setDataset(1, dataset2);
    p1.setDomainAxis(1, domainAxis2);
    p1.setRangeAxis(1, rangeAxis2);
    p1.setRenderer(1, renderer2);
    XYPlot p2 = (XYPlot) TestUtilities.serialised(p1);
    assertEquals(p1, p2);

    // now check that all datasets, renderers and axes are being listened
    // too...
    NumberAxis domainAxisA = (NumberAxis) p2.getDomainAxis(0);
    NumberAxis rangeAxisA = (NumberAxis) p2.getRangeAxis(0);
    XYSeriesCollection datasetA = (XYSeriesCollection) p2.getDataset(0);
    StandardXYItemRenderer rendererA
        = (StandardXYItemRenderer) p2.getRenderer(0);
    NumberAxis domainAxisB = (NumberAxis) p2.getDomainAxis(1);
    NumberAxis rangeAxisB = (NumberAxis) p2.getRangeAxis(1);
    XYSeriesCollection datasetB = (XYSeriesCollection) p2.getDataset(1);
    StandardXYItemRenderer rendererB
        = (StandardXYItemRenderer) p2.getRenderer(1);
    assertTrue(datasetA.hasListener(p2));
    assertTrue(domainAxisA.hasListener(p2));
    assertTrue(rangeAxisA.hasListener(p2));
    assertTrue(rendererA.hasListener(p2));
    assertTrue(datasetB.hasListener(p2));
    assertTrue(domainAxisB.hasListener(p2));
    assertTrue(rangeAxisB.hasListener(p2));
    assertTrue(rendererB.hasListener(p2));
}
 
Example #26
Source File: CombinedRangeXYPlotTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a sample plot.
 *
 * @return A sample plot.
 */
private CombinedRangeXYPlot createPlot() {
    // create subplot 1...
    XYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new StandardXYItemRenderer();
    NumberAxis xAxis1 = new NumberAxis("X1");
    XYPlot subplot1 = new XYPlot(data1, xAxis1, null, renderer1);
    subplot1.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);

    XYTextAnnotation annotation
            = new XYTextAnnotation("Hello!", 50.0, 10000.0);
    annotation.setFont(new Font("SansSerif", Font.PLAIN, 9));
    annotation.setRotationAngle(Math.PI / 4.0);
    subplot1.addAnnotation(annotation);

    // create subplot 2...
    XYDataset data2 = createDataset2();
    XYItemRenderer renderer2 = new StandardXYItemRenderer();
    NumberAxis xAxis2 = new NumberAxis("X2");
    xAxis2.setAutoRangeIncludesZero(false);
    XYPlot subplot2 = new XYPlot(data2, xAxis2, null, renderer2);
    subplot2.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);

    // parent plot...
    CombinedRangeXYPlot plot = new CombinedRangeXYPlot(new NumberAxis(
            "Range"));
    plot.setGap(10.0);

    // add the subplots...
    plot.add(subplot1, 1);
    plot.add(subplot2, 1);
    plot.setOrientation(PlotOrientation.VERTICAL);
    return plot;
}
 
Example #27
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization1() {
    XYDataset data = new XYSeriesCollection();
    NumberAxis domainAxis = new NumberAxis("Domain");
    NumberAxis rangeAxis = new NumberAxis("Range");
    StandardXYItemRenderer renderer = new StandardXYItemRenderer();
    XYPlot p1 = new XYPlot(data, domainAxis, rangeAxis, renderer);
    XYPlot p2 = (XYPlot) TestUtilities.serialised(p1);
    assertEquals(p1, p2);
}
 
Example #28
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization1() {
    XYDataset data = new XYSeriesCollection();
    NumberAxis domainAxis = new NumberAxis("Domain");
    NumberAxis rangeAxis = new NumberAxis("Range");
    StandardXYItemRenderer renderer = new StandardXYItemRenderer();
    XYPlot p1 = new XYPlot(data, domainAxis, rangeAxis, renderer);
    XYPlot p2 = (XYPlot) TestUtilities.serialised(p1);
    assertEquals(p1, p2);
}
 
Example #29
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Tests a bug where the plot is no longer registered as a listener
 * with the dataset(s) and axes after deserialization.  See patch 1209475
 * at SourceForge.
 */
@Test
public void testSerialization5() {
    XYSeriesCollection dataset1 = new XYSeriesCollection();
    NumberAxis domainAxis1 = new NumberAxis("Domain 1");
    NumberAxis rangeAxis1 = new NumberAxis("Range 1");
    StandardXYItemRenderer renderer1 = new StandardXYItemRenderer();
    XYPlot p1 = new XYPlot(dataset1, domainAxis1, rangeAxis1, renderer1);
    NumberAxis domainAxis2 = new NumberAxis("Domain 2");
    NumberAxis rangeAxis2 = new NumberAxis("Range 2");
    StandardXYItemRenderer renderer2 = new StandardXYItemRenderer();
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    p1.setDataset(1, dataset2);
    p1.setDomainAxis(1, domainAxis2);
    p1.setRangeAxis(1, rangeAxis2);
    p1.setRenderer(1, renderer2);
    XYPlot p2 = (XYPlot) TestUtilities.serialised(p1);
    assertEquals(p1, p2);

    // now check that all datasets, renderers and axes are being listened
    // too...
    NumberAxis domainAxisA = (NumberAxis) p2.getDomainAxis(0);
    NumberAxis rangeAxisA = (NumberAxis) p2.getRangeAxis(0);
    XYSeriesCollection datasetA = (XYSeriesCollection) p2.getDataset(0);
    StandardXYItemRenderer rendererA
        = (StandardXYItemRenderer) p2.getRenderer(0);
    NumberAxis domainAxisB = (NumberAxis) p2.getDomainAxis(1);
    NumberAxis rangeAxisB = (NumberAxis) p2.getRangeAxis(1);
    XYSeriesCollection datasetB = (XYSeriesCollection) p2.getDataset(1);
    StandardXYItemRenderer rendererB
        = (StandardXYItemRenderer) p2.getRenderer(1);
    assertTrue(datasetA.hasListener(p2));
    assertTrue(domainAxisA.hasListener(p2));
    assertTrue(rangeAxisA.hasListener(p2));
    assertTrue(rendererA.hasListener(p2));
    assertTrue(datasetB.hasListener(p2));
    assertTrue(domainAxisB.hasListener(p2));
    assertTrue(rangeAxisB.hasListener(p2));
    assertTrue(rendererB.hasListener(p2));
}
 
Example #30
Source File: AbstractXYItemRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Some checks for the findDomainBounds() method.
 */
public void testFindDomainBounds() {
    AbstractXYItemRenderer renderer = new StandardXYItemRenderer();

    // check the bounds of a simple dataset
    XYDataset dataset = createDataset1();
    Range r = renderer.findDomainBounds(dataset);
    assertEquals(1.0, r.getLowerBound(), EPSILON);
    assertEquals(3.0, r.getUpperBound(), EPSILON);

    // check that a null dataset returns null bounds
    assertTrue(renderer.findDomainBounds(null) == null);
}