Example usage for org.jfree.chart JFreeChart removeLegend

List of usage examples for org.jfree.chart JFreeChart removeLegend

Introduction

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

Prototype

public void removeLegend() 

Source Link

Document

Removes the first legend in the chart and sends a ChartChangeEvent to all registered listeners.

Usage

From source file:loci.slim.ui.ExcitationGraph.java

/**
 * Creates the chart/*from www .ja  v  a2  s  . c o  m*/
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @param data fitted data
 * @return the chart
 */
JFreeChart createChart(final int bins, final double timeInc, final double[] values) {

    // create chart data
    createDataset(bins, timeInc, values);

    // make a horizontal axis
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertical axis
    NumberAxis photonAxis;
    if (_logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }

    // make an excitation plot
    final XYSplineRenderer excitationRenderer = new XYSplineRenderer();
    excitationRenderer.setSeriesShapesVisible(0, false);
    excitationRenderer.setSeriesPaint(0, EXCITATION_COLOR);

    _excitationPlot = new XYPlot(_excitationDataset, timeAxis, photonAxis, excitationRenderer);
    _excitationPlot.setDomainCrosshairVisible(true);
    _excitationPlot.setRangeCrosshairVisible(true);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, _excitationPlot, true);
    chart.removeLegend();

    return chart;
}

From source file:loci.slim2.process.interactive.ui.DefaultExcitationGraph.java

/**
 * Creates the chart// w  w  w .j  a v  a 2  s. c om
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @param data fitted data
 * @return the chart
 */
JFreeChart createChart(final int bins, final double timeInc, final double[] values) {

    // create chart data
    createDataset(bins, timeInc, values);

    // make a horizontal axis
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertical axis
    NumberAxis photonAxis;
    if (logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }

    // make an excitation plot
    final XYSplineRenderer excitationRenderer = new XYSplineRenderer();
    excitationRenderer.setSeriesShapesVisible(0, false);
    excitationRenderer.setSeriesPaint(0, EXCITATION_COLOR);

    excitationPlot = new XYPlot(excitationDataset, timeAxis, photonAxis, excitationRenderer);
    excitationPlot.setDomainCrosshairVisible(true);
    excitationPlot.setRangeCrosshairVisible(true);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, excitationPlot, true);
    chart.removeLegend();

    return chart;
}

From source file:ch.agent.crnickl.demo.stox.Chart.java

private JFreeChart makeChart() throws KeyedException {

    if (chartSeries.size() == 0)
        throw new IllegalStateException("addChartSeries() not called");

    if (range == null) {
        for (ChartSeries s : chartSeries) {
            if (range == null)
                range = s.getTimeSeries().getRange();
            else//from  w w  w. j a v  a 2s . co m
                range = range.union(s.getTimeSeries().getRange());
        }
    }

    // use number axis for dates, with special formatter
    DateAxis dateAxis = new DateAxis();
    dateAxis.setDateFormatOverride(new CustomDateFormat("M/d/y"));
    if (range.getTimeDomain().getLabel().equals("workweek"))
        dateAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());

    // combined plot with shared date axis
    CombinedDomainXYPlot plot = new CombinedDomainXYPlot(dateAxis);

    for (ChartSeries s : chartSeries) {
        makeSubPlot(plot, s);
    }

    // make the chart, remove the legend, set the title
    JFreeChart chart = new JFreeChart(plot);
    if (!withLegend)
        chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    chart.setTitle(new TextTitle(title));

    return chart;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java

