Example usage for org.jfree.chart.plot CategoryPlot getLegendItems

List of usage examples for org.jfree.chart.plot CategoryPlot getLegendItems

Introduction

In this page you can find the example usage for org.jfree.chart.plot CategoryPlot getLegendItems.

Prototype

@Override
public LegendItemCollection getLegendItems() 

Source Link

Document

Returns the legend items for the plot.

Usage

From source file:unalcol.termites.boxplots.ECALMessages.java

private LegendTitle modifyLegend(JFreeChart chart, CategoryPlot plot) {
    LegendTitle legend = chart.getLegend();
    chart.removeLegend();//from  w w  w. j av a  2  s.  c  o m
    LegendItemSource[] items = legend.getSources();
    for (LegendItemSource item : items) {
        //LegendItemCollection collection = items[i].getLegendItems();
        LegendItemCollection collection = plot.getLegendItems();

        for (Iterator iter = collection.iterator(); iter.hasNext();) {
            LegendItem element = (LegendItem) iter.next();
            System.out.println(" ## #" + element.getLabel());
        }
    }

    return legend;
}

From source file:charts.Chart.java

public static void PlotParallelCoordinates(String title, String x_axis_label, String y_axis_label, float[][] Md,
        int classes, int[] features, Vector featurestitles, Vector datatitles) {
    JFrame chartwindow = new JFrame(title);
    JFreeChart jfreechart = ChartFactory.createLineChart(title, x_axis_label, y_axis_label, null,
            PlotOrientation.VERTICAL, true, true, false);

    CategoryPlot categoryplot = (CategoryPlot) jfreechart.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.black);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    int lines = Md.length;
    int columns = Md[0].length;

    LineAndShapeRenderer[] lineandshaperenderer = new LineAndShapeRenderer[classes];

    for (int i = 0; i < lineandshaperenderer.length; i++) {
        lineandshaperenderer[i] = new LineAndShapeRenderer();
        lineandshaperenderer[i].setShapesVisible(true);
        lineandshaperenderer[i].setDrawOutlines(true);
        lineandshaperenderer[i].setUseFillPaint(true);
        lineandshaperenderer[i].setFillPaint(Color.white);
        lineandshaperenderer[i].setBaseStroke(new BasicStroke(2.0f));
    }//from  w ww  .  java  2s. c o  m
    int count = 0;
    for (int i = 0; i < lines; i++) {
        int classe = ((int) Md[i][columns - 1]);
        DefaultKeyedValues2DDataset dataset = new DefaultKeyedValues2DDataset();
        int j = 0;
        double value = 0;
        while (j < features.length) {
            /*value recebe o valor da linha i e da coluna especificada
            pelo usuario, por meio do parametro de chegada features[]*/
            value = Md[i][features[j]];

            String strclasse = String.valueOf(classe);
            //especifico Marie-Anne
            /*
            if (classe == 0) {
            strclasse = "thi1";
            lineandshaperenderer[classe].setSeriesPaint(0, Color.RED);
            Shape s0 = new Rectangle2D.Float(-3f, -3f, 6f, 6f);
            lineandshaperenderer[classe].setSeriesShape(0, s0);
            } else if (classe == 1) {
            strclasse = "controle";
            lineandshaperenderer[classe].setSeriesPaint(0, Color.PINK);
            Shape s1 = new Ellipse2D.Float(-3f, -3f, 6f, 6f);
            lineandshaperenderer[classe].setSeriesShape(0, s1);
            } else if (classe == 2) {
            strclasse = "fotossntese";
            lineandshaperenderer[classe].setSeriesPaint(0, Color.GREEN);
            int[] x = {-3, 0, 3};
            int[] y = {-3, 3, -3};
            int n = 3;
            Shape s2 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesShape(0, s2);
            } else if (classe == 3) {
            strclasse = "respirao";
            int[] x = {-3, 0, 3};
            int[] y = {3, -3, 3};
            int n = 3;
            Shape s3 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesShape(0, s3);
            lineandshaperenderer[classe].setSeriesPaint(0, Color.BLUE);
            } else if (classe == 4) {
            strclasse = "sntese de tiamina";
            lineandshaperenderer[classe].setSeriesPaint(0, Color.BLACK);
            Shape s4 = new Rectangle2D.Float(-1f, -3f, 1f, 6f);
            lineandshaperenderer[classe].setSeriesShape(0, s4);
            } else if (classe == 5) {
            strclasse = "gliclise";
            int[] x = {-3, 0, 3, 0};
            int[] y = {0, -3, 0, 3};
            int n = 4;
            Shape s5 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesPaint(0, Color.ORANGE);
            lineandshaperenderer[classe].setSeriesShape(0, s5);
            } else if (classe == 6) {
            strclasse = "AT4G34200";
            int[] x = {-3, 0, 3, 0};
            int[] y = {0, -3, 0, 3};
            int n = 4;
            Shape s5 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesPaint(0, Color.MAGENTA);
            lineandshaperenderer[classe].setSeriesShape(0, s5);
            } else if (classe == 7) {
            strclasse = "AT2G36530";
            int[] x = {-3, 0, 3, 0};
            int[] y = {0, -3, 0, 3};
            int n = 4;
            Shape s5 = new Polygon(x, y, n);
            lineandshaperenderer[classe].setSeriesPaint(0, Color.CYAN);
            lineandshaperenderer[classe].setSeriesShape(0, s5);
            }
             */

            if (featurestitles != null) {
                if (datatitles != null) {
                    dataset.addValue(value, strclasse, (String) featurestitles.get(features[j] + 1));
                    //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c + 1));
                } else {
                    dataset.addValue(value, strclasse, (String) featurestitles.get(features[j]));
                    //datasets[i].addValue(Mo[lineindex[i]][c], label, (String) featurestitles.get(c));
                }
            } else {
                dataset.addValue(value, strclasse, String.valueOf(features[j]));
                //datasets[i].addValue(Mo[lineindex[i]][c], label, String.valueOf(c));
            }
            //dataset.addValue(value, String.valueOf(classe), String.valueOf(features[j]));
            j++;
        }
        categoryplot.setDataset(count, dataset);
        categoryplot.setRenderer(count, lineandshaperenderer[classe]);
        count++;
    }
    LegendItemCollection legends = categoryplot.getLegendItems();
    LegendItemCollection newlegends = new LegendItemCollection();
    for (int i = 0; i < classes; i++) {
        int l = 0;
        //especifico Marie-Anne
        String label1 = null;
        if (i == 0) {
            label1 = "thi1";
        } else if (i == 1) {
            label1 = "controle";
        } else if (i == 2) {
            label1 = "fotossntese";
        } else if (i == 3) {
            label1 = "respirao";
        } else if (i == 4) {
            label1 = "sntese de tiamina";
        } else if (i == 5) {
            label1 = "gliclise";
        } else if (i == 6) {
            label1 = "AT4G34200";
        } else if (i == 7) {
            label1 = "AT2G36530";
        }

        //String label1 = String.valueOf(i);
        String label2 = null;
        boolean found = false;
        do {
            label2 = legends.get(l).getLabel();
            if (label1.equalsIgnoreCase(label2)) {
                found = true;
            } else {
                l++;
            }
        } while (!found && (l < lines));
        if (found) {
            //newlegends.add(legends.get(l));
            LegendItem li = new LegendItem(legends.get(l).getLabel(), legends.get(l).getDescription(),
                    legends.get(l).getToolTipText(), legends.get(l).getURLText(),
                    legends.get(l).isShapeVisible(), legends.get(l).getShape(), legends.get(l).isShapeFilled(),
                    legends.get(l).getFillPaint(), legends.get(l).isShapeOutlineVisible(),
                    legends.get(l).getOutlinePaint(), legends.get(l).getOutlineStroke(),
                    legends.get(l).isLineVisible(), legends.get(l).getLine(), legends.get(l).getLineStroke(),
                    legends.get(l).getLinePaint());
            newlegends.add(li);
        }
    }
    categoryplot.setFixedLegendItems(newlegends);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));
    chartwindow.setContentPane(jpanel);
    chartwindow.pack();
    RefineryUtilities.centerFrameOnScreen(chartwindow);
    chartwindow.setVisible(true);
}