Search in sources :

Example 46 with LegendItem

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

the class BoxAndWhiskerRendererTest method testGetLegendItem.

/**
 * Some checks for the getLegendItem() method.
 */
@Test
public void testGetLegendItem() {
    DefaultBoxAndWhiskerCategoryDataset<String, String> dataset = new DefaultBoxAndWhiskerCategoryDataset<>();
    List<Double> values = new ArrayList<>();
    values.add(1.10);
    values.add(1.45);
    values.add(1.33);
    values.add(1.23);
    dataset.add(values, "R1", "C1");
    BoxAndWhiskerRenderer r = new BoxAndWhiskerRenderer();
    CategoryPlot<String, String> plot = new CategoryPlot<>(dataset, new CategoryAxis("x"), new NumberAxis("y"), r);
    /*JFreeChart chart =*/
    new JFreeChart(plot);
    LegendItem li = r.getLegendItem(0, 0);
    assertNotNull(li);
    r.setSeriesVisibleInLegend(0, Boolean.FALSE);
    li = r.getLegendItem(0, 0);
    assertNull(li);
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) ArrayList(java.util.ArrayList) DefaultBoxAndWhiskerCategoryDataset(org.jfree.data.statistics.DefaultBoxAndWhiskerCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) CategoryAxis(org.jfree.chart.axis.CategoryAxis) LegendItem(org.jfree.chart.legend.LegendItem) Test(org.junit.jupiter.api.Test)

Example 47 with LegendItem

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

the class BoxAndWhiskerRendererTest method testGetLegendItemSeriesIndex.

/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset<String, String> dataset0 = new DefaultCategoryDataset<>();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset<String, String> dataset1 = new DefaultCategoryDataset<>();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    BoxAndWhiskerRenderer r = new BoxAndWhiskerRenderer();
    CategoryPlot<String, String> 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());
}
Also used : NumberAxis(org.jfree.chart.axis.NumberAxis) CategoryAxis(org.jfree.chart.axis.CategoryAxis) LegendItem(org.jfree.chart.legend.LegendItem) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) CategoryPlot(org.jfree.chart.plot.CategoryPlot) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.jupiter.api.Test)

Example 48 with LegendItem

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

the class StandardXYItemRendererTest method testGetLegendItemSeriesIndex.

/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection<String> d1 = new XYSeriesCollection<>();
    XYSeries<String> s1 = new XYSeries<>("S1");
    s1.add(1.0, 1.1);
    XYSeries<String> s2 = new XYSeries<>("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);
    XYSeriesCollection<String> d2 = new XYSeriesCollection<>();
    XYSeries<String> s3 = new XYSeries<>("S3");
    s3.add(1.0, 1.1);
    XYSeries<String> s4 = new XYSeries<>("S4");
    s4.add(1.0, 1.1);
    XYSeries<String> s5 = new XYSeries<>("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);
    StandardXYItemRenderer r = new StandardXYItemRenderer();
    XYPlot<String> plot = new XYPlot<>(d1, new NumberAxis("x"), new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    JFreeChart chart = new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) LegendItem(org.jfree.chart.legend.LegendItem) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.jupiter.api.Test)

Example 49 with LegendItem

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

the class XYDotRendererTest method testGetLegendItemSeriesIndex.

/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection<String> d1 = new XYSeriesCollection<>();
    XYSeries<String> s1 = new XYSeries<>("S1");
    s1.add(1.0, 1.1);
    XYSeries<String> s2 = new XYSeries<>("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);
    XYSeriesCollection<String> d2 = new XYSeriesCollection<>();
    XYSeries<String> s3 = new XYSeries<>("S3");
    s3.add(1.0, 1.1);
    XYSeries<String> s4 = new XYSeries<>("S4");
    s4.add(1.0, 1.1);
    XYSeries<String> s5 = new XYSeries<>("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);
    XYDotRenderer r = new XYDotRenderer();
    XYPlot<String> plot = new XYPlot<>(d1, new NumberAxis("x"), new NumberAxis("y"), r);
    plot.setDataset(1, d2);
    /*JFreeChart chart =*/
    new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
Also used : XYSeries(org.jfree.data.xy.XYSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) LegendItem(org.jfree.chart.legend.LegendItem) XYSeriesCollection(org.jfree.data.xy.XYSeriesCollection) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.jupiter.api.Test)

Example 50 with LegendItem

use of org.jfree.chart.legend.LegendItem 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)

Aggregations

LegendItem (org.jfree.chart.legend.LegendItem)58 Test (org.junit.jupiter.api.Test)32 Paint (java.awt.Paint)23 NumberAxis (org.jfree.chart.axis.NumberAxis)20 LegendItemCollection (org.jfree.chart.legend.LegendItemCollection)20 JFreeChart (org.jfree.chart.JFreeChart)19 XYPlot (org.jfree.chart.plot.XYPlot)18 Stroke (java.awt.Stroke)16 Shape (java.awt.Shape)15 CategoryPlot (org.jfree.chart.plot.CategoryPlot)15 XYDataset (org.jfree.data.xy.XYDataset)12 GradientPaint (java.awt.GradientPaint)9 DefaultCategoryDataset (org.jfree.data.category.DefaultCategoryDataset)9 XYSeriesCollection (org.jfree.data.xy.XYSeriesCollection)9 CategoryAxis (org.jfree.chart.axis.CategoryAxis)8 CategoryDataset (org.jfree.data.category.CategoryDataset)8 XYSeries (org.jfree.data.xy.XYSeries)7 BasicStroke (java.awt.BasicStroke)6 Rectangle2D (java.awt.geom.Rectangle2D)6 Line2D (java.awt.geom.Line2D)5