@Override
public JFreeChart createChart(DatasetMap datasets) {
    logger.debug("IN");
    super.createChart(datasets);
    DefaultXYZDataset dataset = (DefaultXYZDataset) datasets.getDatasets().get("1");

    DateAxis xAxis = new DateAxis(yLabel);
    xAxis.setLowerMargin(0.0);/*from  ww w  .jav  a 2 s .c  om*/
    xAxis.setUpperMargin(0.0);
    xAxis.setInverted(false);
    xAxis.setDateFormatOverride(new SimpleDateFormat("dd/MM/yyyy"));
    if (dateAutoRange) {
        xAxis.setAutoRange(true);
    } else {
        DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy");
        DateTickUnit unit = new DateTickUnit(DateTickUnit.DAY, 1, formatter);
        xAxis.setTickUnit(unit);
    }

    if (dateMin != null && dateMax != null) {
        xAxis.setRange(dateMin, addDay(dateMax));
    } else {
        xAxis.setRange(minDateFound, addDay(maxDateFound));
    }

    //      Calendar c=new GregorianCalendar();
    //      c.set(9 + 2000, Calendar.JANUARY, 1);
    //      java.util.Date minima=c.getTime();
    //      Calendar c1=new GregorianCalendar();
    //      c1.set(9 + 2000, Calendar.FEBRUARY, 1);
    //      java.util.Date massima=c1.getTime();

    NumberAxis yAxis = new NumberAxis(xLabel);
    yAxis.setUpperMargin(0.0);
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    yAxis.setRange(hourMin, hourMax);

    XYBlockRenderer renderer = new XYBlockRenderer();
    renderer.setBlockWidth(BLOCK_HEIGHT);
    // one block for each minute!
    renderer.setBlockHeight(0.017);
    //renderer.setBlockWidth(1);
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM_LEFT);

    //      MyXYItemLabelGenerator my=new MyXYItemLabelGenerator();
    //      renderer.setItemLabelsVisible(null);
    //      renderer.setSeriesItemLabelGenerator(0, my);
    //      renderer.setSeriesItemLabelsVisible(0, true);

    //      XYTextAnnotation annotation1 = new XYTextAnnotation(
    //      "P_",1.2309372E12, 14.3);
    //      XYTextAnnotation annotation2 = new XYTextAnnotation(
    //      "P_",1.2308508E12, 16.3);

    for (Iterator iterator = annotations.keySet().iterator(); iterator.hasNext();) {
        String annotationCode = (String) iterator.next();
        AnnotationBlock annotationBlock = annotations.get(annotationCode);
        XYTextAnnotation xyAnnotation = new XYTextAnnotation(annotationBlock.getAnnotation(),
                annotationBlock.getXPosition() + ANNOTATION_HEIGHT, annotationBlock.getYPosition());
        if (styleAnnotation != null) {
            xyAnnotation.setFont(new Font(styleAnnotation.getFontName(), Font.BOLD, styleAnnotation.getSize()));
            xyAnnotation.setPaint(styleAnnotation.getColor());
        } else {
            xyAnnotation.setFont(new Font("Nome", Font.BOLD, 8));
            xyAnnotation.setPaint(Color.BLACK);
        }

        xyAnnotation.setTextAnchor(TextAnchor.BOTTOM_LEFT);
        renderer.addAnnotation(xyAnnotation);
    }

    logger.debug("Annotation set");

    LookupPaintScale paintScale = new LookupPaintScale(0.5, ranges.size() + 0.5, color);
    String[] labels = new String[ranges.size() + 1];
    labels[0] = "";

    // ******************** SCALE ****************************
    for (Iterator iterator = ranges.iterator(); iterator.hasNext();) {
        RangeBlocks range = (RangeBlocks) iterator.next();
        Integer index = patternRangeIndex.get(range.getPattern());
        Color color = range.getColor();
        if (color != null) {
            //Paint colorTransparent=new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);         
            Paint colorTransparent = null;
            if (addTransparency == true) {
                colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue(), 50);
            } else {
                colorTransparent = new Color(color.getRed(), color.getGreen(), color.getBlue());
            }
            paintScale.add(index + 0.5, colorTransparent);
        }
        //String insertLabel="            "+range.getLabel();
        String insertLabel = range.getLabel();
        labels[index + 1] = insertLabel;
    }
    renderer.setPaintScale(paintScale);

    SymbolAxis scaleAxis = new SymbolAxis(null, labels);
    scaleAxis.setRange(0.5, ranges.size() + 0.5);
    scaleAxis.setPlot(new PiePlot());
    scaleAxis.setGridBandsVisible(false);

    org.jfree.chart.title.PaintScaleLegend psl = new PaintScaleLegend(paintScale, scaleAxis);
    psl.setMargin(new RectangleInsets(3, 10, 3, 10));
    psl.setPosition(RectangleEdge.BOTTOM);
    psl.setAxisOffset(5.0);
    // ******************** END SCALE ****************************

    logger.debug("Scale Painted");

    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);
    plot.setOrientation(PlotOrientation.HORIZONTAL);
    plot.setBackgroundPaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5, 5, 5, 5));

    logger.debug("Plot set");

    JFreeChart chart = new JFreeChart(name, plot);
    if (styleTitle != null) {
        TextTitle title = setStyleTitle(name, styleTitle);
        chart.setTitle(title);
    }
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    chart.addSubtitle(psl);

    logger.debug("OUT");

    return chart;

}

