org.jfree.chart.renderer.category.LineAndShapeRenderer Java Examples

The following examples show how to use org.jfree.chart.renderer.category.LineAndShapeRenderer. 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: CategoryPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
@Test 
public void testRendererIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    assertEquals(renderer, plot.getRenderer(0));
    
    // we should be able to give a renderer an arbitrary index
    CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(20, renderer2);
    assertEquals(2, plot.getRendererCount());
    assertEquals(renderer2, plot.getRenderer(20));
    
    assertEquals(20, plot.getIndexOf(renderer2));
}
 
Example #2
Source File: CategoryPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testRangeMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);    
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(1, yAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    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 #3
Source File: CategoryPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDomainMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second x axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);    
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToDomainAxis(99, 1);
    
    CategoryMarker xMarker1 = new CategoryMarker(123);
    plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND);
    assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains(
            xMarker1));
}
 
Example #4
Source File: CategoryPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Renderers that belong to the plot are being cloned but they are
 * retaining a reference to the original plot.
 */
@Test
public void testBug2817504() {
    CategoryPlot p1 = new CategoryPlot();
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    p1.setRenderer(r1);
    CategoryPlot p2;
    try {
        p2 = (CategoryPlot) p1.clone();
    }
    catch (CloneNotSupportedException e) {
        fail("Cloning failed.");
        return;
    }
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // check for independence
    LineAndShapeRenderer r2 = (LineAndShapeRenderer) p2.getRenderer();
    assertTrue(r2.getPlot() == p2);
}
 
Example #5
Source File: AbstractRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for cloning.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    r1.setBasePaint(Color.blue);
    r1.setBaseLegendTextPaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    LineAndShapeRenderer r2 = (LineAndShapeRenderer) r1.clone();
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    MyRendererChangeListener listener = new MyRendererChangeListener();
    r2.addChangeListener(listener);
    r2.setBasePaint(Color.red);
    assertTrue(listener.lastEvent.getRenderer() == r2);
    assertFalse(r1.hasListener(listener));
}
 
Example #6
Source File: CategoryPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
@Test 
public void testRendererIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    assertEquals(renderer, plot.getRenderer(0));
    
    // we should be able to give a renderer an arbitrary index
    CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(20, renderer2);
    assertEquals(2, plot.getRendererCount());
    assertEquals(renderer2, plot.getRenderer(20));
    
    assertEquals(20, plot.getIndexOf(renderer2));
}
 
Example #7
Source File: CategoryPlotTest.java    From ccu-historian 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 #8
Source File: CategoryPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
@Test 
public void testGetRendererForDataset2() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    // add a second dataset
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset2);
   
    // by default, the renderer with index 0 is used
    assertEquals(renderer, plot.getRendererForDataset(dataset2));
    
    // add a second renderer with the same index as dataset2, now it will
    // be used
    CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    assertEquals(renderer2, plot.getRendererForDataset(dataset2));
}
 
Example #9
Source File: CategoryPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDomainMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second x axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);    
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToDomainAxis(99, 1);
    
    CategoryMarker xMarker1 = new CategoryMarker(123);
    plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND);
    assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains(
            xMarker1));
}
 
Example #10
Source File: CategoryPlotTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testRangeMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);    
    NumberAxis yAxis2 = new NumberAxis("Y2");
    plot.setRangeAxis(1, yAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    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 #11
Source File: EyeCandySixtiesChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
	protected JFreeChart createLineChart() throws JRException
	{
		JFreeChart jfreeChart = super.createLineChart();
		CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
		LineAndShapeRenderer lineRenderer = (LineAndShapeRenderer)categoryPlot.getRenderer();
		lineRenderer.setBaseStroke(new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
//		Stroke stroke = new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

		for (int i = 0; i < lineRenderer.getRowCount(); i++)
		{
			lineRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
			lineRenderer.setSeriesFillPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
			lineRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
			lineRenderer.setSeriesShapesVisible(i,true);
			//it isn't applied at the moment
			//lineRenderer.setSeriesStroke(i,stroke);
			
			//line3DRenderer.setSeriesLinesVisible(i,lineRenderer.getSeriesVisible(i));
		}
//		configureChart(jfreeChart, getPlot());
		return jfreeChart;
	}
 
Example #12
Source File: CategoryPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDomainMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second x axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);    
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToDomainAxis(99, 1);
    
    CategoryMarker xMarker1 = new CategoryMarker(123);
    plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND);
    assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains(
            xMarker1));
}
 
