org.jfree.chart.LegendItem Java Examples

The following examples show how to use org.jfree.chart.LegendItem. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LevelRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    LevelRenderer r = new LevelRenderer();
    CategoryPlot 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());
}
 
Example #2
Source File: XYPlotTest.java    From openstock with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #3
Source File: BoxAndWhiskerRendererTests.java    From astor with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");        
    DefaultCategoryDataset 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 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());
}
 
Example #4
Source File: AbstractXYItemRenderer.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.plot == null) {
        return new LegendItemCollection();
    }
    LegendItemCollection result = new LegendItemCollection();
    int index = this.plot.getIndexOf(this);
    XYDataset dataset = this.plot.getDataset(index);
    if (dataset != null) {
        int seriesCount = dataset.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            if (isSeriesVisibleInLegend(i)) {
                LegendItem item = getLegendItem(index, i);
                if (item != null) {
                    result.add(item);
                }
            }
        }

    }
    return result;
}
 
Example #5
Source File: AbstractXYItemRenderer.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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</code>).
 */
@Override
public LegendItemCollection getLegendItems() {
    if (this.plot == null) {
        return new LegendItemCollection();
    }
    LegendItemCollection result = new LegendItemCollection();
    int index = this.plot.getIndexOf(this);
    XYDataset dataset = this.plot.getDataset(index);
    if (dataset != null) {
        int seriesCount = dataset.getSeriesCount();
        for (int i = 0; i < seriesCount; i++) {
            if (isSeriesVisibleInLegend(i)) {
                LegendItem item = getLegendItem(index, i);
                if (item != null) {
                    result.add(item);
                }
            }
        }

    }
    return result;
}
 
Example #6
Source File: TargetCharts.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public LegendItemCollection createThresholdLegend(Plot plot){
	logger.debug("IN");

	LegendItemCollection collection=new LegendItemCollection();

	for (Iterator iterator = thresholds.keySet().iterator(); iterator.hasNext();) {
		Double thres = (Double) iterator.next();
		TargetThreshold thresTarg=thresholds.get(thres);
		String thresholdName= thresTarg!=null ? thresTarg.getName() : "";

		Color color=Color.BLACK;

		if(thresTarg.getColor()!=null){
			color=thresTarg.getColor();		
		}
		// could add bottom only if used
		LegendItem item=new LegendItem(thresholdName, thresholdName, thresholdName,thresholdName, new Rectangle(10,10),color);
		collection.add(item);
	}
	logger.debug("OUT");
	return collection;
}
 
Example #7
Source File: GanttPanel.java    From openvisualtraceroute with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Update legend
 */
private void updateLegend() {
	_chart.removeLegend();
	final LegendTitle legend = new LegendTitle(() -> {
		final LegendItemCollection collection = new LegendItemCollection();
		if (_currentMode == DisplayMode.TIME) {
			collection.add(new LegendItem(Legend.LATENCY.label, null, null, null, new Rectangle(30, 20), Legend.LATENCY.color));
			if (_dnsLookup && _services.isEmbeddedTRAvailable() && !Env.INSTANCE.isUseOSTraceroute()) {
				collection.add(new LegendItem(Legend.DNS.label, null, null, null, new Rectangle(30, 20), Legend.DNS.color));
			}
		} else {
			collection.add(new LegendItem(Legend.DISTANCE.label, Legend.DISTANCE.color));
		}
		return collection;
	});
	legend.setPosition(RectangleEdge.BOTTOM);
	_chart.addLegend(legend);
}
 
Example #8
Source File: AreaRendererTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    AreaRenderer r = new AreaRenderer();
    CategoryPlot 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());
}
 
Example #9
Source File: BoxAndWhiskerRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset 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 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());
}
 
Example #10
Source File: BarRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    BarRenderer r = new BarRenderer();
    CategoryPlot 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());
}
 
Example #11
Source File: AreaRendererTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    AreaRenderer r = new AreaRenderer();
    CategoryPlot 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());
}
 
Example #12
Source File: SpiderWebPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Fetches the legend items and checks the values.
 */
