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:de.cebitec.readXplorer.plotting.CreatePlots.java

public synchronized static ChartPanel createPlot(Map<PersistentFeature, Pair<Double, Double>> data,
        String xName, String yName, XYToolTipGenerator toolTip) {
    XYSeriesCollection normal = new XYSeriesCollection();
    XYSeries nor = new XYSeries("Normal");
    for (Iterator<PersistentFeature> it = data.keySet().iterator(); it.hasNext();) {
        PersistentFeature key = it.next();
        Pair<Double, Double> pair = data.get(key);
        Double X = pair.getFirst();
        Double Y = pair.getSecond();
        nor.add(new PlotDataItem(key, X, Y));
    }//from  w  w w.  j  av  a2s .c o  m
    normal.addSeries(nor);
    // create subplot 1...
    final XYItemRenderer renderer1 = new XYShapeRenderer();
    renderer1.setBaseToolTipGenerator(toolTip);
    final NumberAxis domainAxis1 = new NumberAxis(xName);
    final NumberAxis rangeAxis1 = new NumberAxis(yName);
    final XYPlot subplot1 = new XYPlot(normal, domainAxis1, rangeAxis1, renderer1);
    JFreeChart chart = new JFreeChart(subplot1);
    chart.removeLegend();
    ChartPanel panel = new ChartPanel(chart, true, false, true, true, true);
    panel.setInitialDelay(0);
    panel.setMaximumDrawHeight(1080);
    panel.setMaximumDrawWidth(1920);
    panel.setMouseWheelEnabled(true);
    panel.setMouseZoomable(true);
    MouseActions mouseAction = new MouseActions();
    panel.addChartMouseListener(mouseAction);
    ChartPanelOverlay overlay = new ChartPanelOverlay(mouseAction);
    panel.addOverlay(overlay);
    return panel;
}

From source file:wsattacker.plugin.intelligentdos.ui.helper.ChartHelper.java

public static JFreeChart createWhiskerChart(SuccessfulAttack sa) {
    BoxAndWhiskerCategoryDataset boxandwhiskercategorydataset = createDataset(sa);
    final BoxAndWhiskerRenderer renderer = new BoxAndWhiskerRenderer();
    renderer.setMaximumBarWidth(0.05);/* w  w  w.ja va2 s .c o m*/
    renderer.setMeanVisible(false);
    renderer.setSeriesPaint(0, Color.GREEN);
    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesPaint(2, Color.BLUE);

    NumberAxis numberAxis = new NumberAxis("duration in ms");
    CategoryPlot categoryplot = new CategoryPlot(boxandwhiskercategorydataset, new CategoryAxis(""), numberAxis,
            renderer);
    categoryplot.setDomainGridlinesVisible(true);
    categoryplot.setRangePannable(true);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    JFreeChart jFreeChart = new JFreeChart("", new Font("SansSerif", Font.BOLD, 14), categoryplot, true);
    jFreeChart.removeLegend();
    return jFreeChart;
}

From source file:org.jfree.graphics2d.demo.SVGPieChartDemo1.java

/**
 * Creates a chart./*www  .  jav  a 2 s.  c o  m*/
 *
 * @param dataset  the dataset.
 *
 * @return A chart.
 */
private static JFreeChart createChart(PieDataset dataset) {

    JFreeChart chart = ChartFactory.createPieChart("Smart Phones Manufactured / Q3 2011", // chart title
            dataset);
    chart.removeLegend();

    // set a custom background for the chart
    chart.setBackgroundPainter(new GradientPainter(new Color(20, 20, 20), RectangleAnchor.TOP_LEFT,
            Color.DARK_GRAY, RectangleAnchor.BOTTOM_RIGHT));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 26));

    PiePlot plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPainter(null);
    plot.setInteriorGap(0.04);
    plot.setBorderPainter(null);

    // use gradients and white borders for the section colours
    plot.setSectionPaint("Others", createGradientPaint(new Color(200, 200, 255), Color.BLUE));
    plot.setSectionPaint("Samsung", createGradientPaint(new Color(255, 200, 200), Color.RED));
    plot.setSectionPaint("Apple", createGradientPaint(new Color(200, 255, 200), Color.GREEN));
    plot.setSectionPaint("Nokia", createGradientPaint(new Color(200, 255, 200), Color.YELLOW));
    plot.setBaseSectionOutlinePaint(Color.WHITE);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(2.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 20));
    plot.setLabelLinkPaint(Color.WHITE);
    plot.setLabelLinkStroke(new BasicStroke(2.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.WHITE);
    plot.setLabelBackgroundPaint(null);
    // add a subtitle giving the data source
    TextTitle source = new TextTitle("Source: http://www.bbc.co.uk/news/business-15489523",
            new Font("Courier New", Font.PLAIN, 12));
    source.setPaint(Color.WHITE);
    source.setPosition(RectangleEdge.BOTTOM);
    source.setHorizontalAlignment(HorizontalAlignment.RIGHT);
    chart.addSubtitle(source);
    return chart;

}

