Example usage for org.jfree.chart LegendItemCollection get

List of usage examples for org.jfree.chart LegendItemCollection get

Introduction

In this page you can find the example usage for org.jfree.chart LegendItemCollection get.

Prototype

public LegendItem get(int index) 

Source Link

Document

Returns a legend item from the collection.

Usage

From source file:gov.nih.nci.caintegrator.ui.graphing.legend.LegendCreator.java

/**
 * creates and HTML legend and returns a string of HTML
 * @param lic - a jFreechart LegendItemCollection
 * @return//from  ww  w  . j  a  v  a2  s . c  o  m
 */
public static String buildLegend(LegendItemCollection lic, String legendTitle) {

    //TODO: take annotation link as a string param

    String html = new String();
    Color p = null;
    html = "<fieldset style='display:table;width:600; border:1px solid gray; text-align:left; padding:5px;'>";
    html += "<legend>Legend: " + legendTitle + "</legend>";

    for (int i = 0; i < lic.getItemCount(); i++) {
        p = (Color) lic.get(i).getFillPaint();
        //html += "<div style='margin:10px; padding:10px;border:1px solid red;'><label style='width:30px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;'>&nbsp;&nbsp;&nbsp;</label><b style='color: "+ c2hex(p)+"'>"+lic.get(i).getLabel()+"</b></div>\n";   
        html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "
                + c2hex(p)
                + "; border:1px solid black;\">&nbsp;&nbsp;&nbsp;</td><td><a style=\"text-decoration:none\" href=\"javascript:alert(\'some annotation for:"
                + lic.get(i).getLabel() + "\');\"><b style=\"color: " + c2hex(p) + "\">" + lic.get(i).getLabel()
                + "</b></a></td></tr></table>";
    }
    html += "</fieldset>";

    String js = "";
    //js = "<script language=\"javascript\">document.getElementById('legend').innerHTML = \""+ html +" \"; </script>";
    return html;
}

From source file:gov.nih.nci.cma.web.graphing.LegendCreator.java

/**
 * creates and HTML legend and returns a string of HTML
 * @param lic - a jFreechart LegendItemCollection
 * @return//from   w  w w .j  a va 2s  .  c om
 */
public static String buildLegend(LegendItemCollection lic, String legendTitle) {

    //TODO: take annotation link as a string param

    String html = new String();
    Color p = null;
    //html = "<fieldset style='display:table;width:600; border:1px solid gray; text-align:left; padding:5px;'>";
    //html += "<legend>Legend: "+ legendTitle+"</legend>";

    for (int i = 0; i < lic.getItemCount(); i++) {
        p = (Color) lic.get(i).getFillPaint();
        //html += "<div style='margin:10px; padding:10px;border:1px solid red;'><label style='width:30px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;'>&nbsp;&nbsp;&nbsp;</label><b style='color: "+ c2hex(p)+"'>"+lic.get(i).getLabel()+"</b></div>\n";
        html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "
                + c2hex(p)
                + "; border:1px solid black;\">&nbsp;&nbsp;&nbsp;</td><td><a style=\"text-decoration:none\" "
                + "href=\"javascript:spawnAnnot('" + lic.get(i).getLabel() + "\');\"><b style=\"color: "
                + c2hex(p) + "\">" + lic.get(i).getLabel() + "</b></a></td></tr></table>";

        //html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;\">&nbsp;&nbsp;&nbsp;</td><td><a style=\"text-decoration:none\" href=\"javascript:alert(\'some annotation for:"+lic.get(i).getLabel()+"\');\"><b style=\"color: "+ c2hex(p)+"\">"+lic.get(i).getLabel()+"</b></a></td></tr></table>";
    }
    //html += "</fieldset>";
    //System.out.println(html);
    String js = "";
    //js = "<script language=\"javascript\">document.getElementById('legend').innerHTML = \""+ html +" \"; </script>";
    return html;
}

From source file:gov.nih.nci.cma.web.graphing.LegendCreator.java

/**
 * creates and HTML legend and returns a string of HTML
 * @param lic - a jFreechart LegendItemCollection
 * @return/*  w w  w  . jav  a2  s.  co m*/
 */
