Search in sources :

Example 1 with LegendItem

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

the class XYDifferenceRendererTest 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);
    XYDifferenceRenderer r = new XYDifferenceRenderer();
    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 2 with LegendItem

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

the class YIntervalRendererTest method testGetLegendItemSeriesIndex.

/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    YIntervalSeriesCollection<String> d1 = new YIntervalSeriesCollection<>();
    YIntervalSeries<String> s1 = new YIntervalSeries<>("S1");
    s1.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeries<String> s2 = new YIntervalSeries<>("S2");
    s2.add(1.0, 1.1, 1.2, 1.3);
    d1.addSeries(s1);
    d1.addSeries(s2);
    YIntervalSeriesCollection<String> d2 = new YIntervalSeriesCollection<>();
    YIntervalSeries<String> s3 = new YIntervalSeries<>("S3");
    s3.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeries<String> s4 = new YIntervalSeries<>("S4");
    s4.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeries<String> s5 = new YIntervalSeries<>("S5");
    s5.add(1.0, 1.1, 1.2, 1.3);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);
    YIntervalRenderer r = new YIntervalRenderer();
    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 : YIntervalSeriesCollection(org.jfree.data.xy.YIntervalSeriesCollection) YIntervalSeries(org.jfree.data.xy.YIntervalSeries) NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) LegendItem(org.jfree.chart.legend.LegendItem) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.jupiter.api.Test)

Example 3 with LegendItem

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

the class XYAreaRendererTest 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);
    XYAreaRenderer r = new XYAreaRenderer();
    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 4 with LegendItem

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

the class XYLineAndShapeRendererTest 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);
    XYLineAndShapeRenderer r = new XYLineAndShapeRenderer();
    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 5 with LegendItem

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

the class XYBubbleRendererTest method testGetLegendItemSeriesIndex.

/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultXYZDataset<String> d1 = new DefaultXYZDataset<>();
    double[] x = { 2.1, 2.3, 2.3, 2.2, 2.2, 1.8, 1.8, 1.9, 2.3, 3.8 };
    double[] y = { 14.1, 11.1, 10.0, 8.8, 8.7, 8.4, 5.4, 4.1, 4.1, 25 };
    double[] z = { 2.4, 2.7, 2.7, 2.2, 2.2, 2.2, 2.1, 2.2, 1.6, 4 };
    double[][] s1 = new double[][] { x, y, z };
    d1.addSeries("S1", s1);
    x = new double[] { 2.1 };
    y = new double[] { 14.1 };
    z = new double[] { 2.4 };
    double[][] s2 = new double[][] { x, y, z };
    d1.addSeries("S2", s2);
    DefaultXYZDataset<String> d2 = new DefaultXYZDataset<>();
    x = new double[] { 2.1 };
    y = new double[] { 14.1 };
    z = new double[] { 2.4 };
    double[][] s3 = new double[][] { x, y, z };
    d2.addSeries("S3", s3);
    x = new double[] { 2.1 };
    y = new double[] { 14.1 };
    z = new double[] { 2.4 };
    double[][] s4 = new double[][] { x, y, z };
    d2.addSeries("S4", s4);
    x = new double[] { 2.1 };
    y = new double[] { 14.1 };
    z = new double[] { 2.4 };
    double[][] s5 = new double[][] { x, y, z };
    d2.addSeries("S5", s5);
    XYBubbleRenderer r = new XYBubbleRenderer();
    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 : NumberAxis(org.jfree.chart.axis.NumberAxis) XYPlot(org.jfree.chart.plot.XYPlot) LegendItem(org.jfree.chart.legend.LegendItem) DefaultXYZDataset(org.jfree.data.xy.DefaultXYZDataset) JFreeChart(org.jfree.chart.JFreeChart) Test(org.junit.jupiter.api.Test)

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