Search in sources :

Example 56 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class GroupedStackedBarRendererTest method testDrawWithNullInfo.

/**
 * 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 {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "S1", "C1");
        dataset.addValue(2.0, "S1", "C2");
        dataset.addValue(3.0, "S2", "C1");
        dataset.addValue(4.0, "S2", "C2");
        GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
        CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), renderer);
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */
        chart.createBufferedImage(300, 200, null);
    } catch (NullPointerException e) {
        fail("No exception should be thrown.");
    }
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 57 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class LayeredBarRendererTest method testDrawWithNullInfo.

/**
 * 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 {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        dataset.addValue(1.0, "S1", "C1");
        CategoryPlot plot = new CategoryPlot(dataset, new CategoryAxis("Category"), new NumberAxis("Value"), new LayeredBarRenderer());
        JFreeChart chart = new JFreeChart(plot);
        /* BufferedImage image = */
        chart.createBufferedImage(300, 200, null);
    } catch (NullPointerException e) {
        fail("No exception should be thrown.");
    }
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.Test)

Example 58 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class CategoryAxis3D method getCategoryJava2DCoordinate.

/**
 * Returns the Java 2D coordinate for a category.
 *
 * @param anchor  the anchor point.
 * @param category  the category index.
 * @param categoryCount  the category count.
 * @param area  the data area.
 * @param edge  the location of the axis.
 *
 * @return The coordinate.
 */
@Override
public double getCategoryJava2DCoordinate(CategoryAnchor anchor, int category, int categoryCount, Rectangle2D area, RectangleEdge edge) {
    double result = 0.0;
    Rectangle2D adjustedArea = area;
    CategoryPlot plot = (CategoryPlot) getPlot();
    CategoryItemRenderer renderer = plot.getRenderer();
    if (renderer instanceof Effect3D) {
        Effect3D e3D = (Effect3D) renderer;
        double adjustedX = area.getMinX();
        double adjustedY = area.getMinY();
        double adjustedW = area.getWidth() - e3D.getXOffset();
        double adjustedH = area.getHeight() - e3D.getYOffset();
        if (edge == RectangleEdge.LEFT || edge == RectangleEdge.BOTTOM) {
            adjustedY += e3D.getYOffset();
        } else if (edge == RectangleEdge.RIGHT || edge == RectangleEdge.TOP) {
            adjustedX += e3D.getXOffset();
        }
        adjustedArea = new Rectangle2D.Double(adjustedX, adjustedY, adjustedW, adjustedH);
    }
    if (anchor == CategoryAnchor.START) {
        result = getCategoryStart(category, categoryCount, adjustedArea, edge);
    } else if (anchor == CategoryAnchor.MIDDLE) {
        result = getCategoryMiddle(category, categoryCount, adjustedArea, edge);
    } else if (anchor == CategoryAnchor.END) {
        result = getCategoryEnd(category, categoryCount, adjustedArea, edge);
    }
    return result;
}
Also used : CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) Rectangle2D(java.awt.geom.Rectangle2D) Effect3D(org.jfree.chart.Effect3D) CategoryPlot(org.jfree.chart.plot.CategoryPlot)

Example 59 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class GanttChartTest method testDrawWithNullInfo2.

/**
 * Draws the chart with a <code>null</code> info object to make sure that
 * no exceptions are thrown (a problem that was occurring at one point).
 */
@Test
public void testDrawWithNullInfo2() {
    JFreeChart chart = createGanttChart();
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDataset(createDataset());
    /* BufferedImage img =*/
    chart.createBufferedImage(300, 200, null);
// FIXME we should really assert a value
}
Also used : CategoryPlot(org.jfree.chart.plot.CategoryPlot) Test(org.junit.Test)

Example 60 with CategoryPlot

use of org.jfree.chart.plot.CategoryPlot in project SIMVA-SoS by SESoS.

the class GanttChartTest method testReplaceDataset.

/**
 * Replaces the chart's dataset and then checks that the new dataset is OK.
 */
@Test
public void testReplaceDataset() {
    LocalListener l = new LocalListener();
    this.chart.addChangeListener(l);
    CategoryPlot plot = (CategoryPlot) this.chart.getPlot();
    plot.setDataset(null);
    assertEquals(true, l.flag);
}
Also used : CategoryPlot(org.jfree.chart.plot.CategoryPlot) Test(org.junit.Test)

Aggregations

CategoryPlot (org.jfree.chart.plot.CategoryPlot)189 JFreeChart (org.jfree.chart.JFreeChart)94 CategoryAxis (org.jfree.chart.axis.CategoryAxis)88 NumberAxis (org.jfree.chart.axis.NumberAxis)80 Test (org.junit.Test)72 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)44 CategoryItemRenderer (org.jfree.chart.renderer.category.CategoryItemRenderer)36 ValueAxis (org.jfree.chart.axis.ValueAxis)35 BarRenderer (org.jfree.chart.renderer.category.BarRenderer)32 CategoryDataset (org.jfree.data.category.CategoryDataset)29 StandardCategoryToolTipGenerator (org.jfree.chart.labels.StandardCategoryToolTipGenerator)27 StandardCategoryURLGenerator (org.jfree.chart.urls.StandardCategoryURLGenerator)24 Paint (java.awt.Paint)23 DefaultBoxAndWhiskerCategoryDataset (org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset)16 LegendItem (org.jfree.chart.LegendItem)15 LineAndShapeRenderer (org.jfree.chart.renderer.category.LineAndShapeRenderer)13 RectangleInsets (org.jfree.ui.RectangleInsets)13 ArrayList (java.util.ArrayList)11 ChartRenderingInfo (org.jfree.chart.ChartRenderingInfo)11 XYPlot (org.jfree.chart.plot.XYPlot)11