public static String buildSmartLegend(String chipType, LegendItemCollection lic, String legendTitle) {

    //TODO: take annotation link as a string param

    String html = new String();
    Color p = null;
    //html = "<fieldset style='display:table;width:600; border:1px solid gray; text-align:left; padding:5px;'>";
    //html += "<legend>Legend: "+ legendTitle+"</legend>";

    for (int i = 0; i < lic.getItemCount(); i++) {
        p = (Color) lic.get(i).getFillPaint();
        //html += "<div style='margin:10px; padding:10px;border:1px solid red;'><label style='width:30px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;'>&nbsp;&nbsp;&nbsp;</label><b style='color: "+ c2hex(p)+"'>"+lic.get(i).getLabel()+"</b></div>\n";

        // JB: GF [#21548] Issue for annotation query in GeneView
        // The LPG application that these probeset links redirect the user to, only support the HG-133 Chip.
        // So, when non-HG133 chips were selected for the GeneView search, those links probeset
        // links are NOT hyperlinked to the LPG site.
        if (chipType.equals("AFFY_HT_HG-U133A") || chipType.equals("AFFY_HGU133P2")) {
            html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "
                    + c2hex(p)
                    + "; border:1px solid black;\">&nbsp;&nbsp;&nbsp;</td><td><a style=\"text-decoration:none\" "
                    + "href=\"javascript:spawnAnnot('" + lic.get(i).getLabel() + "\');\"><b style=\"color: "
                    + c2hex(p) + "\">" + lic.get(i).getLabel() + "</b></a></td></tr></table>";
        } else {
            html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "
                    + c2hex(p) + "; border:1px solid black;\">&nbsp;&nbsp;&nbsp;</td><td><b style=\"color: "
                    + c2hex(p) + "\">" + lic.get(i).getLabel() + "</b></td></tr></table>";
        }
        //html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;\">&nbsp;&nbsp;&nbsp;</td><td><a style=\"text-decoration:none\" href=\"javascript:alert(\'some annotation for:"+lic.get(i).getLabel()+"\');\"><b style=\"color: "+ c2hex(p)+"\">"+lic.get(i).getLabel()+"</b></a></td></tr></table>";
    }
    //html += "</fieldset>";
    //System.out.println(html);
    String js = "";
    //js = "<script language=\"javascript\">document.getElementById('legend').innerHTML = \""+ html +" \"; </script>";
    return html;
}

From source file:gov.nih.nci.rembrandt.web.legend.LegendCreator.java

/**
 * creates and HTML legend and returns a string of HTML
 * @param lic - a jFreechart LegendItemCollection
 * @return//from   www  . j a va 2 s.  c  o m
 */
public static String buildLegend(LegendItemCollection lic, String legendTitle) {

    //TODO: take annotation link as a string param

    String html = new String();
    Color p = null;
    html = "<fieldset style='display:table;width:600; border:1px solid gray; text-align:left; padding:5px;'>";
    html += "<legend>Legend: " + legendTitle + "</legend>";

    for (int i = 0; i < lic.getItemCount(); i++) {
        p = (Color) lic.get(i).getFillPaint();
        //html += "<div style='margin:10px; padding:10px;border:1px solid red;'><label style='width:30px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;'>&nbsp;&nbsp;&nbsp;</label><b style='color: "+ c2hex(p)+"'>"+lic.get(i).getLabel()+"</b></div>\n";   
        html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "
                + c2hex(p)
                + "; border:1px solid black;\">&nbsp;&nbsp;&nbsp;</td><td><a style=\"text-decoration:none\" href=\"javascript:spawnAnnot('reporterFromGeneQS', '"
                + lic.get(i).getLabel() + "\');\"><b style=\"color: " + c2hex(p) + "\">" + lic.get(i).getLabel()
                + "</b></a></td></tr></table>";

        //html += "<table style=\"display:inline;\"><tr><td style=\"width:10px; height:10px; background-color: "+ c2hex(p)+"; border:1px solid black;\">&nbsp;&nbsp;&nbsp;</td><td><a style=\"text-decoration:none\" href=\"javascript:alert(\'some annotation for:"+lic.get(i).getLabel()+"\');\"><b style=\"color: "+ c2hex(p)+"\">"+lic.get(i).getLabel()+"</b></a></td></tr></table>";
    }
    html += "</fieldset>";

    String js = "";
    //js = "<script language=\"javascript\">document.getElementById('legend').innerHTML = \""+ html +" \"; </script>";
    return html;
}

From source file:org.talend.dataprofiler.chart.ChartDecorator.java

/**
 * //from  w  w w  . j a v  a2 s . c om
 * if it contians CJK, set Font to "Arial Unicode MS".Or else, the Font is "Tahoma".
 * 
 * @param chart
 */
private static void setLegendFont(JFreeChart chart) {
    Font font;
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        font = new Font("Tahoma", Font.PLAIN, BASE_LEGEND_LABEL_SIZE);//$NON-NLS-1$
        // get legend label to judge if it contains CJK.
        LegendItemSource[] sources = legend.getSources();
        Set<String> itemLabels = new HashSet<String>();
        for (LegendItemSource source : sources) {
            LegendItemCollection legendItems = source.getLegendItems();
            for (int i = 0; i < legendItems.getItemCount(); i++) {
                String label = legendItems.get(i).getLabel();
                if (label != null) {
                    itemLabels.add(label);
                }
            }
        }
        if (isContainCJKCharacter(itemLabels.toArray())) {
            font = getCJKFont(Font.PLAIN, BASE_LEGEND_LABEL_SIZE);
        }
        legend.setItemFont(font);
    }
}

