Example usage for org.jfree.chart LegendItemCollection LegendItemCollection

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

Introduction

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

Prototype

public LegendItemCollection() 

Source Link

Document

Constructs a new legend item collection, initially empty.

Usage

From source file:org.tsho.dmc2.core.chart.TrajectoryMultiRenderer.java

public LegendItemCollection getLegendItems() {

    Stroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL);
    Shape shape = new Rectangle2D.Double(-3, -3, 6, 6);

    LegendItemCollection legendItems = new LegendItemCollection();

    for (int i = 0; i < stepperList.length; i++) {
        legendItems.add(new LegendItem(Integer.toString(i), "", shape, true, paintList[i], stroke, Color.yellow,
                stroke));//from ww  w.j  ava2 s. c  o  m
    }

    return legendItems;
}

From source file:org.gwaspi.reports.GenericReportGenerator.java

public static CombinedRangeXYPlot buildManhattanPlot(OperationKey testOpKey) throws IOException {

    // PLOT DEFAULTS
    final Config config = Config.getSingleton();
    final double threshold = config.getDouble(PLOT_MANHATTAN_THRESHOLD_CONFIG,
            PLOT_MANHATTAN_THRESHOLD_DEFAULT);
    final Color background = config.getColor(PLOT_MANHATTAN_BACKGROUND_CONFIG,
            PLOT_MANHATTAN_BACKGROUND_DEFAULT);
    final Color backgroundAlternative = config.getColor(PLOT_MANHATTAN_BACKGROUND_ALTERNATIVE_CONFIG,
            PLOT_MANHATTAN_BACKGROUND_ALTERNATIVE_DEFAULT);
    final Color main = config.getColor(PLOT_MANHATTAN_MAIN_CONFIG, PLOT_MANHATTAN_MAIN_DEFAULT);

    Map<MarkerKey, MarkerManhattenData> markerKeyChrPosPVal = assembleManhattenPlotData(testOpKey);

    XYSeriesCollection currChrSC = new XYSeriesCollection();

    NumberAxis sharedAxis = new NumberAxis("-log?(P)");

    CombinedRangeXYPlot combinedPlot = new CombinedRangeXYPlot(sharedAxis);
    combinedPlot.setGap(0);/*www . j a  v a2  s. c  om*/

    XYSeries currChrS = null;

    // Subdividing points into sub-XYSeries, per chromosome
    String currChr = "";
    Map<String, MarkerKey> labeler = new LinkedHashMap<String, MarkerKey>(); // FIXME This is unused, was a global static var before (also private though), was the data added here actually used somewhere? (i think not)
    for (Map.Entry<MarkerKey, MarkerManhattenData> entry : markerKeyChrPosPVal.entrySet()) {
        MarkerKey markerKey = entry.getKey();
        MarkerManhattenData data = entry.getValue();

        if (data.getPValue() != null) {
            final double pVal = data.getPValue(); // Is allready free of NaN and infinity
            if (pVal < 1) {
                if (data.getChromosome().equals(currChr)) {
                    currChrS.add(data.getPosition(), pVal);
                    labeler.put(currChr + "_" + data.getPosition(), markerKey);
                } else {
                    if (!currChr.isEmpty()) { // SKIP FIRST TIME (NO DATA YET!)
                        // add the last (now compleeted) chromosomes data-set,
                        // before starting the new one
                        currChrSC.addSeries(currChrS);
                        appendToCombinedRangeManhattanPlot(combinedPlot, currChr, currChrSC, false, threshold,
                                background, backgroundAlternative, main);
                    }
                    currChr = data.getChromosome();
                    currChrSC = new XYSeriesCollection();
                    currChrS = new XYSeries(currChr);
                    labeler.put(currChr + "_" + data.getPosition(), markerKey);

                    currChrS.add(data.getPosition(), pVal);
                }
            }
        }
    }
    if (currChrS != null) {
        currChrSC.addSeries(currChrS);
        // ADD LAST CHR TO PLOT
        appendToCombinedRangeManhattanPlot(combinedPlot, currChr, currChrSC, true, threshold, background,
                backgroundAlternative, main);
    }

    // Remove Legend from the bottom of the chart
    combinedPlot.setFixedLegendItems(new LegendItemCollection());

    return combinedPlot;
}

