org.jfree.chart.ChartFactory Java Examples

The following examples show how to use org.jfree.chart.ChartFactory. 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: PiePlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a pie chart where the label generator returns null.
 */
@Test
public void testDrawWithNullLegendLabels() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("L1", 12.0);
    dataset.setValue("L2", 11.0);
    JFreeChart chart = ChartFactory.createPieChart("Test", dataset, true,
            false, false);
    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setLegendLabelGenerator(new NullLegendLabelGenerator());
    boolean success = false;
    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: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 6 votes vote down vote up
/**
 * Performing scatter plot with grid
 * @param xLabel
 * @param yLabel
 */
public JFreeChart scatterGridPlot(String xLabel, String yLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createScatterPlot(chartTitle
            , xLabel
            , yLabel
            , dataset.get(0));
    XYPlot plot = result.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));        
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        plot.setRenderer(i, new XYLineAndShapeRenderer(true, true));
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example #3
Source File: ChartViewerUtil.java    From cst with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static synchronized ChartPanel createLineXYChart(XYSeriesCollection dataset, String title, String categoryAxisLabel, String valueAxisLabel, long timeRefresh) {

        final JFreeChart chart = ChartFactory.createXYLineChart(title, categoryAxisLabel, valueAxisLabel, dataset, PlotOrientation.VERTICAL, true, true, false);

        final XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(Color.lightGray);
        plot.setDomainGridlinePaint(Color.white);
        plot.setRangeGridlinePaint(Color.white);
        plot.getDomainAxis().setFixedAutoRange(timeRefresh * 100);
        chart.setBackgroundPaint(Color.lightGray);

        ChartPanel localChartPanel = new ChartPanel(chart);
        localChartPanel.setVisible(true);
        localChartPanel.setDomainZoomable(true);

        return localChartPanel;
    }
 
Example #4
Source File: LineChart3DTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Create a line chart with sample data in the range -3 to +3.
 *
 * @return The chart.
 */
private static JFreeChart createLineChart3D() {

    // create a dataset...
    Number[][] data = new Integer[][]
        {{new Integer(-3), new Integer(-2)},
         {new Integer(-1), new Integer(1)},
         {new Integer(2), new Integer(3)}};

    CategoryDataset dataset = DatasetUtilities.createCategoryDataset("S", 
            "C", data);

    // create the chart...
    return ChartFactory.createLineChart3D(
        "Line Chart",
        "Domain", "Range",
        dataset,
        PlotOrientation.HORIZONTAL,
        true,     // include legend
        true,
        true
    );

}
 
Example #5
Source File: StackedXYAreaRenderer2Test.java    From ECG-Viewer 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.
 */
@Test
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 #6
Source File: CategoryPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * This test ensures that a plot with markers is serialized correctly.
 */
@Test
public void testSerialization4() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createBarChart(
            "Test Chart", "Category Axis", "Value Axis",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.addRangeMarker(new ValueMarker(1.1), Layer.FOREGROUND);
    plot.addRangeMarker(new IntervalMarker(2.2, 3.3), Layer.BACKGROUND);
    JFreeChart chart2 = (JFreeChart) TestUtilities.serialised(chart);
    assertEquals(chart, chart2);

    // now check that the chart is usable...
    try {
        chart2.createBufferedImage(300, 200);
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #7
Source File: ParallelPlotter2.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
private static JFreeChart createChart(XYDataset dataset) {

		// create the chart...
		JFreeChart chart = ChartFactory.createXYLineChart(null,                      // chart title
				null,                      // x axis label
				null,                      // y axis label
				dataset,                   // data
				PlotOrientation.VERTICAL, false,                     // include legend
				true,                      // tooltips
				false                      // urls
				);

		chart.setBackgroundPaint(Color.white);

		// get a reference to the plot for further customization...
		XYPlot plot = (XYPlot) chart.getPlot();
		plot.setBackgroundPaint(Color.WHITE);

		ValueAxis valueAxis = plot.getRangeAxis();
		valueAxis.setLabelFont(LABEL_FONT_BOLD);
		valueAxis.setTickLabelFont(LABEL_FONT);

		return chart;
	}
 
Example #8
Source File: ChartPanelTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that a call to the zoom() method generates just one
 * ChartChangeEvent.
 */
public void test2502355_zoom() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("TestChart", "X",
            "Y", dataset, false);
    ChartPanel panel = new ChartPanel(chart);
    chart.addChangeListener(this);
    this.chartChangeEvents.clear();
    panel.zoom(new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0));
    assertEquals(1, this.chartChangeEvents.size());
}
 