From source file:net.sf.dynamicreports.test.jasper.chart.GroupedStackedBarChartData2Test.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/*from   ww  w  .  j a v  a2 s . co m*/

    String[] categories = new String[] { "value1" };
    String[] series = new String[] {
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series3",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series4" };
    Number[][] values = new Number[][] { { 1d, 2d, 3d } };
    chartCountTest("groupFooter.chart1", 2);
    chartCategoryCountTest("groupFooter.chart1", 0, 1);
    chartSeriesCountTest("groupFooter.chart1", 0, 3);
    chartDataTest("groupFooter.chart1", 0, categories, series, values);
    JFreeChart chart = getChart("groupFooter.chart1", 0);
    LegendItemCollection fixedLegendItems = chart.getCategoryPlot().getFixedLegendItems();
    Assert.assertEquals("series name", "series1", fixedLegendItems.get(0).getLabel());
    Assert.assertEquals("series name", "series3", fixedLegendItems.get(1).getLabel());
    Assert.assertEquals("series name", "series4", fixedLegendItems.get(2).getLabel());

    series = new String[] { "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series2",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series3",
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series4" };
    values = new Number[][] { { 4d, 5d, 6d, 7d } };
    chartCategoryCountTest("groupFooter.chart1", 1, 1);
    chartSeriesCountTest("groupFooter.chart1", 1, 4);
    chartDataTest("groupFooter.chart1", 1, categories, series, values);
    chart = getChart("groupFooter.chart1", 1);
    fixedLegendItems = chart.getCategoryPlot().getFixedLegendItems();
    Assert.assertEquals("series name", "series1", fixedLegendItems.get(0).getLabel());
    Assert.assertEquals("series name", "series2", fixedLegendItems.get(1).getLabel());
    Assert.assertEquals("series name", "series3", fixedLegendItems.get(2).getLabel());
    Assert.assertEquals("series name", "series4", fixedLegendItems.get(3).getLabel());
}

From source file:edu.emory.library.tast.database.graphs.GraphTypeXY.java

public JFreeChart createChart(Object[] data) {

    CategoryTableXYDataset dataset = new CategoryTableXYDataset();

    JFreeChart chart = ChartFactory.createXYLineChart(null, getSelectedIndependentVariable().getLabel(),
            TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true,
            false);/* w  ww  .j a  v  a  2  s.  c  o  m*/

    Format formatter = getSelectedIndependentVariable().getFormat();

    XYPlot plot = chart.getXYPlot();
    if (formatter != null)
        ((NumberAxis) plot.getDomainAxis()).setNumberFormatOverride((NumberFormat) formatter);

    chart.setBackgroundPaint(Color.white);

    List allDataSeries = getDataSeries();
    for (int j = 0; j < allDataSeries.size(); j++) {
        DataSeries dataSearies = (DataSeries) allDataSeries.get(j);
        String dataSeriesLabel = dataSearies.formatForDisplay();
        for (int i = 0; i < data.length; i++) {
            Object[] row = (Object[]) data[i];
            Number x = (Number) row[0];
            Number y = (Number) row[j + 1];
            if (x != null && y != null)
                dataset.add(x.doubleValue(), y.doubleValue(), dataSeriesLabel);
        }
    }

    LegendItemCollection legendItems = chart.getPlot().getLegendItems();
    for (int i = 0; i < legendItems.getItemCount(); i++) {
        LegendItem legendItem = legendItems.get(i);
        DataSeries dataSearies = (DataSeries) allDataSeries.get(i);
        if (legendItem.getFillPaint() instanceof Color) {
            dataSearies.setColor(((Color) legendItem.getFillPaint()));
        }
    }

    return chart;

}

From source file:net.sf.dynamicreports.test.jasper.chart.GroupedStackedBarChartData3Test.java