From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java

private LegendTitle createLegend(final Collection<VehicleRoute> routes, final XYSeriesCollection shipments,
        final XYPlot plot) {
    LegendItemSource lis = new LegendItemSource() {

        @Override/* w w  w.ja  v  a2  s  .  co  m*/
        public LegendItemCollection getLegendItems() {
            LegendItemCollection lic = new LegendItemCollection();
            LegendItem vehLoc = new LegendItem("vehLoc", Color.RED);
            vehLoc.setShape(ELLIPSE);
            vehLoc.setShapeVisible(true);
            lic.add(vehLoc);
            if (containsServiceAct) {
                LegendItem item = new LegendItem("service", Color.BLUE);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (containsPickupAct) {
                LegendItem item = new LegendItem("pickup", Color.GREEN);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (containsDeliveryAct) {
                LegendItem item = new LegendItem("delivery", Color.BLUE);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (routes != null) {
                LegendItem item = new LegendItem("firstActivity", Color.BLACK);
                Shape upTriangle = ShapeUtilities.createUpTriangle(3.0f);
                item.setShape(upTriangle);
                item.setOutlinePaint(Color.BLACK);

                item.setLine(upTriangle);
                item.setLinePaint(Color.BLACK);
                item.setShapeVisible(true);

                lic.add(item);
            }
            if (!shipments.getSeries().isEmpty()) {
                lic.add(plot.getRenderer(1).getLegendItem(1, 0));
            }
            if (routes != null) {
                lic.addAll(plot.getRenderer(2).getLegendItems());
            }
            return lic;
        }
    };

    LegendTitle legend = new LegendTitle(lis);
    legend.setPosition(RectangleEdge.BOTTOM);
    return legend;
}

From source file:com.sun.japex.ChartGenerator.java

private JFreeChart generateDriverBarChart() {
    try {//from  w  w  w  . jav a2  s .  c  om
        String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT);
        String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X);

        // Ensure japex.resultUnitX is not null
        if (resultUnitX == null) {
            resultUnitX = "";
        }

        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        DefaultCategoryDataset datasetX = new DefaultCategoryDataset();

        // Find first normalizer driver (if any) and adjust unit            
        DriverImpl normalizerDriver = null;
        for (DriverImpl driver : _testSuite.getDriverInfoList()) {
            if (driver.isNormal()) {
                normalizerDriver = driver;
                break;
            }
        }

        // Check if normalizer driver can be used as such
        if (normalizerDriver != null) {
            if (normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN) == 0.0
                    || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN) == 0.0
                    || normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN) == 0.0) {
                System.out.println("Warning: Driver '" + normalizerDriver.getName()
                        + "' cannot be used to normalize results");
                normalizerDriver = null;
            } else {
                resultUnit = "% of " + resultUnit;
                if (resultUnitX != null) {
                    resultUnitX = "% of " + resultUnitX;
                }
            }
        }

        boolean hasValueX = false;

        // Generate charts
        for (DriverImpl di : _testSuite.getDriverInfoList()) {
            if (normalizerDriver != null) {
                dataset.addValue(
                        normalizerDriver == di ? 100.0
                                : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN)
                                        / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN)),
                        di.getName(), "Arithmetic Mean");
                dataset.addValue(
                        normalizerDriver == di ? 100.0
                                : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN)
                                        / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN)),
                        di.getName(), "Geometric Mean");
                dataset.addValue(
                        normalizerDriver == di ? 100.0
                                : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN)
                                        / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN)),
                        di.getName(), "Harmonic Mean");

                if (di.hasParam(Constants.RESULT_ARIT_MEAN_X)) {
                    datasetX.addValue(
                            normalizerDriver == di ? 100.0
                                    : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X)
                                            / normalizerDriver
                                                    .getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X)),
                            di.getName(), "Arithmetic Mean");
                    datasetX.addValue(
                            normalizerDriver == di ? 100.0
                                    : (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X)
                                            / normalizerDriver
                                                    .getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X)),
                            di.getName(), "Geometric Mean");
                    datasetX.addValue(
                            (100.0 * di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X)
                                    / normalizerDriver.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X)),
                            di.getName(), "Harmonic Mean");
                    hasValueX = true;
                }
            } else {
                dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN), di.getName(),
                        "Arithmetic Mean");
                dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN), di.getName(),
                        "Geometric Mean");
                dataset.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN), di.getName(),
                        "Harmonic Mean");

                if (di.hasParam(Constants.RESULT_ARIT_MEAN_X)) {
                    datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_ARIT_MEAN_X), di.getName(),
                            "Arithmetic Mean");
                    datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_GEOM_MEAN_X), di.getName(),
                            "Geometric Mean");
                    datasetX.addValue(di.getDoubleParamNoNaN(Constants.RESULT_HARM_MEAN_X), di.getName(),
                            "Harmonic Mean");
                    hasValueX = true;
                }
            }

        }

        int nextPlotIndex = 1;
        CombinedDomainCategoryPlot plot = new CombinedDomainCategoryPlot();

        // Use same renderer in combine charts to get same colors
        BarRenderer3D renderer = new BarRenderer3D();
        renderer.setToolTipGenerator(new StandardCategoryToolTipGenerator());

        // Bar chart for secondary data set based on japex.resultValueX
        if (hasValueX) {
            NumberAxis rangeAxisX = new NumberAxis(resultUnitX);
            CategoryPlot subplotX = new CategoryPlot(datasetX, null, rangeAxisX, renderer);

            // Set transparency and clear legend for this plot
            subplotX.setForegroundAlpha(0.7f);
            subplotX.setFixedLegendItems(new LegendItemCollection());

            plot.add(subplotX, nextPlotIndex++);
            _chartHeight += 50; // Adjust chart height
        } else {
        }

        // Bar chart for main data set based on japex.resultValue
        NumberAxis rangeAxis = new NumberAxis(resultUnit);
        CategoryPlot subplot = new CategoryPlot(dataset, null, rangeAxis, renderer);
        subplot.setForegroundAlpha(0.7f); // transparency
        plot.add(subplot, nextPlotIndex);

        // Create chart and save it as JPEG
        String chartTitle = "Result Summary";
        JFreeChart chart = new JFreeChart(hasValueX ? chartTitle : (chartTitle + "(" + resultUnit + ")"),
                new Font("SansSerif", Font.BOLD, 14), plot, true);
        chart.setAntiAlias(true);
        return chart;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}