From source file:de.cebitec.readXplorer.plotting.CreatePlots.java

public synchronized static ChartPanel createInfPlot(Map<PersistentFeature, Pair<Double, Double>> data,
        String xName, String yName, XYToolTipGenerator toolTip) {
    XYSeriesCollection normal = new XYSeriesCollection();
    XYSeriesCollection posInf = new XYSeriesCollection();
    XYSeriesCollection negInf = new XYSeriesCollection();
    XYSeries nor = new XYSeries("Normal");
    XYSeries pos = new XYSeries("Positive Infinite");
    XYSeries neg = new XYSeries("Negative Infinite");
    for (Iterator<PersistentFeature> it = data.keySet().iterator(); it.hasNext();) {
        PersistentFeature key = it.next();
        Pair<Double, Double> pair = data.get(key);
        Double X = pair.getFirst();
        Double Y = pair.getSecond();

        if (Y == Double.POSITIVE_INFINITY) {
            Y = 0d;// w ww.j  a  va  2s .c om
            pos.add(new PlotDataItem(key, X, Y));
        }
        if (Y == Double.NEGATIVE_INFINITY) {
            Y = 0d;
            neg.add(new PlotDataItem(key, X, Y));
        }
        if (!Y.isInfinite() && !X.isInfinite()) {
            nor.add(new PlotDataItem(key, X, Y));
        }
    }
    normal.addSeries(nor);
    posInf.addSeries(pos);
    negInf.addSeries(neg);
    JFreeChart chart = createCombinedChart(normal, posInf, negInf, xName, yName, toolTip);
    chart.removeLegend();
    ChartPanel panel = new ChartPanel(chart, true, false, true, true, true);
    panel.setInitialDelay(0);
    panel.setMaximumDrawHeight(1080);
    panel.setMaximumDrawWidth(1920);
    panel.setMouseWheelEnabled(true);
    panel.setMouseZoomable(true);
    MouseActions mouseAction = new MouseActions();
    panel.addChartMouseListener(mouseAction);
    ChartPanelOverlay overlay = new ChartPanelOverlay(mouseAction);
    panel.addOverlay(overlay);
    return panel;
}

From source file:projects.tgas.exec.HrDiagram.java

/**
 * Plot the HR diagram chart from the given data.
 * @param series//ww w  . j ava2s  . c om
 *    A {@link XYSeries} containing the HR diagram data.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getHrChart(XYSeries series) {

    XYSeriesCollection hrData = new XYSeriesCollection();
    hrData.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer hrRenderer = new XYLineAndShapeRenderer();

    hrRenderer.setSeriesLinesVisible(0, false);
    hrRenderer.setSeriesShapesVisible(0, true);
    hrRenderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1));

    // Configure axes
    NumberAxis xAxis = new NumberAxis("B - V [mag]");
    xAxis.setRange(-0.5, 2.25);

    NumberAxis yAxis = new NumberAxis("G [mag]");
    yAxis.setInverted(true);
    yAxis.setRange(-5, 13);

    // Configure plot
    XYPlot xyplot = new XYPlot(hrData, xAxis, yAxis, hrRenderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart hrChart = new JFreeChart("HR diagram of TGAS stars", xyplot);
    hrChart.removeLegend();
    hrChart.setBackgroundPaint(Color.white);

    return hrChart;
}

From source file:org.fhaes.jsea.JSEABarChart.java

/**
 * Creates a demo chart.//from  w  ww  .  j a  va2  s  .  c  o m
 * 
 * @return A chart.
 */
