Search in sources :

Example 6 with LegendItemCollection

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

the class CombinedRangeXYPlot method getLegendItems.

/**
 * Returns a collection of legend items for the plot.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = getFixedLegendItems();
    if (result == null) {
        result = new LegendItemCollection();
        if (this.subplots != null) {
            Iterator iterator = this.subplots.iterator();
            while (iterator.hasNext()) {
                XYPlot plot = (XYPlot) iterator.next();
                LegendItemCollection more = plot.getLegendItems();
                result.addAll(more);
            }
        }
    }
    return result;
}
Also used : LegendItemCollection(org.jfree.chart.LegendItemCollection) Iterator(java.util.Iterator)

Example 7 with LegendItemCollection

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

the class PiePlotTest method testGetLegendItems.

/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    DefaultPieDataset dataset = new DefaultPieDataset();
    dataset.setValue("Item 1", 1.0);
    dataset.setValue("Item 2", 2.0);
    dataset.setValue("Item 3", 0.0);
    dataset.setValue("Item 4", null);
    PiePlot plot = new PiePlot(dataset);
    plot.setIgnoreNullValues(false);
    plot.setIgnoreZeroValues(false);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(4, items.getItemCount());
    // check that null items are ignored if requested
    plot.setIgnoreNullValues(true);
    items = plot.getLegendItems();
    assertEquals(3, items.getItemCount());
    // check that zero items are ignored if requested
    plot.setIgnoreZeroValues(true);
    items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
    // check that negative items are always ignored
    dataset.setValue("Item 5", -1.0);
    items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
}
Also used : DefaultPieDataset(org.jfree.data.general.DefaultPieDataset) LegendItemCollection(org.jfree.chart.LegendItemCollection) Test(org.junit.Test)

Example 8 with LegendItemCollection

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

the class PolarPlotTest method testGetLegendItems.

/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    XYSeriesCollection d = new XYSeriesCollection();
    d.addSeries(new XYSeries("A"));
    d.addSeries(new XYSeries("B"));
    DefaultPolarItemRenderer r = new DefaultPolarItemRenderer();
    PolarPlot plot = new PolarPlot();
    plot.setDataset(d);
    plot.setRenderer(r);
    LegendItemCollection items = plot.getLegendItems();
    assertEquals(2, items.getItemCount());
    LegendItem item1 = items.get(0);
    assertEquals("A", item1.getLabel());
    LegendItem item2 = items.get(1);
    assertEquals("B", item2.getLabel());
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) LegendItem(org.jfree.chart.LegendItem) LegendItemCollection(org.jfree.chart.LegendItemCollection) DefaultPolarItemRenderer(org.jfree.chart.renderer.DefaultPolarItemRenderer) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) Test(org.junit.Test)

Example 9 with LegendItemCollection

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

the class XYPlotTest method testCloning3.

/**
 * 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));
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) LegendItem(org.jfree.chart.LegendItem) StandardXYItemRenderer(org.jfree.chart.renderer.xy.StandardXYItemRenderer) LegendItemCollection(org.jfree.chart.LegendItemCollection) Test(org.junit.Test)

Example 10 with LegendItemCollection

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

the class CategoryPlot method getLegendItems.

/**
 * Returns the legend items for the plot.  By default, this method creates
 * a legend item for each series in each of the datasets.  You can change
 * this behaviour by overriding this method.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    // get the legend items for the datasets...
    for (CategoryDataset dataset : this.datasets.values()) {
        if (dataset != null) {
            int datasetIndex = indexOf(dataset);
            CategoryItemRenderer renderer = getRenderer(datasetIndex);
            if (renderer != null) {
                result.addAll(renderer.getLegendItems());
            }
        }
    }
    return result;
}
Also used : AbstractCategoryItemRenderer(org.jfree.chart.renderer.category.AbstractCategoryItemRenderer) CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) LegendItemCollection(org.jfree.chart.LegendItemCollection) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint)

Aggregations

LegendItemCollection (org.jfree.chart.LegendItemCollection)30 LegendItem (org.jfree.chart.LegendItem)19 Paint (java.awt.Paint)12 Test (org.junit.Test)12 Iterator (java.util.Iterator)9 BasicStroke (java.awt.BasicStroke)6 Stroke (java.awt.Stroke)6 GradientPaint (java.awt.GradientPaint)5 NumberAxis (org.jfree.chart.axis.NumberAxis)5 List (java.util.List)4 XYDataset (org.jfree.data.xy.XYDataset)4 Shape (java.awt.Shape)3 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)3 Color (java.awt.Color)2 Font (java.awt.Font)2 HashSet (java.util.HashSet)2 JFreeChart (org.jfree.chart.JFreeChart)2 DefaultPolarItemRenderer (org.jfree.chart.renderer.DefaultPolarItemRenderer)2 DefaultXYItemRenderer (org.jfree.chart.renderer.xy.DefaultXYItemRenderer)2 LegendTitle (org.jfree.chart.title.LegendTitle)2