From source file:vteaexploration.plottools.panels.XYChartPanel.java

private ChartPanel createChart(int x, int y, int l, String xText, String yText, String lText,
        Color imageGateColor) {/*from w  w w.ja v  a  2  s .  c  o  m*/

    XYShapeRenderer renderer = new XYShapeRenderer();
    XYShapeRenderer rendererGate = new XYShapeRenderer();

    PaintScaleLegend psl = new PaintScaleLegend(new LookupPaintScale(0, 100, new Color(0, 0, 0)),
            new NumberAxis(""));

    if (l > 0) {
        double max = getMaximumOfData((ArrayList) plotValues.get(1), l);
        double min = this.getMinimumOfData((ArrayList) plotValues.get(1), l);
        double range = max - min;

        if (max == 0) {
            max = 1;
        }

        //System.out.println("PROFILING-DETAILS: Points to plot: " + ((ArrayList) plotValues.get(1)).size());
        LookupPaintScale ps = new LookupPaintScale(min, max + 100, new Color(0, 0, 0));

        renderer.setPaintScale(ps);

        ps.add(min, TENPERCENT);
        ps.add(min + (1 * (range / 10)), XYChartPanel.TENPERCENT);
        ps.add(min + (2 * (range / 10)), XYChartPanel.TWENTYPERCENT);
        ps.add(min + (3 * (range / 10)), XYChartPanel.THIRTYPERCENT);
        ps.add(min + (4 * (range / 10)), XYChartPanel.FORTYPERCENT);
        ps.add(min + (5 * (range / 10)), XYChartPanel.FIFTYPERCENT);
        ps.add(min + (6 * (range / 10)), XYChartPanel.SIXTYPERCENT);
        ps.add(min + (7 * (range / 10)), XYChartPanel.SEVENTYPERCENT);
        ps.add(min + (8 * (range / 10)), XYChartPanel.EIGHTYPERCENT);
        ps.add(min + (9 * (range / 10)), XYChartPanel.NINETYPERCENT);
        ps.add(max, XYChartPanel.ALLPERCENT);

        NumberAxis lAxis = new NumberAxis(lText);
        lAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        psl = new PaintScaleLegend(ps, lAxis);
        psl.setBackgroundPaint(VTC._VTC.BACKGROUND);
        psl.setPosition(RectangleEdge.RIGHT);
        psl.setMargin(4, 4, 40, 4);
        psl.setAxisLocation(AxisLocation.BOTTOM_OR_RIGHT);

    } else {

        renderer.setBaseFillPaint(TENPERCENT);
    }

    Ellipse2D shape = new Ellipse2D.Double(0, 0, size, size);
    Ellipse2D shapeGate = new Ellipse2D.Double(-2, -2, size + 4, size + 4);

    renderer.setBaseShape(shape);

    rendererGate.setBaseShape(shapeGate);

    NumberAxis xAxis = new NumberAxis("");
    NumberAxis yAxis = new NumberAxis("");

    xAxis.setAutoRangeIncludesZero(false);
    yAxis.setAutoRangeIncludesZero(false);

    XYPlot plot = new XYPlot(createXYZDataset((ArrayList) plotValues.get(1), x, y, l), xAxis, yAxis, renderer);

    plot.getDomainAxis();
    plot.getRangeAxis();

    plot.setDomainPannable(false);
    plot.setRangePannable(false);

    plot.setRenderer(0, renderer);
    plot.setRenderer(1, rendererGate);

    plot.setDataset(0, createXYZDataset((ArrayList) plotValues.get(1), x, y, l));

    if (imageGate) {
        roiCreated(impoverlay);
        XYZDataset set = createXYZDataset(ImageGateOverlay, x, y, l);
        plot.setDataset(1, set);
        plot.setRenderer(1, new XYShapeRenderer() {
            @Override
            protected java.awt.Paint getPaint(XYDataset dataset, int series, int item) {
                return imageGateOutline;
            }

            @Override
            public Shape getItemShape(int row, int col) {
                return new Ellipse2D.Double(-2, -2, size + 4, size + 4);
            }
        });

    }
    //System.out.println("PROFILING: Generating plot with " + plot.getDatasetCount() + " datasets.");
    //System.out.println("PROFILING: Generating plot with " + ImageGateOverlay.size() + " objects gated.");

    try {
        if (getRangeofData((ArrayList) plotValues.get(1), x) > 16384) {
            LogAxis logAxisX = new LogAxis();
            logAxisX.setAutoRange(true);
            plot.setDomainAxis(logAxisX);
        }

        if (getRangeofData((ArrayList) plotValues.get(1), y) > 16384) {
            LogAxis logAxisY = new LogAxis();
            logAxisY.setAutoRange(true);
            plot.setRangeAxis(logAxisY);
        }
    } catch (NullPointerException e) {
    }
    ;

    JFreeChart chart = new JFreeChart("Plot of " + xText + " vs. " + yText, plot);

    chart.removeLegend();

    //LUT 
    if (l > 0)
        chart.addSubtitle(psl);

    //notifiyUpdatePlotWindowListeners();
    return new ChartPanel(chart, true, true, false, false, true);
}