@Override
public void test() {
    super.test();

    numberOfPagesTest(1);/* w  ww  . j  a  v a 2 s  . com*/

    String[] categories = new String[] { "value1" };
    String[] series = new String[] {
            "group1" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group2" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group3" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1" };
    Number[][] values = new Number[][] { { 1d, 2d, 3d } };
    chartCountTest("groupFooter.chart1", 2);
    chartCategoryCountTest("groupFooter.chart1", 0, 1);
    chartSeriesCountTest("groupFooter.chart1", 0, 3);
    chartDataTest("groupFooter.chart1", 0, categories, series, values);
    JFreeChart chart = getChart("groupFooter.chart1", 0);
    LegendItemCollection fixedLegendItems = chart.getCategoryPlot().getFixedLegendItems();
    Assert.assertEquals("series name", "series1", fixedLegendItems.get(0).getLabel());
    testMap(chart, "group1", "group2", "group3");

    series = new String[] { "group2" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group4" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group5" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1",
            "group6" + GroupedStackedBarRendererCustomizer.GROUP_SERIES_KEY + "series1" };
    values = new Number[][] { { 4d, 5d, 6d, 7d } };
    chartCategoryCountTest("groupFooter.chart1", 1, 1);
    chartSeriesCountTest("groupFooter.chart1", 1, 4);
    chartDataTest("groupFooter.chart1", 1, categories, series, values);
    chart = getChart("groupFooter.chart1", 1);
    fixedLegendItems = chart.getCategoryPlot().getFixedLegendItems();
    Assert.assertEquals("series name", "series1", fixedLegendItems.get(0).getLabel());
    testMap(chart, "group2", "group4", "group5", "group6");
}

From source file:edu.emory.library.tast.database.graphs.GraphTypeBar.java

public JFreeChart createChart(Object[] data) {

    DefaultCategoryDataset dataset = new DefaultCategoryDataset();

    JFreeChart chart = ChartFactory.createBarChart(null, getSelectedIndependentVariable().getLabel(),
            TastResource.getText("components_charts_barvalue"), dataset, PlotOrientation.VERTICAL, true, true,
            false);/*from w  w w .  j av  a 2  s .co  m*/

    CategoryPlot plot = chart.getCategoryPlot();
    plot.getDomainAxis().setMaximumCategoryLabelLines(5);
    plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.DOWN_90);
    chart.setBackgroundPaint(Color.white);

    Format formatter = getSelectedIndependentVariable().getFormat();

    List allDataSeries = getDataSeries();
    for (int j = 0; j < allDataSeries.size(); j++) {

        DataSeries dataSearies = (DataSeries) allDataSeries.get(j);
        String dataSeriesLabel = dataSearies.formatForDisplay();

        for (int i = 0; i < data.length; i++) {
            Object[] row = (Object[]) data[i];

            String cat = formatter == null ? row[0].toString() : formatter.format(row[0]);

            dataset.addValue((Number) row[j + 1], dataSeriesLabel, cat);
        }
    }

    LegendItemCollection legendItems = chart.getPlot().getLegendItems();
    for (int i = 0; i < legendItems.getItemCount(); i++) {
        LegendItem legendItem = legendItems.get(i);
        DataSeries dataSearies = (DataSeries) allDataSeries.get(i);
        if (legendItem.getFillPaint() instanceof Color) {
            dataSearies.setColor(((Color) legendItem.getFillPaint()));
        }
    }

    return chart;

}

From source file:gavisualizer.LineChart.java

@Override
public void generate() {
    // Creates Line Chart from variables
    JFreeChart chart = ChartFactory.createLineChart(_title, // chart title
            _axisLabelDomain, // domain axis label
            _axisLabelRange, // range axis label
            _dataset, // data
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            false, // tooltips
            false // urls
    );/* w  ww .jav a2 s .  c om*/

    // Set the Plot to certain colors
    final CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setOutlinePaint(Color.white);

    // Set Legend to the right of the chart
    final LegendTitle lt = (LegendTitle) chart.getLegend();
    lt.setPosition(RectangleEdge.RIGHT);

    // Set paints for lines in the chart
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    DefaultDrawingSupplier dw = new DefaultDrawingSupplier(PAINTS,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_PAINT_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_OUTLINE_STROKE_SEQUENCE,
            DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE);
    plot.setDrawingSupplier(dw);

    // Customize stroke width of the series
    ((AbstractRenderer) renderer).setAutoPopulateSeriesStroke(false);
    renderer.setBaseStroke(STROKE_WIDTH);
    renderer.setBaseShapesVisible(false);

    // Include dashed lines if necessary
    List<String> rows = _dataset.getRowKeys();

    // See if the title includes Downloads (Dashed lines are for Download lines)
    if (rows.get(rows.size() - 1).endsWith("Downloads")) {
        // Set the start to half the rows
        int start = _dataset.getRowCount() / 2;

        // Create an initial value
        int init = 0;

        // Iterate through the Download lines
        while (start < _dataset.getRowCount()) {
            // Make sure series and legend have dashes
            renderer.setSeriesStroke(start, DASHED_STROKE);
            LegendItemCollection legend = renderer.getLegendItems();
            LegendItem li = legend.get(start - 1);
            li.setLineStroke(DASHED_STROKE);

            // Make sure the color matches the undashed year
            renderer.setSeriesPaint(start, renderer.getItemPaint(init, 0));
            init++;
            start++;
        }
    }

    // Customise the range axis...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(true);

    _chart = chart;
}