org.jfree.chart.axis.NumberAxis Java Examples

The following examples show how to use org.jfree.chart.axis.NumberAxis. 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: ChartFactory.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings.
 *
 * @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 orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return The chart.
 */
public static JFreeChart createXYLineChart(String title, String xAxisLabel,
        String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
        boolean legend, boolean tooltips, boolean urls) {

    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #2
Source File: AbstractRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Some checks for the paint lookup mechanism.
 */
@Test
public void testPaintLookup() {
    BarRenderer r = new BarRenderer();
    assertEquals(Color.blue, r.getBasePaint());

    // first check that autoPopulate==false works as expected
    r.setAutoPopulateSeriesPaint(false);
    assertEquals(Color.blue, r.lookupSeriesPaint(0));
    assertNull(r.getSeriesPaint(0));

    // now check autoPopulate==true
    r.setAutoPopulateSeriesPaint(true);
    /*CategoryPlot plot =*/ new CategoryPlot(null, new CategoryAxis(
            "Category"), new NumberAxis("Value"), r);
    assertEquals(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[0],
            r.lookupSeriesPaint(0));
    assertNotNull(r.getSeriesPaint(0));
}
 
Example #3
Source File: AbstractChartsPanel.java    From computational-economy with GNU General Public License v3.0 6 votes vote down vote up
protected void configureChart(final JFreeChart chart) {
	chart.setBackgroundPaint(Color.white);
	final XYPlot plot = (XYPlot) chart.getPlot();
	plot.setBackgroundPaint(Color.lightGray);
	plot.setDomainGridlinePaint(Color.white);
	plot.setRangeGridlinePaint(Color.white);
	plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

	final DateAxis dateAxis = (DateAxis) plot.getDomainAxis();
	final NumberAxis valueAxis = (NumberAxis) plot.getRangeAxis();

	dateAxis.setDateFormatOverride(new SimpleDateFormat("dd-MMM"));
	valueAxis.setAutoRangeIncludesZero(true);
	valueAxis.setUpperMargin(0.15);
	valueAxis.setLowerMargin(0.15);
}
 
Example #4
Source File: ChartFactory.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a wind plot with default settings.
 *
 * @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 that controls whether or not a legend is created.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return A wind plot.
 *
 */
public static JFreeChart createWindPlot(String title, String xAxisLabel,
        String yAxisLabel, WindDataset dataset, boolean legend,
        boolean tooltips, boolean urls) {

    ValueAxis xAxis = new DateAxis(xAxisLabel);
    ValueAxis yAxis = new NumberAxis(yAxisLabel);
    yAxis.setRange(-12.0, 12.0);

    WindItemRenderer renderer = new WindItemRenderer();
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #5
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a polar plot for the specified dataset (x-values interpreted as 
 * angles in degrees).  The chart object returned by this method uses a 
 * {@link PolarPlot} instance as the plot, with a {@link NumberAxis} for 
 * the radial axis.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param legend  legend required?
 * @param tooltips  tooltips required?
 * @param urls  URLs required?
 *
 * @return A chart.
 */
public static JFreeChart createPolarChart(String title,
                                          XYDataset dataset,
                                          boolean legend,
                                          boolean tooltips,
                                          boolean urls) {

    PolarPlot plot = new PolarPlot();
    plot.setDataset(dataset);
    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAxisLineVisible(false);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setAxis(rangeAxis);
    plot.setRenderer(new DefaultPolarItemRenderer());
    JFreeChart chart = new JFreeChart(
            title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    return chart;

}
 
Example #6
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 #7
Source File: ThermometerPlot.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new thermometer plot, using default attributes where necessary.
 *
 * @param dataset  the data set.
 */
public ThermometerPlot(ValueDataset dataset) {

    super();

    this.padding = new RectangleInsets(UnitType.RELATIVE, 0.05, 0.05, 0.05,
            0.05);
    this.dataset = dataset;
    if (dataset != null) {
        dataset.addChangeListener(this);
    }
    NumberAxis axis = new NumberAxis(null);
    axis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    axis.setAxisLineVisible(false);
    axis.setPlot(this);
    axis.addChangeListener(this);
    this.rangeAxis = axis;
    setAxisRange();
}
 
Example #8
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
@Test 
public void testRendererIndices() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    
    assertEquals(renderer, plot.getRenderer(0));
    
    // we should be able to give a renderer an arbitrary index
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    plot.setRenderer(20, renderer2);
    assertEquals(2, plot.getRendererCount());
    assertEquals(renderer2, plot.getRenderer(20));
    
    assertEquals(20, plot.getIndexOf(renderer2));
}
 
Example #9
Source File: XYPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testAxisIndices() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    assertEquals(xAxis, plot.getDomainAxis(0));        
    assertEquals(yAxis, plot.getRangeAxis(0)); 
    
    NumberAxis xAxis2 = new NumberAxis("X2");
    plot.setDomainAxis(99, xAxis2);
    assertEquals(xAxis2, plot.getDomainAxis(99));
    
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(99, yAxis2);
    assertEquals(yAxis2, plot.getRangeAxis(99));
}
 
Example #10
Source File: ChartFactory.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a polar plot for the specified dataset (x-values interpreted as
 * angles in degrees).  The chart object returned by this method uses a
 * {@link PolarPlot} instance as the plot, with a {@link NumberAxis} for
 * the radial axis.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param dataset  the dataset (<code>null</code> permitted).
 * @param legend  legend required?
 * @param tooltips  tooltips required?
 * @param urls  URLs required?
 *
 * @return A chart.
 */
public static JFreeChart createPolarChart(String title, XYDataset dataset,
        boolean legend, boolean tooltips, boolean urls) {

    PolarPlot plot = new PolarPlot();
    plot.setDataset(dataset);
    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAxisLineVisible(false);
    rangeAxis.setTickMarksVisible(false);
    rangeAxis.setTickLabelInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
    plot.setAxis(rangeAxis);
    plot.setRenderer(new DefaultPolarItemRenderer());
    JFreeChart chart = new JFreeChart(
            title, JFreeChart.DEFAULT_TITLE_FONT, plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #11
Source File: CombinedRangeCategoryPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Check that only one chart change event is generated by a change to a
 * subplot.
 */
public void testNotification() {
    CombinedRangeCategoryPlot plot = createPlot();
    JFreeChart chart = new JFreeChart(plot);
    chart.addChangeListener(this);
    CategoryPlot subplot1 = (CategoryPlot) plot.getSubplots().get(0);
    NumberAxis yAxis = (NumberAxis) subplot1.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(!yAxis.getAutoRangeIncludesZero());
    assertEquals(1, this.events.size());

    // a redraw should NOT trigger another change event
    BufferedImage image = new BufferedImage(200, 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    this.events.clear();
    chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0));
    assertTrue(this.events.isEmpty());
}
 
Example #12
Source File: ChartFactory.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a line chart (based on an {@link XYDataset}) with default
 * settings.
 *
 * @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 orientation  the plot orientation (horizontal or vertical)
 *                     (<code>null</code> NOT permitted).
 * @param legend  a flag specifying whether or not a legend is required.
 * @param tooltips  configure chart to generate tool tips?
 * @param urls  configure chart to generate URLs?
 *
 * @return The chart.
 */
public static JFreeChart createXYLineChart(String title, String xAxisLabel,
        String yAxisLabel, XYDataset dataset, PlotOrientation orientation,
        boolean legend, boolean tooltips, boolean urls) {

    ParamChecks.nullNotPermitted(orientation, "orientation");
    NumberAxis xAxis = new NumberAxis(xAxisLabel);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisLabel);
    XYItemRenderer renderer = new XYLineAndShapeRenderer(true, false);
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(orientation);
    if (tooltips) {
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    }
    if (urls) {
        renderer.setURLGenerator(new StandardXYURLGenerator());
    }

    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #13
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 #14
Source File: CategoryPlotTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the getDomainAxisIndex() method.
 */
public void testGetDomainAxisIndex() {
    CategoryAxis domainAxis1 = new CategoryAxis("X1");
    CategoryAxis domainAxis2 = new CategoryAxis("X2");
    NumberAxis rangeAxis1 = new NumberAxis("Y1");
    CategoryPlot plot = new CategoryPlot(null, domainAxis1, rangeAxis1,
            null);
    assertEquals(0, plot.getDomainAxisIndex(domainAxis1));
    assertEquals(-1, plot.getDomainAxisIndex(domainAxis2));
    plot.setDomainAxis(1, domainAxis2);
    assertEquals(1, plot.getDomainAxisIndex(domainAxis2));
    assertEquals(-1, plot.getDomainAxisIndex(new CategoryAxis("X2")));
    boolean pass = false;
    try {
        plot.getDomainAxisIndex(null);
    }
    catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}
 
Example #15
Source File: AbstractRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the outline paint lookup mechanism.
 */
public void testOutlinePaintLookup() {
    BarRenderer r = new BarRenderer();
    assertEquals(Color.gray, r.getBaseOutlinePaint());

    // first check that autoPopulate==false works as expected
    r.setAutoPopulateSeriesOutlinePaint(false);
    assertEquals(Color.gray, r.lookupSeriesOutlinePaint(0));
    assertNull(r.getSeriesOutlinePaint(0));

    // now check autoPopulate==true
    r.setAutoPopulateSeriesOutlinePaint(true);
    /*CategoryPlot plot =*/ new CategoryPlot(null, new CategoryAxis(
            "Category"), new NumberAxis("Value"), r);
    assertEquals(DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE[0],
            r.lookupSeriesOutlinePaint(0));
    assertNotNull(r.getSeriesOutlinePaint(0));
}
 
Example #16
Source File: CombinedRangeXYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that only one chart change event is generated by a change to a
 * subplot.
 */
@Test
public void testNotification() {
    CombinedRangeXYPlot plot = createPlot();
    JFreeChart chart = new JFreeChart(plot);
    chart.addChangeListener(this);
    XYPlot subplot1 = (XYPlot) plot.getSubplots().get(0);
    NumberAxis xAxis = (NumberAxis) subplot1.getDomainAxis();
    xAxis.setAutoRangeIncludesZero(!xAxis.getAutoRangeIncludesZero());
    assertEquals(1, this.events.size());

    // a redraw should NOT trigger another change event
    BufferedImage image = new BufferedImage(200, 100,
            BufferedImage.TYPE_INT_RGB);
    Graphics2D g2 = image.createGraphics();
    this.events.clear();
    chart.draw(g2, new Rectangle2D.Double(0.0, 0.0, 200.0, 100.0));
    assertTrue(this.events.isEmpty());
}
 
Example #17
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void testRangeMarkerIndices() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second axis
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(new XYSeries("Series in dataset 2"));
    plot.setDataset(99, dataset);    
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(1, yAxis2);
    XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToRangeAxis(99, 1);
    
    ValueMarker yMarker1 = new ValueMarker(123);
    plot.addRangeMarker(99, yMarker1, Layer.FOREGROUND);
    assertTrue(plot.getRangeMarkers(99, Layer.FOREGROUND).contains(yMarker1));
}
 
Example #18
Source File: BoxAndWhiskerRendererTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a chart where the dataset contains a null min outlier value.
 */
@Test
public void testDrawWithNullMinOutlier() {
    boolean success;
    try {
        DefaultBoxAndWhiskerCategoryDataset dataset
                = new DefaultBoxAndWhiskerCategoryDataset();
        dataset.add(new BoxAndWhiskerItem(new Double(1.0), new Double(2.0),
                new Double(3.0), new Double(4.0), new Double(0.5),
                new Double(4.5), null, new Double(5.5),
                null), "S1", "C1");
        CategoryPlot plot = new CategoryPlot(dataset,
                new CategoryAxis("Category"), new NumberAxis("Value"),
                new BoxAndWhiskerRenderer());
        ChartRenderingInfo info = new ChartRenderingInfo();
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200,
                info);
        success = true;
    }
    catch (Exception e) {
        success = false;
    }
    assertTrue(success);
}
 