Example #9
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
@Test
public void test1654215() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new XYLineAndShapeRenderer());
    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();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #10
Source File: GraphData.java    From iBioSim with Apache License 2.0 6 votes vote down vote up
public GraphData(String printer_id, String outDir, boolean warn, String printer_track_quantity, String label, XYSeriesCollection dataset, String time,
		ArrayList<String> learnSpecs) {
	this.outDir = outDir;
	this.printer_id = printer_id;
	this.warn = warn;
	this.learnSpecs = learnSpecs;
	graphSpecies = new ArrayList<String>();
	graphed = new LinkedList<GraphSpecies>();
	chart = ChartFactory.createXYLineChart(label, time, printer_track_quantity, dataset, PlotOrientation.VERTICAL, true, true, false);
	applyChartTheme();
	chart.setBackgroundPaint(new java.awt.Color(238, 238, 238));
	chart.getPlot().setBackgroundPaint(java.awt.Color.WHITE);
	chart.getXYPlot().setDomainGridlinePaint(java.awt.Color.LIGHT_GRAY);
	chart.getXYPlot().setRangeGridlinePaint(java.awt.Color.LIGHT_GRAY);
	legend = chart.getLegend();
	timeSeriesPlot = true;
	LogX = false;
	LogY = false;
	visibleLegend = false;
	averageOrder = null;
	resize(dataset);
}
 
Example #11
Source File: Chart.java    From Neural-Network-Programming-with-Java-SecondEdition with MIT License 6 votes vote down vote up
/**
 * Performing line plot
 * @param xLabel
 * @param yLabel
 */
public JFreeChart linePlot(String xLabel, String yLabel){
    int numDatasets = dataset.size();
    JFreeChart result = ChartFactory.createXYLineChart(
chartTitle, // chart title
xLabel, // x axis label
yLabel, // y axis label
dataset.get(0), // data
PlotOrientation.VERTICAL, 
true, // include legend
true, // tooltips
false // urls
    );
    XYPlot plot = result.getXYPlot();
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    plot.getRenderer().setSeriesPaint(0, seriesColor.get(0));
    for(int i=1;i<numDatasets;i++){
        plot.setDataset(i,dataset.get(i));
        //XYItemRenderer renderer = plot.getRenderer(i-0);
        //plot.setRenderer(i, new XYLineAndShapeRenderer(false, true));
        plot.getRenderer(i).setSeriesStroke(0, new BasicStroke(1.0f));
        plot.getRenderer(i).setSeriesPaint(0,seriesColor.get(i));
    }

    return result;
}
 
Example #12
Source File: PiePlot3DTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Draws a pie chart where the label generator returns null.
 */
@Test
public void testDrawWithNullDataset() {
    JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true,
            false, false);
    boolean success = false;
    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 #13
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
@Test
public void test1654215() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new XYLineAndShapeRenderer());
    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();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #14
Source File: PiePlot3DTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Draws a pie chart where the label generator returns null.
 */