From source file:de.dfki.owlsmx.gui.ResultVisualization.java

public JFreeChart createRPChart() {

    Query query;//from   w  ww . ja  v a 2  s .c om
    Map.Entry me;
    MacroAvgRecallPrecision recall = new MacroAvgRecallPrecision(20);
    ArrayList retrievedServices = new ArrayList();
    ArrayList relevantServices = new ArrayList();
    for (Iterator iter = TestCollection.getInstance()
            .getMatchmakerAnswerset(GUIState.getInstance().getSorting()).entrySet().iterator(); iter
                    .hasNext();) {
        me = (Map.Entry) (iter.next());
        query = (Query) me.getKey();
        retrievedServices = getURIasStringFromServiceSet((SortedSet) me.getValue());
        relevantServices = getURIasStringFromURISet(TestCollection.getInstance().getAnswerset(query.getURI()));
        //          owlsmx.io.ErrorLog.instanceOf().report(query.toString() + ":");
        //          owlsmx.io.ErrorLog.instanceOf().report("  " + retrievedServices.toString());
        //          owlsmx.io.ErrorLog.instanceOf().report("  " + relevantServices.toString());
        if (relevantServices.size() <= 0)
            GUIState.displayWarning(this, "Error when computing recall/precision graph",
                    "Relevance set is empty. Maybe forgotten to define?");
        recall.processRecallPrecision(retrievedServices, relevantServices);
    }

    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(createRPSeries(recall, (retrievedServices.size() <= 0)));

    JFreeChart chart = ChartFactory.createXYLineChart("Recall/Precision", "Recall", "Precision", data,
            org.jfree.chart.plot.PlotOrientation.VERTICAL, true, true, false);
    chart.removeLegend();
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer renderer = (XYItemRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.red);
    return chart;
}

From source file:GeMSE.GS.Analysis.Stats.OneSamplePCAPanel.java

