Search in sources :

Example 21 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class PiePlotTest method testGetLegendItems.

/**
 * Some checks for the getLegendItems() method.
 */
@Test
public void testGetLegendItems() {
    DefaultPieDataset<String> 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.legend.LegendItemCollection) AttributedString(java.text.AttributedString) Test(org.junit.jupiter.api.Test)

Example 22 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class SpiderWebPlot method getLegendItems.

/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never {@code null}).
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (getDataset() == null) {
        return result;
    }
    List keys = null;
    if (this.dataExtractOrder == TableOrder.BY_ROW) {
        keys = this.dataset.getRowKeys();
    } else if (this.dataExtractOrder == TableOrder.BY_COLUMN) {
        keys = this.dataset.getColumnKeys();
    }
    if (keys == null) {
        return result;
    }
    int series = 0;
    Iterator iterator = keys.iterator();
    Shape shape = getLegendItemShape();
    while (iterator.hasNext()) {
        Comparable key = (Comparable) iterator.next();
        String label = key.toString();
        String description = label;
        Paint paint = getSeriesPaint(series);
        Paint outlinePaint = getSeriesOutlinePaint(series);
        Stroke stroke = getSeriesOutlineStroke(series);
        LegendItem item = new LegendItem(label, description, null, null, shape, paint, stroke, outlinePaint);
        item.setDataset(getDataset());
        item.setSeriesKey(key);
        item.setSeriesIndex(series);
        result.add(item);
        series++;
    }
    return result;
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) List(java.util.List)

Example 23 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class CombinedDomainXYPlot 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) {
            for (XYPlot plot : this.subplots) {
                LegendItemCollection more = plot.getLegendItems();
                result.addAll(more);
            }
        }
    }
    return result;
}
Also used : LegendItemCollection(org.jfree.chart.legend.LegendItemCollection)

Example 24 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

the class CombinedDomainCategoryPlot 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) {
            for (CategoryPlot plot : this.subplots) {
                LegendItemCollection more = plot.getLegendItems();
                result.addAll(more);
            }
        }
    }
    return result;
}
Also used : LegendItemCollection(org.jfree.chart.legend.LegendItemCollection)

Example 25 with LegendItemCollection

use of org.jfree.chart.legend.LegendItemCollection in project ES-LEI-2Sem-2022-Grupo-1 by tmrbo-iscte.

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) {
            for (XYPlot plot : this.subplots) {
                LegendItemCollection more = plot.getLegendItems();
                result.addAll(more);
            }
        }
    }
    return result;
}
Also used : LegendItemCollection(org.jfree.chart.legend.LegendItemCollection)

Aggregations

LegendItemCollection (org.jfree.chart.legend.LegendItemCollection)29 LegendItem (org.jfree.chart.legend.LegendItem)20 Test (org.junit.jupiter.api.Test)15 Paint (java.awt.Paint)7 BasicStroke (java.awt.BasicStroke)5 GradientPaint (java.awt.GradientPaint)5 Stroke (java.awt.Stroke)4 NumberAxis (org.jfree.chart.axis.NumberAxis)4 Rectangle2D (java.awt.geom.Rectangle2D)3 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)3 List (java.util.List)2 JFreeChart (org.jfree.chart.JFreeChart)2 RectangleInsets (org.jfree.chart.api.RectangleInsets)2 DefaultPolarItemRenderer (org.jfree.chart.renderer.DefaultPolarItemRenderer)2 DefaultXYItemRenderer (org.jfree.chart.renderer.xy.DefaultXYItemRenderer)2 StandardXYItemRenderer (org.jfree.chart.renderer.xy.StandardXYItemRenderer)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 DefaultShadowGenerator (org.jfree.chart.util.DefaultShadowGenerator)2 XYDataset (org.jfree.data.xy.XYDataset)2 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)2