From source file:jspritTest.util.Plotter.java

private LegendTitle createLegend(final Collection<VehicleRoute> routes, final XYSeriesCollection shipments,
        final XYPlot plot) {
    LegendItemSource lis = new LegendItemSource() {

        public LegendItemCollection getLegendItems() {
            LegendItemCollection lic = new LegendItemCollection();
            LegendItem vehLoc = new LegendItem("vehLoc", Color.RED);
            vehLoc.setShape(ELLIPSE);/*from  w  w  w  . j  av a2 s.c o  m*/
            vehLoc.setShapeVisible(true);
            lic.add(vehLoc);
            if (containsServiceAct) {
                LegendItem item = new LegendItem("service", Color.BLUE);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (containsPickupAct) {
                LegendItem item = new LegendItem("pickup", Color.GREEN);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (containsDeliveryAct) {
                LegendItem item = new LegendItem("delivery", Color.BLUE);
                item.setShape(ELLIPSE);
                item.setShapeVisible(true);
                lic.add(item);
            }
            if (routes != null) {
                LegendItem item = new LegendItem("firstActivity", Color.BLACK);
                Shape upTriangle = ShapeUtilities.createUpTriangle(3.0f);
                item.setShape(upTriangle);
                item.setOutlinePaint(Color.BLACK);

                item.setLine(upTriangle);
                item.setLinePaint(Color.BLACK);
                item.setShapeVisible(true);

                lic.add(item);
            }
            if (!shipments.getSeries().isEmpty()) {
                lic.add(plot.getRenderer(1).getLegendItem(1, 0));
            }
            if (routes != null) {
                lic.addAll(plot.getRenderer(2).getLegendItems());
            }
            return lic;
        }
    };

    LegendTitle legend = new LegendTitle(lis);
    legend.setPosition(RectangleEdge.BOTTOM);
    return legend;
}

From source file:org.logisticPlanning.utils.graphics.chart.impl.jfree._JFCLineChart2D.java

/** process the lines */
private final void __processLines() {
    final LegendItemCollection legendCollection;
    final boolean addLegend;
    final ChartPalette palette;
    Stroke legendStroke;/*from w  w w . j a v a  2  s . c om*/
    Color legendColor;
    int index;
    Line2D line;
    List<Line2D> lines;
    Iterator<Point2D> it;
    Point2D p;
    boolean foreground;
    XYSeries ser;
    String name;
    LegendItem item;

    lines = this.getBackgroundLines();
    ((_JFCXYLineAndShapeRenderer) (this.m_plot.getDrawingSupplier())).m_backgroundCount = lines.size();
    foreground = false;

    legendCollection = new LegendItemCollection();
    addLegend = (this.getLegendType() != ELegendType.NO_LEGEND);
    palette = this.getDriver().getPalette();

    // first add all foreground lines, than all background lines
    outer: for (;;) {
        index = 0;

        while (lines.size() > 0) {
            line = lines.remove(0);
            it = this.iterateLinePoints(line);

            // // are there any points to plot?
            // if (it.hasNext()) {
            // // then let's make a series and plot them!
            name = line.name();
            ser = new XYSeries(((name != null) ? name : EmptyUtils.EMPTY_STRING), false, true);

            while (it.hasNext()) {
                p = it.next();
                ser.add(_JFCLineChart2D.__format(p.getX()), _JFCLineChart2D.__format(p.getY()));
            }

            this.m_dataset.addSeries(ser);

            if (addLegend && (name != null) && (name.length() > 0)) {

                legendColor = (foreground ? //
                        palette.getForegroundDataColor(index)//
                        : palette.getBackgroundDataColor(index));
                legendStroke = (foreground ? //
                        palette.getForegroundDataStroke(index)//
                        : palette.getBackgroundDataStroke(index));

                item = new LegendItem(//
                        name, null, null, null, // text
                        false, _JFCLineChart2D.EMPTY_SHAPE, false, // shape
                        legendColor, //
                        false, //
                        legendColor, //
                        legendStroke, //
                        false, _JFCLineChart2D.EMPTY_SHAPE, // line
                        legendStroke, //
                        legendColor//
                );
                item.setLabelFont(palette.getLegendFont());
                item.setLabelPaint(legendColor);
                legendCollection.add(item);
            }
            index++;
            // }
        }

        if (foreground) {
            break outer;
        }
        foreground = true;
        lines = this.getLines();
    }

    this.m_plot.setFixedLegendItems(legendCollection);
}

From source file:edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo4.java

/**
 * Creates the legend items for the chart.  In this case, we set them 
 * manually because we only want legend items for a subset of the data 
 * series.//from  ww  w  .  j  ava  2  s .  c o m
 * 
 * @return The legend items.
 */
private static LegendItemCollection createLegendItems() {
    LegendItemCollection result = new LegendItemCollection();
    LegendItem item1 = new LegendItem("US", "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX,
            new Color(0x22, 0x22, 0xFF));
    LegendItem item2 = new LegendItem("Europe", "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX,
            new Color(0x22, 0xFF, 0x22));
    LegendItem item3 = new LegendItem("Asia", "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX,
            new Color(0xFF, 0x22, 0x22));
    LegendItem item4 = new LegendItem("Middle East", "-", null, null, Plot.DEFAULT_LEGEND_ITEM_BOX,
            new Color(0xFF, 0xFF, 0x22));
    result.add(item1);
    result.add(item2);
    result.add(item3);
    result.add(item4);
    return result;
}

From source file:org.jax.haplotype.analysis.visualization.GenomicGraphFactory.java

/**
 * Create a SNP block graph for the given parameters. This graph
 * will show where the intervals do and don't exist. Interval lists
 * are organized with the X axis label matching the list's key
 * @param snpIntervals//from w w  w . ja  va2s  .  c om
 *          the blocks
 * @param startInBasePairs
 *          the x location to start the graph at
 * @param extentInBasePairs
 *          the extent to use for the graph
 * @param maximumImageBlockCount
 *          the max # of separate image blocks to use
 * @param renderAxes
 *          if true render the axes... otherwise dont
 * @param legendText
 *          the text to use for the legend
 * @param yAxisText
 *          the text to use for the y axis
 * @param trueColor
 *          the color to use for true
 * @param falseColor
 *          the color to use for false 
 * @return
 *          the graph
 */
public JFreeChart createSnpIntervalGraph(
        final Map<String, ? extends List<? extends BasePairInterval>> snpIntervals, final long startInBasePairs,
        final long extentInBasePairs, final int maximumImageBlockCount, final boolean renderAxes,
        final String legendText, final String yAxisText, final Color trueColor, final Color falseColor) {
    XYDataset dataset = snpIntervalsToDataset(snpIntervals, startInBasePairs, extentInBasePairs,
            maximumImageBlockCount);

    NumberAxis xAxis = new NumberAxis("SNP Position (Base Pairs)");
    xAxis.setAutoRangeIncludesZero(false);
    xAxis.setRange(new Range(startInBasePairs, startInBasePairs + extentInBasePairs));
    String[] sortedStrainNames = extractSortedStrainNames(snpIntervals);
    for (int strainIndex = 0; strainIndex < sortedStrainNames.length; strainIndex++) {
        LOG.info("Strain Name: " + sortedStrainNames[strainIndex]);
    }
    SymbolAxis yAxis = new SymbolAxis(yAxisText == null ? "" : yAxisText, sortedStrainNames);

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, null);
    LegendItemCollection items = new LegendItemCollection();
    if (legendText != null) {
        items.add(new LegendItem(legendText, null, null, null, new Rectangle2D.Double(-3.0, -3.0, 6.0, 6.0),
                trueColor, new BasicStroke(), Color.BLACK));
    }
    plot.setFixedLegendItems(items);

    XYBlockRenderer r = new XYBlockRenderer();
    SmoothPaintScale ps = new SmoothPaintScale(0.0, 1.0, falseColor, trueColor);

    r.setPaintScale(ps);
    r.setBlockHeight(1.0);
    r.setBlockWidth(1.0);
    plot.setRenderer(r);

    final JFreeChart chart;
    if (renderAxes) {
        chart = new JFreeChart("Identical By State Blocks", JFreeChart.DEFAULT_TITLE_FONT, plot, true);
    } else {
        xAxis.setVisible(false);
        yAxis.setVisible(false);
        plot.setInsets(new RectangleInsets(0.0, 0.0, 0.0, 0.0));
        chart = new JFreeChart(plot);
    }

    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

From source file:edu.jhuapl.graphs.controller.GraphController.java

public GraphObject createTimeSeriesGraph(GraphDataInterface graphData, Double yAxisMin, Double yAxisMax,
        String displayKey) {/*ww  w.j  a va2s  .  c  o  m*/
    List<DataSeries> dataSeries = new ArrayList<DataSeries>();
    LegendItemCollection legendItems = new LegendItemCollection();
    Map<String, Object> graphMetaData = new HashMap<String, Object>();
    double maxCount = setDataSeries(graphData, displayKey, false, dataSeries, legendItems);

    setTimeSeriesGraphMetaData(graphData, yAxisMin, yAxisMax, maxCount, graphMetaData);

    return getGraph(graphData, dataSeries, graphMetaData, legendItems, "tsgraph");
}

From source file:edu.jhuapl.graphs.controller.GraphController.java

/**
 * The useItemColor is still under development to allow each bar to be a different color.
 *//*  www. jav  a 2 s  .  com*/
public GraphObject createBarGraph(GraphDataInterface graphData, boolean stackGraph, boolean useItemColor) {
    List<DataSeries> dataSeries = new ArrayList<DataSeries>();
    LegendItemCollection legendItems = new LegendItemCollection();
    Map<String, Object> graphMetaData = new HashMap<String, Object>();

    setDataSeries(graphData, null, false, dataSeries, legendItems, useItemColor);
    setBarGraphMetaData(graphData, stackGraph, graphMetaData);

    return getGraph(graphData, dataSeries, graphMetaData, legendItems, "bargraph");
}