@Test
public void testDrawWithNullDataset() {
    JFreeChart chart = ChartFactory.createPieChart3D("Test", null, true,
            false, false);
    boolean success = false;
    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 #15
Source File: CategoryPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This test ensures that a plot with markers is serialized correctly.
 */
@Test
public void testSerialization4() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createBarChart(
            "Test Chart", "Category Axis", "Value Axis",
            dataset, PlotOrientation.VERTICAL, true, true, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.addRangeMarker(new ValueMarker(1.1), Layer.FOREGROUND);
    plot.addRangeMarker(new IntervalMarker(2.2, 3.3), Layer.BACKGROUND);
    JFreeChart chart2 = (JFreeChart) TestUtilities.serialised(chart);
    assertEquals(chart, chart2);

    // now check that the chart is usable...
    try {
        chart2.createBufferedImage(300, 200);
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #16
Source File: CategoryPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
@Test
public void test1654215() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(1, new LineAndShapeRenderer());
    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();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #17
Source File: MultiExtXmlChartDemo.java    From pentaho-reporting with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
   * Creates a sample chart.
   *
   * @return A chart.
   */
  private JFreeChart createChart(final int year)
  {

    final JFreeChart chart = ChartFactory.createPieChart3D(
        "Programming Language of the Year " + year, // chart title
        createSampleDataset(), // data
        true, // include legend
        true,
        false
    );

    // set the background color for the chart...
    final PiePlot3D plot = (PiePlot3D) chart.getPlot();
    plot.setStartAngle(270);
//    plot.setDirection(Rotation.CLOCKWISE);
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage("No data to display");

    return chart;

  }
 
Example #18
Source File: XYLineAndShapeRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    XYSeriesCollection dataset
            = RendererXYPackageUtils.createTestXYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart(
            "Test Chart", "X", "Y", dataset, PlotOrientation.VERTICAL,
            false, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    Range bounds = domainAxis.getRange();
    assertFalse(bounds.contains(0.9));
    assertTrue(bounds.contains(1.0));
    assertTrue(bounds.contains(2.0));
    assertFalse(bounds.contains(2.10));
}
 
Example #19
Source File: NumberAxisTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Checks that the auto-range for the range axis on an XYPlot is
 * working as expected.
 */
public void testXYAutoRange2() {
    XYSeries series = new XYSeries("Series 1");
    series.add(1.0, 1.0);
    series.add(2.0, 2.0);
    series.add(3.0, 3.0);
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Test", "X", "Y",
            dataset, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    assertEquals(0.9, axis.getLowerBound(), EPSILON);
    assertEquals(3.1, axis.getUpperBound(), EPSILON);
}
 
Example #20
Source File: ManaRepartitionPanel.java    From MtgDesktopCompanion with GNU General Public License v3.0 6 votes vote down vote up
@Override
public JFreeChart initChart() {
	
	JFreeChart chart = ChartFactory.createPieChart3D("Color repartition", // chart title
			getDataSet(), // data
			false, // include legend
			true, true);
	
	PiePlot plot = (PiePlot) chart.getPlot();
	
	for(MTGColor c : MTGColor.values())
	{
		plot.setSectionPaint(c,c.toColor());
		
	}
	plot.setSectionPaint("Multi", Color.YELLOW);
	plot.setSectionPaint("multi", Color.YELLOW);
	
	plot.setSimpleLabels(true);

	PieSectionLabelGenerator generator = new StandardPieSectionLabelGenerator("{1}", new DecimalFormat("0"),
			new DecimalFormat("0.00%"));
	plot.setLabelGenerator(generator);

	return chart;
}
 
Example #21
Source File: NumberAxisTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * NumberAxis used as the range axis for a CategoryPlot.  In this
 * case, the 'autoRangeIncludesZero' flag is set to false AND the
 * original dataset is replaced with a new dataset.
 */
@Test
public void testAutoRange3() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",
            "Value", dataset, PlotOrientation.VERTICAL, false, false,
            false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    assertEquals(axis.getLowerBound(), 95.0, EPSILON);
    assertEquals(axis.getUpperBound(), 205.0, EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(axis.getLowerBound(), 895.0, EPSILON);
    assertEquals(axis.getUpperBound(), 1005.0, EPSILON);
}
 
Example #22
Source File: SWTPieChartDemo1.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a chart.
 * 
 * @param dataset  the dataset.
 * 
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {
    
    JFreeChart chart = ChartFactory.createPieChart(
        "Pie Chart Demo 1",  // chart title
        dataset,             // data
        true,               // include legend
        true,
        false
    );

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setSectionOutlinesVisible(false);
    plot.setLabelFont(new Font("SansSerif", Font.PLAIN, 12));
    plot.setNoDataMessage("No data available");
    plot.setCircular(false);
    plot.setLabelGap(0.02);
    return chart;
    
}
 
Example #23
Source File: XYLineAndShapeRendererTest.java    From SIMVA-SoS with Apache License 2.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 #24
Source File: ValueAxisTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Tests the the lower and upper margin settings produce the expected
 * results.
 */
@Test
public void testAxisMargins() {
    XYSeries series = new XYSeries("S1");
    series.add(100.0, 1.1);
    series.add(200.0, 2.2);
    XYSeriesCollection dataset = new XYSeriesCollection(series);
    dataset.setIntervalWidth(0.0);
    JFreeChart chart = ChartFactory.createScatterPlot("Title", "X", "Y", 
            dataset);
    ValueAxis domainAxis = ((XYPlot) chart.getPlot()).getDomainAxis();
    Range r = domainAxis.getRange();
    assertEquals(110.0, r.getLength(), EPSILON);
    domainAxis.setLowerMargin(0.10);
    domainAxis.setUpperMargin(0.10);
    r = domainAxis.getRange();
    assertEquals(120.0, r.getLength(), EPSILON);
}
 
Example #25
Source File: CategoryPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Serialize an instance, restore it, and check for equality.
 */
@Test
public void testSerialization3() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createBarChart(
            "Test Chart", "Category Axis", "Value Axis", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    JFreeChart chart2 = (JFreeChart) TestUtilities.serialised(chart);

    // now check that the chart is usable...
    try {
        chart2.createBufferedImage(300, 200);
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #26
Source File: StackedXYBarRendererTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Check that the renderer is calculating the domain bounds correctly.
 */
@Test
public void testFindDomainBounds() {
    TableXYDataset dataset
            = RendererXYPackageUtils.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 #27
Source File: XYPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test for bug 1654215 (where a renderer is added to the plot without
 * a corresponding dataset and it throws an exception at drawing time).
 */
@Test
public void test1654215() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    JFreeChart chart = ChartFactory.createXYLineChart("Title", "X", "Y",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new XYLineAndShapeRenderer());
    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();
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}
 
Example #28
Source File: JFreeChartTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Common test setup.
 */
protected void setUp() {

    // create a dataset...
    DefaultPieDataset data = new DefaultPieDataset();
    data.setValue("Java", new Double(43.2));
    data.setValue("Visual Basic", new Double(0.0));
    data.setValue("C/C++", new Double(17.5));

    // create the chart...
    this.pieChart = ChartFactory.createPieChart(
        "Pie Chart",  // chart title
        data,         // data
        true,         // include legend
        true,
        false
    );

}
 
Example #29
Source File: NumberAxisTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A simple test for the auto-range calculation looking at a
 * NumberAxis used as the range axis for a CategoryPlot.  In this
 * case, the 'autoRangeIncludesZero' flag is set to false AND the
 * original dataset is replaced with a new dataset.
 */
@Test
public void testAutoRange3() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.setValue(100.0, "Row 1", "Column 1");
    dataset.setValue(200.0, "Row 1", "Column 2");
    JFreeChart chart = ChartFactory.createLineChart("Test", "Categories",
            "Value", dataset, PlotOrientation.VERTICAL, false, false,
            false);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    NumberAxis axis = (NumberAxis) plot.getRangeAxis();
    axis.setAutoRangeIncludesZero(false);
    assertEquals(axis.getLowerBound(), 95.0, EPSILON);
    assertEquals(axis.getUpperBound(), 205.0, EPSILON);

    // now replacing the dataset should update the axis range...
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(900.0, "Row 1", "Column 1");
    dataset2.setValue(1000.0, "Row 1", "Column 2");
    plot.setDataset(dataset2);
    assertEquals(axis.getLowerBound(), 895.0, EPSILON);
    assertEquals(axis.getUpperBound(), 1005.0, EPSILON);
}
 
Example #30
Source File: XYPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A test to reproduce a bug in serialization: the domain and/or range
 * markers for a plot are not being serialized.
 */
@Test
public void testSerialization4() {

    XYSeriesCollection dataset = new XYSeriesCollection();
    JFreeChart chart = ChartFactory.createXYLineChart("Test Chart",
            "Domain Axis", "Range Axis", dataset);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.addDomainMarker(new ValueMarker(1.0), Layer.FOREGROUND);
    plot.addDomainMarker(new IntervalMarker(2.0, 3.0), Layer.BACKGROUND);
    plot.addRangeMarker(new ValueMarker(4.0), Layer.FOREGROUND);
    plot.addRangeMarker(new IntervalMarker(5.0, 6.0), Layer.BACKGROUND);
    JFreeChart chart2 = (JFreeChart) TestUtilities.serialised(chart);
    assertEquals(chart, chart2);
    try {
        chart2.createBufferedImage(300, 200);
    }
    catch (Exception e) {
        fail("No exception should be thrown.");
    }
}