Search in sources :

Example 6 with LegendItemCollection

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

the class XYPlot method getLegendItems.

/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's renderer, since the renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    for (XYDataset<S> dataset : this.datasets.values()) {
        if (dataset == null) {
            continue;
        }
        int datasetIndex = indexOf(dataset);
        XYItemRenderer renderer = getRenderer(datasetIndex);
        if (renderer == null) {
            renderer = getRenderer(0);
        }
        if (renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                if (renderer.isSeriesVisible(i) && renderer.isSeriesVisibleInLegend(i)) {
                    LegendItem item = renderer.getLegendItem(datasetIndex, i);
                    if (item != null) {
                        result.add(item);
                    }
                }
            }
        }
    }
    return result;
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) AbstractXYItemRenderer(org.jfree.chart.renderer.xy.AbstractXYItemRenderer) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer)

Example 7 with LegendItemCollection

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

the class PolarPlot method getLegendItems.

/**
 * Returns the legend items for the plot.  Each legend item is generated by
 * the plot's m_Renderer, since the m_Renderer is responsible for the visual
 * representation of the data.
 *
 * @return The legend items.
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.fixedLegendItems != null) {
        return this.fixedLegendItems;
    }
    LegendItemCollection result = new LegendItemCollection();
    int count = this.datasets.size();
    for (int datasetIndex = 0; datasetIndex < count; datasetIndex++) {
        XYDataset dataset = getDataset(datasetIndex);
        PolarItemRenderer renderer = getRenderer(datasetIndex);
        if (dataset != null && renderer != null) {
            int seriesCount = dataset.getSeriesCount();
            for (int i = 0; i < seriesCount; i++) {
                LegendItem item = renderer.getLegendItem(i);
                result.add(item);
            }
        }
    }
    return result;
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) XYDataset(org.jfree.data.xy.XYDataset) PolarItemRenderer(org.jfree.chart.renderer.PolarItemRenderer) Point(java.awt.Point) Paint(java.awt.Paint)

Example 8 with LegendItemCollection

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

the class AbstractCategoryItemRenderer method getLegendItems.

/**
 * Returns a (possibly empty) collection of legend items for the series
 * that this renderer is responsible for drawing.
 *
 * @return The legend item collection (never {@code null}).
 *
 * @see #getLegendItem(int, int)
 */
@Override
public LegendItemCollection getLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    if (this.plot == null) {
        return result;
    }
    int index = this.plot.getIndexOf(this);
    CategoryDataset dataset = this.plot.getDataset(index);
    if (dataset == null) {
        return result;
    }
    int seriesCount = dataset.getRowCount();
    if (plot.getRowRenderingOrder().equals(SortOrder.ASCENDING)) {
        for (int i = 0; i < seriesCount; i++) {
            if (isSeriesVisibleInLegend(i)) {
                LegendItem item = getLegendItem(index, i);
                if (item != null) {
                    result.add(item);
                }
            }
        }
    } else {
        for (int i = seriesCount - 1; i >= 0; i--) {
            if (isSeriesVisibleInLegend(i)) {
                LegendItem item = getLegendItem(index, i);
                if (item != null) {
                    result.add(item);
                }
            }
        }
    }
    return result;
}
Also used : LegendItem(org.jfree.chart.legend.LegendItem) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) CategoryDataset(org.jfree.data.category.CategoryDataset) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Example 9 with LegendItemCollection

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

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

Example 10 with LegendItemCollection

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

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<R, C> 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 : CategoryItemRenderer(org.jfree.chart.renderer.category.CategoryItemRenderer) LegendItemCollection(org.jfree.chart.legend.LegendItemCollection) Paint(java.awt.Paint)

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