@SuppressWarnings("deprecation")
public static JFreeChart createChart(String title, double[] meanByWindow, int lengthOfWindow,
        int yearsPriorOfEvent, int yearsAfterEvent, double[][] leftEndPointSim, double[][] rightEndPointSim,
        String outputFilePrefix, int alphaLevel, int segmentIndex) {

    JSEABarChart.meanByWindow = meanByWindow;
    JSEABarChart.lengthOfWindow = lengthOfWindow;
    JSEABarChart.yearsPriorOfEvent = yearsPriorOfEvent;
    JSEABarChart.leftEndPointSim = leftEndPointSim;
    JSEABarChart.rightEndPointSim = rightEndPointSim;
    JSEABarChart.alphaLevel = alphaLevel;

    CategoryPlot plot = new CategoryPlot();
    plot.setDataset(0, createDataset());
    plot.setOrientation(PlotOrientation.VERTICAL);

    CustomBarRenderer renderer = new CustomBarRenderer(createPaint(lengthOfWindow, Color.gray));
    renderer.setBarPainter(new StandardBarPainter());
    renderer.setDrawBarOutline(false);
    renderer.setOutlinePaint(Color.yellow);
    renderer.setOutlineStroke(new BasicStroke(1.1f, BasicStroke.JOIN_ROUND, BasicStroke.JOIN_BEVEL));
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.CENTER_HORIZONTAL));
    plot.setRenderer(0, renderer);
    Color allcolors[] = { Color.red, Color.green, Color.blue };

    System.out.println("here is the alphlevel " + alphaLevel);
    // for (int k = 0; k <= 5; k++) {
    // if (k <= 2) {
    // / plot.setDataset(k + 1, createEndDataset(k, true));
    // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k], k));
    // } else {
    // plot.setDataset(k + 1, createEndDataset(k - 3, false));
    // plot.setRenderer(k + 1, createCategoryItemRenderer(allcolors[k - 3], k - 3));
    // }
    // }
    // for (int k = 0; k <1; k++) {
    // if (k <= 2) {
    plot.setDataset(1, createEndDataset(alphaLevel, true));
    plot.setRenderer(1, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel));
    // } else {
    plot.setDataset(4, createEndDataset(alphaLevel, false));
    plot.setRenderer(4, createCategoryItemRenderer(allcolors[alphaLevel], alphaLevel));
    // }
    // }
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    // plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainAxis(new CategoryAxis("LAG"));

    plot.addRangeMarker(new ValueMarker(0));

    plot.setRangeAxis(new NumberAxis(outputFilePrefix));
    plot.setRangeGridlinesVisible(true);

    JFreeChart chart = new JFreeChart(plot);
    chart.setTitle(title);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.WHITE);

    return chart;
}

From source file:projects.hip.exec.HrDiagram.java

/**
 * Plot the HR diagram chart from the given data.
 * @param series//  w w  w. j a v  a2s .c o  m
 *    A {@link XYSeries} containing the HR diagram data.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getHrChart(XYSeries series) {

    XYSeriesCollection hrData = new XYSeriesCollection();
    hrData.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer hrRenderer = new XYLineAndShapeRenderer();

    hrRenderer.setSeriesLinesVisible(0, false);
    hrRenderer.setSeriesShapesVisible(0, true);
    hrRenderer.setSeriesShape(0, new Ellipse2D.Double(-0.5, -0.5, 1, 1));

    // Configure axes
    NumberAxis xAxis = new NumberAxis("B - V [mag]");
    xAxis.setRange(-0.5, 2.25);

    NumberAxis yAxis = new NumberAxis("H [mag]");
    yAxis.setInverted(true);
    yAxis.setRange(-5, 13);

    // Configure plot
    XYPlot xyplot = new XYPlot(hrData, xAxis, yAxis, hrRenderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart hrChart = new JFreeChart("HR diagram of Hipparcos stars", xyplot);
    hrChart.removeLegend();
    hrChart.setBackgroundPaint(Color.white);

    return hrChart;
}

From source file:projects.hip.exec.HrDiagram.java

/**
 * Plot the distribution of distance of all objects.
 * @param d_hist/*from ww  w. j av a 2s. c  o m*/
 *    The array containing the distance distribution histogram.
 * @return
 *    A {@link JFreeChart} containing the plot.
 */