Example #13
Source File: AbstractRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A check for cloning.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    r1.setBasePaint(Color.blue);
    r1.setBaseLegendTextPaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    LineAndShapeRenderer r2 = (LineAndShapeRenderer) r1.clone();
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    MyRendererChangeListener listener = new MyRendererChangeListener();
    r2.addChangeListener(listener);
    r2.setBasePaint(Color.red);
    assertTrue(listener.lastEvent.getRenderer() == r2);
    assertFalse(r1.hasListener(listener));
}
 
Example #14
Source File: CategoryPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Renderers that belong to the plot are being cloned but they are
 * retaining a reference to the original plot.
 */
@Test
public void testBug2817504() {
    CategoryPlot p1 = new CategoryPlot();
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    p1.setRenderer(r1);
    CategoryPlot p2;
    try {
        p2 = (CategoryPlot) p1.clone();
    }
    catch (CloneNotSupportedException e) {
        fail("Cloning failed.");
        return;
    }
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // check for independence
    LineAndShapeRenderer r2 = (LineAndShapeRenderer) p2.getRenderer();
    assertTrue(r2.getPlot() == p2);
}
 
Example #15
Source File: CategoryPlotTest.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() {
    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 #16
Source File: AbstractRendererTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for cloning.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    r1.setBasePaint(Color.blue);
    r1.setBaseLegendTextPaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    LineAndShapeRenderer r2 = (LineAndShapeRenderer) r1.clone();
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    MyRendererChangeListener listener = new MyRendererChangeListener();
    r2.addChangeListener(listener);
    r2.setBasePaint(Color.red);
    assertTrue(listener.lastEvent.getRenderer() == r2);
    assertFalse(r1.hasListener(listener));
}
 
Example #17
Source File: CategoryPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
@Test 
public void testGetRendererForDataset2() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    // add a second dataset
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset2);
   
    // by default, the renderer with index 0 is used
    assertEquals(renderer, plot.getRendererForDataset(dataset2));
    
    // add a second renderer with the same index as dataset2, now it will
    // be used
    CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    assertEquals(renderer2, plot.getRendererForDataset(dataset2));
}
 
Example #18
Source File: CategoryPlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
@Test
public void testDomainMarkerIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    // add a second dataset, plotted against a second x axis
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset);    
    CategoryAxis xAxis2 = new CategoryAxis("X2");
    plot.setDomainAxis(1, xAxis2);
    LineAndShapeRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    plot.mapDatasetToDomainAxis(99, 1);
    
    CategoryMarker xMarker1 = new CategoryMarker(123);
    plot.addDomainMarker(99, xMarker1, Layer.FOREGROUND);
    assertTrue(plot.getDomainMarkers(99, Layer.FOREGROUND).contains(
            xMarker1));
}
 
Example #19
Source File: CategoryPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
@Test 
public void testGetRendererForDataset2() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);

    // add a second dataset
    DefaultCategoryDataset dataset2 = new DefaultCategoryDataset();
    dataset2.setValue(1, "R1", "C1");
    plot.setDataset(99, dataset2);
   
    // by default, the renderer with index 0 is used
    assertEquals(renderer, plot.getRendererForDataset(dataset2));
    
    // add a second renderer with the same index as dataset2, now it will
    // be used
    CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(99, renderer2);
    assertEquals(renderer2, plot.getRendererForDataset(dataset2));
}
 