Example #19
Source File: LevelRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Draws the chart with a <code>null</code> info object to make sure that 
 * no exceptions are thrown (particularly by code in the renderer).
 */
public void testDrawWithNullInfo() {
    boolean success = false;
    try {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "S1", "C1");
        CategoryPlot plot = new CategoryPlot(dataset, 
                new CategoryAxis("Category"), new NumberAxis("Value"), 
                new LevelRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200, 
                null);
        success = true;
    }
    catch (NullPointerException e) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
 
Example #20
Source File: StatisticalLineAndShapeRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws the chart with a <code>null</code> info object to make sure that
 * no exceptions are thrown (particularly by code in the renderer).
 */
@Test
public void testDrawWithNullInfo() {
    try {
        DefaultStatisticalCategoryDataset dataset
            = new DefaultStatisticalCategoryDataset();
        dataset.add(1.0, 2.0, "S1", "C1");
        dataset.add(3.0, 4.0, "S1", "C2");
        CategoryPlot plot = new CategoryPlot(dataset,
                new CategoryAxis("Category"), new NumberAxis("Value"),
                new StatisticalLineAndShapeRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */ chart.createBufferedImage(300, 200,
                null);
    }
    catch (NullPointerException e) {
        fail("No exception should be thrown.");
    }
}
 
Example #21
Source File: AbstractRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the paint lookup mechanism.
 */
public void testPaintLookup() {
    BarRenderer r = new BarRenderer();
    assertEquals(Color.blue, r.getBasePaint());
    
    // first check that autoPopulate==false works as expected
    r.setAutoPopulateSeriesPaint(false);
    assertEquals(Color.blue, r.lookupSeriesPaint(0));
    assertNull(r.getSeriesPaint(0));
    
    // now check autoPopulate==true
    r.setAutoPopulateSeriesPaint(true);
    /*CategoryPlot plot =*/ new CategoryPlot(null, new CategoryAxis(
            "Category"), new NumberAxis("Value"), r);
    assertEquals(DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[0], 
            r.lookupSeriesPaint(0));
    assertNotNull(r.getSeriesPaint(0));
}
 
Example #22
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 #23
Source File: AbstractRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Some checks for the fill paint lookup mechanism.
 */
@Test
public void testFillPaintLookup() {
    BarRenderer r = new BarRenderer();
    assertEquals(Color.white, r.getBaseFillPaint());

    // first check that autoPopulate==false works as expected
    r.setAutoPopulateSeriesFillPaint(false);
    assertEquals(Color.white, r.lookupSeriesFillPaint(0));
    assertNull(r.getSeriesFillPaint(0));

    // now check autoPopulate==true
    r.setAutoPopulateSeriesFillPaint(true);
    /*CategoryPlot plot =*/ new CategoryPlot(null, new CategoryAxis(
            "Category"), new NumberAxis("Value"), r);
    assertEquals(DefaultDrawingSupplier.DEFAULT_FILL_PAINT_SEQUENCE[0],
            r.lookupSeriesFillPaint(0));
    assertNotNull(r.getSeriesFillPaint(0));
}
 
Example #24
Source File: StackedXYAreaRenderer2Test.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.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 #25
Source File: LineAndShapeRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    LineAndShapeRenderer r = new LineAndShapeRenderer();
    CategoryPlot plot = new CategoryPlot(dataset0, new CategoryAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, dataset1);
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("R5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example #26
Source File: XYLineAndShapeRendererTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the range bounds correctly.
 */
@Test
public void testFindRangeBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.createTestTableXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    Range bounds = rangeAxis.getRange();
    assertFalse(bounds.contains(1.0));
    assertTrue(bounds.contains(2.0));
    assertTrue(bounds.contains(5.0));
    assertFalse(bounds.contains(6.0));
}
 
Example #27
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates an area chart with default settings.  The chart object returned
 * by this method uses a {@link CategoryPlot} instance as the plot, with a
 * {@link CategoryAxis} for the domain axis, a {@link NumberAxis} as the
 * range axis, and an {@link AreaRenderer} as the renderer.
 *
 * @param title  the chart title (<code>null</code> permitted).
 * @param categoryAxisLabel  the label for the category axis
 *                           (<code>null</code> permitted).
 * @param valueAxisLabel  the label for the value 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 An area chart.
 */
public static JFreeChart createAreaChart(String title,
        String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    categoryAxis.setCategoryMargin(0.0);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    AreaRenderer renderer = new AreaRenderer();
    renderer.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator());
    CategoryPlot plot = new CategoryPlot(dataset, categoryAxis, valueAxis,
            renderer);
    JFreeChart chart = new JFreeChart(title, JFreeChart.DEFAULT_TITLE_FONT,
            plot, legend);
    currentTheme.apply(chart);
    return chart;

}
 