@Test
public void testGetLegendItems() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(35.0, "S1", "C1");
    dataset.addValue(45.0, "S1", "C2");
    dataset.addValue(55.0, "S2", "C1");
    dataset.addValue(15.0, "S2", "C2");
    SpiderWebPlot plot = new SpiderWebPlot(dataset);
    JFreeChart chart = new JFreeChart(plot);
    LegendItemCollection legendItems = plot.getLegendItems();
    assertEquals(2, legendItems.getItemCount());
    LegendItem item1 = legendItems.get(0);
    assertEquals("S1", item1.getLabel());
    assertEquals("S1", item1.getSeriesKey());
    assertEquals(0, item1.getSeriesIndex());
    assertEquals(dataset, item1.getDataset());
    assertEquals(0, item1.getDatasetIndex());

    LegendItem item2 = legendItems.get(1);
    assertEquals("S2", item2.getLabel());
    assertEquals("S2", item2.getSeriesKey());
    assertEquals(1, item2.getSeriesIndex());
    assertEquals(dataset, item2.getDataset());
    assertEquals(0, item2.getDatasetIndex());
}
 
Example #13
Source File: CategoryStepRendererTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    CategoryStepRenderer r = new CategoryStepRenderer();
    CategoryPlot 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());
}
 
Example #14
Source File: CategoryStepRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    CategoryStepRenderer r = new CategoryStepRenderer();
    CategoryPlot 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());
}
 
Example #15
Source File: PolarPlot.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source File: LevelRendererTest.java    From ccu-historian with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    DefaultCategoryDataset dataset0 = new DefaultCategoryDataset();
    dataset0.addValue(21.0, "R1", "C1");
    dataset0.addValue(22.0, "R2", "C1");
    DefaultCategoryDataset dataset1 = new DefaultCategoryDataset();
    dataset1.addValue(23.0, "R3", "C1");
    dataset1.addValue(24.0, "R4", "C1");
    dataset1.addValue(25.0, "R5", "C1");
    LevelRenderer r = new LevelRenderer();
    CategoryPlot 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());
}
 
Example #17
Source File: MultiplePiePlotTest.java    From SIMVA-SoS with Apache License 2.0 6 votes vote down vote up
/**
 * Fetches the legend items and checks the values.
 */
@Test
public void testGetLegendItems() {
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(35.0, "S1", "C1");
    dataset.addValue(45.0, "S1", "C2");
    dataset.addValue(55.0, "S2", "C1");
    dataset.addValue(15.0, "S2", "C2");
    MultiplePiePlot plot = new MultiplePiePlot(dataset);
    JFreeChart chart = new JFreeChart(plot);
    LegendItemCollection legendItems = plot.getLegendItems();
    assertEquals(2, legendItems.getItemCount());
    LegendItem item1 = legendItems.get(0);
    assertEquals("S1", item1.getLabel());
    assertEquals("S1", item1.getSeriesKey());
    assertEquals(0, item1.getSeriesIndex());
    assertEquals(dataset, item1.getDataset());
    assertEquals(0, item1.getDatasetIndex());

    LegendItem item2 = legendItems.get(1);
    assertEquals("S2", item2.getLabel());
    assertEquals("S2", item2.getSeriesKey());
    assertEquals(1, item2.getSeriesIndex());
    assertEquals(dataset, item2.getDataset());
    assertEquals(0, item2.getDatasetIndex());
}
 
Example #18
Source File: XYPlotTest.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * 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));
}
 
Example #19
Source File: Cardumen_009_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * 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.
 */
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);
        if (dataset != null) {
            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;
}
 
Example #20
Source File: XYLineAndShapeRendererTests.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);
    
    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYLineAndShapeRenderer r = new XYLineAndShapeRenderer();
    XYPlot 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());
}
 
Example #21
Source File: BarRenderer.java    From opensim-gui with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot cp = getPlot();
    if (cp == null) {
        return null;
    }

    CategoryDataset dataset;
    dataset = cp.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, 
            series);
    String description = label;
    String toolTipText = null; 
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);   
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset, 
                series);   
    }
    Shape shape = new Rectangle2D.Double(-4.0, -4.0, 8.0, 8.0);
    Paint paint = getSeriesPaint(series);
    Paint outlinePaint = getSeriesOutlinePaint(series);
    Stroke outlineStroke = getSeriesOutlineStroke(series);

    LegendItem result = new LegendItem(label, description, toolTipText, 
            urlText, true, shape, true, paint, isDrawBarOutline(), 
            outlinePaint, outlineStroke, false, new Line2D.Float(), 
            new BasicStroke(1.0f), Color.black);
    if (this.gradientPaintTransformer != null) {
        result.setFillPaintTransformer(this.gradientPaintTransformer);
    }
    return result;
}
 