private static JFreeChart getDistanceChart(double[] d_hist) {

    XYSeries series = new XYSeries("Distance distribution");

    for (int i = 0; i < d_hist.length; i++) {
        // Centre of this distance bin
        double d = d_min + i * d_step + d_step / 2.0;
        series.add(d, d_hist[i]);
    }
    XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(series);

    // Set up the renderer
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, false);

    // Configure axes
    NumberAxis xAxis = new NumberAxis("Distance [pc]");
    xAxis.setRange(d_min, d_max);

    NumberAxis yAxis = new NumberAxis("Number of objects");
    yAxis.setAutoRangeIncludesZero(true);

    // Configure plot
    XYPlot xyplot = new XYPlot(data, xAxis, yAxis, renderer);
    xyplot.setBackgroundPaint(Color.white);

    JFreeChart dChart = new JFreeChart("Distance distribution of Hipparcos stars", xyplot);
    dChart.removeLegend();
    dChart.setBackgroundPaint(Color.white);

    return dChart;
}

From source file:org.spf4j.perf.impl.chart.Charts.java

public static JFreeChart createHeatJFreeChart(final String[] dsNames, final double[][] values,
        final long startTimeMillis, final long stepMillis, final String uom, final String chartName) {
    final QuantizedXYZDatasetImpl dataSet = new QuantizedXYZDatasetImpl(dsNames, values, startTimeMillis,
            stepMillis);/*from  w  w  w. ja v a  2 s.  com*/
    NumberAxis xAxis = new NumberAxis("Time");
    xAxis.setStandardTickUnits(dataSet.createXTickUnits());
    xAxis.setLowerMargin(0);
    xAxis.setUpperMargin(0);
    xAxis.setVerticalTickLabels(true);
    NumberAxis yAxis = new NumberAxis(uom);
    yAxis.setStandardTickUnits(dataSet.createYTickUnits());
    yAxis.setLowerMargin(0);
    yAxis.setUpperMargin(0);
    XYBlockRenderer renderer = new XYBlockRenderer();
    PaintScale scale;
    if (dataSet.getMinValue() >= dataSet.getMaxValue()) {
        if (dataSet.getMinValue() == Double.POSITIVE_INFINITY) {
            scale = new InverseGrayScale(0, 1);
        } else {
            scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue() + 1);
        }
    } else {
        scale = new InverseGrayScale(dataSet.getMinValue(), dataSet.getMaxValue());
    }
    renderer.setPaintScale(scale);
    renderer.setBlockWidth(1);
    renderer.setBlockHeight(1);
    XYPlot plot = new XYPlot(dataSet, xAxis, yAxis, renderer);
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);
    plot.setRangeMinorGridlinesVisible(false);
    JFreeChart chart = new JFreeChart(chartName, plot);
    PaintScaleLegend legend = new PaintScaleLegend(scale, new NumberAxis("Count"));
    legend.setMargin(0, 5, 0, 5);
    chart.addSubtitle(legend);
    chart.removeLegend();
    chart.setBackgroundPaint(Color.white);
    return chart;
}

From source file:ImageProcessing.ImageProcessing.java

public static JFreeChart createHistogram(double[] dataset_values, Color barColor) {
    //Creates a histogram based on passed values and bar colors.        
    HistogramDataset dataset = new HistogramDataset();
    dataset.addSeries("Values", dataset_values, 255, 0, 255);

    JFreeChart chart = ChartFactory.createHistogram(null, //Title
            null, //X Label
            null, //Y Label
            dataset, //Dataset
            org.jfree.chart.plot.PlotOrientation.VERTICAL, //Plot orientation
            true, false, false); //Other details

    //Remove chart legends to save space, we don't really need them anyway
    chart.removeLegend();
    //Set bar colors according to the parameter passed.
    XYItemRenderer renderer = chart.getXYPlot().getRenderer();
    renderer.setSeriesPaint(0, barColor);
    //Set background to null (the background will be similar to frame color in display.
    chart.setBackgroundPaint(null);/*from  w w  w .j  av  a2s.  com*/

    return chart;
}