Example #20
Source File: CategoryPlotTest.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() {
    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 #21
Source File: AbstractRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for cloning.
 */
@Test
public void testCloning2() throws CloneNotSupportedException {
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    r1.setBasePaint(Color.blue);
    r1.setBaseLegendTextPaint(new GradientPaint(1.0f, 2.0f, Color.red,
            3.0f, 4.0f, Color.blue));
    LineAndShapeRenderer r2 = (LineAndShapeRenderer) r1.clone();
    assertTrue(r1 != r2);
    assertTrue(r1.getClass() == r2.getClass());
    assertTrue(r1.equals(r2));

    MyRendererChangeListener listener = new MyRendererChangeListener();
    r2.addChangeListener(listener);
    r2.setBasePaint(Color.red);
    assertTrue(listener.lastEvent.getRenderer() == r2);
    assertFalse(r1.hasListener(listener));
}
 
Example #22
Source File: CategoryPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Renderers that belong to the plot are being cloned but they are
 * retaining a reference to the original plot.
 */
@Test
public void testBug2817504() {
    CategoryPlot p1 = new CategoryPlot();
    LineAndShapeRenderer r1 = new LineAndShapeRenderer();
    p1.setRenderer(r1);
    CategoryPlot p2;
    try {
        p2 = (CategoryPlot) p1.clone();
    }
    catch (CloneNotSupportedException e) {
        fail("Cloning failed.");
        return;
    }
    assertTrue(p1 != p2);
    assertTrue(p1.getClass() == p2.getClass());
    assertTrue(p1.equals(p2));

    // check for independence
    LineAndShapeRenderer r2 = (LineAndShapeRenderer) p2.getRenderer();
    assertTrue(r2.getPlot() == p2);
}
 
Example #23
Source File: CategoryPlotTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
@Test 
public void testRendererIndices() {
    CategoryDataset dataset = new DefaultCategoryDataset();
    CategoryAxis xAxis = new CategoryAxis("X");
    NumberAxis yAxis = new NumberAxis("Y");
    CategoryItemRenderer renderer = new BarRenderer();
    CategoryPlot plot = new CategoryPlot(dataset, xAxis, yAxis, renderer);
    
    assertEquals(renderer, plot.getRenderer(0));
    
    // we should be able to give a renderer an arbitrary index
    CategoryItemRenderer renderer2 = new LineAndShapeRenderer();
    plot.setRenderer(20, renderer2);
    assertEquals(2, plot.getRendererCount());
    assertEquals(renderer2, plot.getRenderer(20));
    
    assertEquals(20, plot.getIndexOf(renderer2));
}
 
Example #24
Source File: ChartFactory.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a line 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 a {@link LineAndShapeRenderer} 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 A line chart.
 */
public static JFreeChart createLineChart(String title,
        String categoryAxisLabel, String valueAxisLabel,
        CategoryDataset dataset, boolean legend) {

    CategoryAxis categoryAxis = new CategoryAxis(categoryAxisLabel);
    ValueAxis valueAxis = new NumberAxis(valueAxisLabel);
    LineAndShapeRenderer renderer = new LineAndShapeRenderer(true, false);
    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 #25
Source File: CategoryPlotTests.java    From astor 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).
 */
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());
    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) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}
 
Example #26
Source File: LineAndShapeRendererTests.java    From astor 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.
 */
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 #27
Source File: LineAndShapeRendererTests.java    From astor 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.
 */
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 #28
Source File: AbstractCategoryItemRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Some checks for the findRangeBounds() method.
 */
public void testFindRangeBounds() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNull(r.findRangeBounds(null));

    // an empty dataset should return a null range
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    assertNull(r.findRangeBounds(dataset));

    dataset.addValue(1.0, "R1", "C1");
    assertEquals(new Range(1.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(-2.0, "R1", "C2");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));

    dataset.addValue(null, "R1", "C3");
    assertEquals(new Range(-2.0, 1.0), r.findRangeBounds(dataset));
}
 
Example #29
Source File: AbstractCategoryItemRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A test that reproduces the problem reported in bug 2947660.
 */
public void test2947660() {
    AbstractCategoryItemRenderer r = new LineAndShapeRenderer();
    assertNotNull(r.getLegendItems());
    assertEquals(0, r.getLegendItems().getItemCount());

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(dataset);
    plot.setRenderer(r);
    assertEquals(0, r.getLegendItems().getItemCount());

    dataset.addValue(1.0, "S1", "C1");
    LegendItemCollection lic = r.getLegendItems();
    assertEquals(1, lic.getItemCount());
    assertEquals("S1", lic.get(0).getLabel());
}
 
Example #30
Source File: CategoryPlotTests.java    From astor 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).
 */
public void test1654215() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    JFreeChart chart = ChartFactory.createLineChart("Title", "X", "Y",
            dataset, true);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setRenderer(1, new LineAndShapeRenderer());
    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) {
        e.printStackTrace();
        success = false;
    }
    assertTrue(success);
}