private void Plot() {
    double[][] data = _principalComponents.getData();
    if (data[0].length < 2) {
        JOptionPane.showMessageDialog(this,
                "An error occured when computing principal components.     "
                        + "\nRequire at least two principal components, but calculated "
                        + String.valueOf(data[0].length) + "\n",
                "Not enough data", JOptionPane.ERROR_MESSAGE);
        return;/* w ww  .  j  a  va 2 s .  c om*/
    }

    float[] yAxisColor = new float[3];
    Color.RGBtoHSB(255, 255, 255, yAxisColor);

    float[] hsbValues = new float[3];
    Color.RGBtoHSB(16, 23, 67, hsbValues);

    float[] pcColor = new float[3];
    Color.RGBtoHSB(255, 255, 0, pcColor);

    XYSeriesCollection dataset = new XYSeriesCollection();

    XYSeries series = new XYSeries("PC");
    for (double[] d : data)
        series.add(d[0], d[1]);
    dataset.addSeries(series);

    JFreeChart chart = ChartFactory.createScatterPlot(null, "Principal component 1", "Principal component 2",
            (XYDataset) dataset);
    chart.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2]));
    chart.removeLegend();

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2]));

    Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14);
    Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12);

    plot.setDomainGridlinePaint(Color.gray);
    plot.setRangeGridlinePaint(Color.gray);

    plot.getDomainAxis().setTickLabelPaint(Color.white);
    plot.getDomainAxis().setLabelPaint(Color.white);
    plot.getDomainAxis().setLabelFont(axisLabelFont);
    plot.getDomainAxis().setTickLabelFont(axisTickLabelFont);

    plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(yAxisColor[0], yAxisColor[1], yAxisColor[2]));
    plot.getRangeAxis().setLabelPaint(Color.getHSBColor(yAxisColor[0], yAxisColor[1], yAxisColor[2]));
    plot.getRangeAxis().setLabelFont(axisLabelFont);
    plot.getRangeAxis().setTickLabelFont(axisTickLabelFont);

    Shape shape = ShapeUtilities.createDiagonalCross(4, 0.5f);
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    renderer.setSeriesShape(0, shape);
    renderer.setSeriesPaint(0, Color.getHSBColor(pcColor[0], pcColor[1], pcColor[2]));

    ChartPanel panel = new ChartPanel(chart);
    Dimension plotDim = plotPanel.getSize();
    plotDim.height -= (plotDim.height * 10) / 100;
    plotDim.width -= (plotDim.width * 10) / 100;
    panel.setPreferredSize(plotDim);
    plotPanel.setViewportView(panel);

    revalidate();
    repaint();
}

From source file:datavis.Gui.java

private void updateGraphs_lineGraph(DataList dataset, boolean load) {
    String sItem = "default";
    if (load) {//  w ww  . j a  v a2  s  .c  o m
        sItem = "default";
    } else {
        sItem = jComboBox3.getSelectedItem().toString();
    }

    sItem = sItem.replaceAll("\\s+", "");
    sItem = Character.toLowerCase(sItem.charAt(0)) + (sItem.length() > 1 ? sItem.substring(1) : "");

    jPanel3.removeAll();
    jPanel3.revalidate();

    JFreeChart chart = dataset.getBarGraphChart(sItem);
    chart.removeLegend();
    javax.swing.JPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(jPanel3.getSize());

    jPanel3.add(chartPanel);
    jPanel3.repaint();
}

From source file:datavis.Gui.java

private void updateGraphs_barGraph(DataList dataset, boolean load) {
    String sItem = "default";

    if (load) {/*from   w w  w  .j  av  a  2 s  .  c om*/
        sItem = "default";
    } else {
        sItem = jComboBox2.getSelectedItem().toString();
    }

    sItem = sItem.replaceAll("\\s+", "");
    sItem = Character.toLowerCase(sItem.charAt(0)) + (sItem.length() > 1 ? sItem.substring(1) : "");

    jPanel2.removeAll();
    jPanel2.revalidate();
    JFreeChart chart = dataset.getLineGraphChart(sItem);
    chart.removeLegend();
    javax.swing.JPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(jPanel2.getSize());

    jPanel2.add(chartPanel);
    jPanel2.repaint();

}

From source file:datavis.Gui.java

private void updateGraphs_pieChart(DataList dataset, boolean load) {
    String sItem = "default";

    //If you are initially loading the data..
    if (load) {/*from w w w.j ava  2s . c  o m*/
        sItem = "default"; //Display the default chart
    } else {
        //otherwise, display the chart from the drop-down menu selection
        sItem = jComboBox1.getSelectedItem().toString();
    }

    //modify the string to match what is needed
    //To select the proper graph
    sItem = sItem.replaceAll("\\s+", "");
    sItem = Character.toLowerCase(sItem.charAt(0)) + (sItem.length() > 1 ? sItem.substring(1) : "");

    //Reinit and Add chart to GUI
    jPanel1.removeAll();
    jPanel1.revalidate();
    JFreeChart chart = dataset.getPieChartChart(sItem);
    chart.removeLegend();
    javax.swing.JPanel chartPanel = new ChartPanel(chart);
    chartPanel.setSize(jPanel1.getSize());

    jPanel1.add(chartPanel);
    jPanel1.repaint();

}