Example #28
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testMapDatasetToDomainAxis() {
    XYDataset dataset = new XYSeriesCollection();
    NumberAxis xAxis = new NumberAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    XYItemRenderer renderer = new DefaultXYItemRenderer();
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    NumberAxis xAxis2 = new NumberAxis("X2");
    plot.setDomainAxis(11, xAxis2);
    
    // add a second dataset
    XYSeriesCollection dataset2 = new XYSeriesCollection();
    dataset2.addSeries(new XYSeries("Series in dataset 2"));
    plot.setDataset(99, dataset);    
    
    assertEquals(xAxis, plot.getDomainAxisForDataset(99));

    // now map the dataset to the second xAxis
    plot.mapDatasetToDomainAxis(99, 11);
    assertEquals(xAxis2, plot.getDomainAxisForDataset(99));
}
 
Example #29
Source File: CombinedRangeCategoryPlotTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Creates a sample plot.
 *
 * @return A plot.
 */
private CombinedRangeCategoryPlot createPlot() {
    CategoryDataset dataset1 = createDataset1();
    CategoryAxis catAxis1 = new CategoryAxis("Category");
    LineAndShapeRenderer renderer1 = new LineAndShapeRenderer();
    renderer1.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator());
    CategoryPlot subplot1 = new CategoryPlot(dataset1, catAxis1, null,
            renderer1);
    subplot1.setDomainGridlinesVisible(true);

    CategoryDataset dataset2 = createDataset2();
    CategoryAxis catAxis2 = new CategoryAxis("Category");
    BarRenderer renderer2 = new BarRenderer();
    renderer2.setBaseToolTipGenerator(
            new StandardCategoryToolTipGenerator());
    CategoryPlot subplot2 = new CategoryPlot(dataset2, catAxis2, null,
            renderer2);
    subplot2.setDomainGridlinesVisible(true);

    NumberAxis rangeAxis = new NumberAxis("Value");
    CombinedRangeCategoryPlot plot = new CombinedRangeCategoryPlot(
            rangeAxis);
    plot.add(subplot1, 2);
    plot.add(subplot2, 1);
    return plot;
}
 
Example #30
Source File: XYDotRendererTests.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);

    XYDotRenderer r = new XYDotRenderer();
    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());
}