Example #22
Source File: CategoryStepRenderer.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a legend item for a series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return The legend item.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {

    CategoryPlot p = getPlot();
    if (p == null) {
        return null;
    }

    // check that a legend item needs to be displayed...
    if (!isSeriesVisible(series) || !isSeriesVisibleInLegend(series)) {
        return null;
    }

    CategoryDataset dataset = p.getDataset(datasetIndex);
    String label = getLegendItemLabelGenerator().generateLabel(dataset, 
            series);
    String description = label;
    String toolTipText = null; 
    if (getLegendItemToolTipGenerator() != null) {
        toolTipText = getLegendItemToolTipGenerator().generateLabel(
                dataset, series);   
    }
    String urlText = null;
    if (getLegendItemURLGenerator() != null) {
        urlText = getLegendItemURLGenerator().generateLabel(dataset, 
                series);   
    }
    Shape shape = new Rectangle2D.Double(-4.0, -3.0, 8.0, 6.0);
    Paint paint = lookupSeriesPaint(series);
 
    LegendItem item = new LegendItem(label, description, toolTipText, 
            urlText, shape, paint);
    item.setSeriesKey(dataset.getRowKey(series));
    item.setSeriesIndex(series);
    item.setDataset(dataset);
    item.setDatasetIndex(datasetIndex);
    return item;
}
 
Example #23
Source File: XYDifferenceRendererTest.java    From openstock with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYDifferenceRenderer r = new XYDifferenceRenderer();
    XYPlot 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());
}
 
Example #24
Source File: YIntervalRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    YIntervalSeriesCollection d1 = new YIntervalSeriesCollection();
    YIntervalSeries s1 = new YIntervalSeries("S1");
    s1.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeries s2 = new YIntervalSeries("S2");
    s2.add(1.0, 1.1, 1.2, 1.3);
    d1.addSeries(s1);
    d1.addSeries(s2);

    YIntervalSeriesCollection d2 = new YIntervalSeriesCollection();
    YIntervalSeries s3 = new YIntervalSeries("S3");
    s3.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeries s4 = new YIntervalSeries("S4");
    s4.add(1.0, 1.1, 1.2, 1.3);
    YIntervalSeries 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 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());
}
 
Example #25
Source File: SpiderWebPlot.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a collection of legend items for the spider web chart.
 *
 * @return The legend items (never <code>null</code>).
 */
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;
}
 
Example #26
Source File: XYDifferenceRendererTest.java    From ccu-historian with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYDifferenceRenderer r = new XYDifferenceRenderer();
    XYPlot 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());
}
 
Example #27
Source File: XYBarRendererTest.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYBarRenderer r = new XYBarRenderer();
    XYPlot plot = new XYPlot(new XYBarDataset(d1, 1.0), new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, new XYBarDataset(d2, 2.0));
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example #28
Source File: XYDotRendererTest.java    From SIMVA-SoS with Apache License 2.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYDotRenderer r = new XYDotRenderer();
    XYPlot 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());
}
 
Example #29
Source File: XYBarRendererTest.java    From ECG-Viewer with GNU General Public License v2.0 5 votes vote down vote up
/**
 * A check for the datasetIndex and seriesIndex fields in the LegendItem
 * returned by the getLegendItem() method.
 */
@Test
public void testGetLegendItemSeriesIndex() {
    XYSeriesCollection d1 = new XYSeriesCollection();
    XYSeries s1 = new XYSeries("S1");
    s1.add(1.0, 1.1);
    XYSeries s2 = new XYSeries("S2");
    s2.add(1.0, 1.1);
    d1.addSeries(s1);
    d1.addSeries(s2);

    XYSeriesCollection d2 = new XYSeriesCollection();
    XYSeries s3 = new XYSeries("S3");
    s3.add(1.0, 1.1);
    XYSeries s4 = new XYSeries("S4");
    s4.add(1.0, 1.1);
    XYSeries s5 = new XYSeries("S5");
    s5.add(1.0, 1.1);
    d2.addSeries(s3);
    d2.addSeries(s4);
    d2.addSeries(s5);

    XYBarRenderer r = new XYBarRenderer();
    XYPlot plot = new XYPlot(new XYBarDataset(d1, 1.0), new NumberAxis("x"),
            new NumberAxis("y"), r);
    plot.setDataset(1, new XYBarDataset(d2, 2.0));
    /*JFreeChart chart =*/ new JFreeChart(plot);
    LegendItem li = r.getLegendItem(1, 2);
    assertEquals("S5", li.getLabel());
    assertEquals(1, li.getDatasetIndex());
    assertEquals(2, li.getSeriesIndex());
}
 
Example #30
Source File: XYPlot.java    From buffer_bci with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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 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;
}