Example usage for org.jfree.chart.title LegendTitle setFrame

List of usage examples for org.jfree.chart.title LegendTitle setFrame

Introduction

In this page you can find the example usage for org.jfree.chart.title LegendTitle setFrame.

Prototype

public void setFrame(BlockFrame frame) 

Source Link

Document

Sets the frame (or border).

Usage

From source file:com.mgmtp.perfload.perfalyzer.reportpreparation.PlotCreator.java

public JFreeChart createPlot(final AxisType xAxisType, final AxisType yAxisType,
        final RendererType rendererType, final DisplayData displayData, final DataRange dataRange,
        boolean showMarkers, final NumberDataSet... dataSets) {

    NumberAxis xAxis = createAxis(xAxisType, resourceBundle.getString(displayData.getUnitX()));

    XYPlot plot;/*  w  w w. ja  v  a2  s  .  com*/
    if (dataSets.length == 1) {
        NumberAxis yAxis = createAxis(yAxisType, resourceBundle.getString(displayData.getUnitY()));
        plot = new XYPlot(dataSets[0], xAxis, yAxis, rendererType.createRenderer());
    } else {
        CombinedDomainXYPlot combinedPlot = new CombinedDomainXYPlot(xAxis);
        for (int i = 0; i < dataSets.length; ++i) {
            NumberDataSet dataSet = dataSets[i];
            // no range for y-axis!
            NumberAxis yAxis = createAxis(yAxisType,
                    resourceBundle.getString(displayData.getUnitYList().get(i)));
            XYPlot subPlot = new XYPlot(dataSet, null, yAxis, rendererType.createRenderer());
            combinedPlot.add(subPlot);
            formatPlot(subPlot);
        }
        plot = combinedPlot;
    }

    JFreeChart chart = new JFreeChart(plot);
    CHART_THEME.apply(chart);

    formatPlot(plot);

    if (showMarkers) {
        for (Marker marker : markers) {
            IntervalMarker im = new IntervalMarker(marker.getLeftMillis() / 1000L,
                    marker.getRightMillis() / 1000L);
            im.setLabel(marker.getName());
            im.setLabelFont(new Font("Sans Serif", Font.ITALIC | Font.BOLD, 14));
            im.setLabelAnchor(RectangleAnchor.TOP);
            im.setLabelOffset(new RectangleInsets(8d, 0d, 0d, 0d));
            im.setLabelPaint(Color.BLACK);
            im.setAlpha(.2f);
            im.setPaint(Color.WHITE);
            im.setOutlinePaint(Color.BLACK);
            im.setOutlineStroke(new BasicStroke(1.0f));
            plot.addDomainMarker(im, Layer.BACKGROUND);
        }
    }

    LegendTitle legend = chart.getLegend();
    legend.setBackgroundPaint(new Color(229, 229, 229));
    legend.setFrame(
            new LineBorder(new Color(213, 213, 213), new BasicStroke(1.0f), legend.getFrame().getInsets()));

    // only for non-logarithmic axes
    // range must be set after plot is created, otherwise nothing is drawn
    if (dataRange != null && !xAxisType.equals(AxisType.LOGARITHMIC)) {
        xAxis.setRange(dataRange.getLowerSeconds(), dataRange.getUpperSeconds());
    }

    return chart;
}

From source file:no.met.jtimeseries.marinogram.MarinogramTemperaturePlot.java

private XYPlot createPlot(TimeZone timezone, boolean plotAirTemp, boolean plotWaterTemp,
        boolean plotDewpointTemp) throws ParseException {
    Date startTime = null;/*from ww w . j a  v a 2  s  .  c o m*/
    NumberPhenomenon aTemperature = null;
    NumberPhenomenon wTemperature = null;
    NumberPhenomenon dTemperature = null;
    // default setting
    ChartPlotter plotter = new ChartPlotter();
    plotter.setHeight(this.getHeight());
    plotter.setWidth(this.getWidth());
    plotter.setPlotDefaultProperties("", "");

    double minValue = 100;
    double maxValue = -100;
    int plotIndex = 0;
    if (plotAirTemp) {
        aTemperature = getLocationForecastDataModel().getPhenomenen(PhenomenonName.AirTemperature.toString(),
                NumberPhenomenon.class);
        minValue = aTemperature.getMinValue() < minValue ? aTemperature.getMinValue() : minValue;
        maxValue = aTemperature.getMaxValue() > maxValue ? aTemperature.getMaxValue() : maxValue;
        startTime = aTemperature.getTime().get(0);
        plotTemperature(plotter, aTemperature, new BasicStroke(2.0f), Color.RED,
                messages.getString("label.air"), true);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(1, true);
        plotIndex++;
    }

    if (plotWaterTemp) {
        wTemperature = getOceanForecastDataModel().getPhenomenen(PhenomenonName.seaTemperature.toString(),
                NumberPhenomenon.class);
        // only plot water temperature if it is availbe for this location
        if (wTemperature != null) {
            minValue = wTemperature.getMinValue() < minValue ? wTemperature.getMinValue() : minValue;
            maxValue = wTemperature.getMaxValue() > maxValue ? wTemperature.getMaxValue() : maxValue;
            startTime = wTemperature.getTime().get(0);
            BasicStroke dottedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { 2.0f, 6.0f }, 0.0f);
            plotTemperature(plotter, wTemperature, dottedStroke, Color.RED, messages.getString("label.water"),
                    true);
            plotter.getPlot().getRenderer(plotIndex++).setSeriesVisibleInLegend(0, true);
        }
    }

    if (plotDewpointTemp) {
        dTemperature = getLocationForecastDataModel()
                .getPhenomenen(PhenomenonName.dewPointTemperature.toString(), NumberPhenomenon.class);
        minValue = dTemperature.getMinValue() < minValue ? dTemperature.getMinValue() : minValue;
        maxValue = dTemperature.getMaxValue() > maxValue ? dTemperature.getMaxValue() : maxValue;
        startTime = dTemperature.getTime().get(0);
        plotTemperature(plotter, dTemperature, new BasicStroke(2.0f), Color.ORANGE,
                messages.getString("label.dewpoint"), false);
        plotter.getPlot().getRenderer(plotIndex).setSeriesVisibleInLegend(0, true);
    }

    double tick = (maxValue - minValue) / 3.5;
    tick = Math.ceil(tick);
    double lowBound = Math.floor(minValue / (tick)) * (tick);
    lowBound = lowBound - tick / 2;
    double upperBound = lowBound + tick * 7;

    // set range axis
    NumberAxis numberAxis = new NumberAxis();
    numberAxis.setLabelPaint(Color.RED);
    numberAxis.setTickLabelPaint(Color.RED);
    numberAxis.setLabel(messages.getString("parameter.temperature") + " (\u00B0 C)");
    numberAxis.setTickUnit(new NumberTickUnit(tick));
    numberAxis.setLowerBound(lowBound);
    numberAxis.setUpperBound(upperBound);

    //Set left axis and right axis
    plotter.getPlot().setRangeAxis(0, numberAxis);
    plotter.getPlot().setRangeAxis(1, numberAxis);
    //Set the third axis and hide the third axis
    if (plotAirTemp && plotWaterTemp && plotDewpointTemp) {
        NumberAxis numberAxis2 = new NumberAxis();
        numberAxis2.setTickUnit(new NumberTickUnit(tick));
        numberAxis2.setLowerBound(lowBound);
        numberAxis2.setUpperBound(upperBound);
        plotter.getPlot().setRangeAxis(2, numberAxis2);
        plotter.getPlot().getRangeAxis(2).setVisible(false);
    }

    //Show legend at the top right position of the plot
    LegendTitle lt = new LegendTitle(plotter.getPlot());
    lt.setItemFont(new Font("Dialog", Font.PLAIN, 9));
    lt.setBackgroundPaint(new Color(255, 255, 255, 100));
    lt.setFrame(new BlockBorder(Color.white));
    lt.setPosition(RectangleEdge.TOP);
    XYTitleAnnotation ta = new XYTitleAnnotation(0.99, 0.95, lt, RectangleAnchor.TOP_RIGHT);
    plotter.getPlot().addAnnotation(ta);

    // set domain range after (must) plot all the data
    plotter.addHourBasedDomainGridLines();
    // add markers
    plotter.addDomainMarkers(getShortTermTime(startTime), timezone, locale);
    Date minDate = getShortTermTime(startTime).get(0);
    Date maxDate = getShortTermTime(startTime).get(getShortTermTime(startTime).size() - 1);
    plotter.setDomainRange(minDate, maxDate);
    plotter.setDomainDateFormat(timezone, "HH");
    plotter.getPlot().setOutlineVisible(true);
    // invisible the domain i.e, x axis
    plotter.getPlot().getDomainAxis().setTickLabelsVisible(false);

    return plotter.getPlot();

}

From source file:com.ikon.servlet.admin.StatsGraphServlet.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    String action = WebUtils.getString(request, "action", "graph");
    String type = WebUtils.getString(request, "t");
    JFreeChart chart = null;/*w w w .j av a 2 s. com*/
    updateSessionManager(request);

    try {
        if ("refresh".equals(action)) {
            new RepositoryInfo().runAs(null);
            ServletContext sc = getServletContext();
            sc.getRequestDispatcher("/admin/stats.jsp").forward(request, response);
        } else {
            response.setContentType("image/png");
            OutputStream out = response.getOutputStream();

            if (DOCUMENTS.equals(type) || DOCUMENTS_SIZE.equals(type) || FOLDERS.equals(type)) {
                chart = repoStats(type);
            } else if (DISK.equals(type)) {
                chart = diskStats();
            } else if (JVM_MEMORY.equals(type)) {
                chart = jvmMemStats();
            } else if (OS_MEMORY.equals(type)) {
                chart = osMemStats();
            }

            if (chart != null) {
                // Customize title font
                chart.getTitle().setFont(new Font("Tahoma", Font.BOLD, 16));

                // Match body {   background-color:#F6F6EE; }
                chart.setBackgroundPaint(new Color(246, 246, 238));

                // Customize no data
                PiePlot plot = (PiePlot) chart.getPlot();
                plot.setNoDataMessage("No data to display");

                // Customize labels
                plot.setLabelGenerator(null);

                // Customize legend
                LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
                legend.setPosition(RectangleEdge.BOTTOM);
                legend.setFrame(BlockBorder.NONE);
                legend.setItemFont(new Font("Tahoma", Font.PLAIN, 12));
                chart.removeLegend();
                chart.addLegend(legend);

                if (DISK.equals(type) || JVM_MEMORY.equals(type) || OS_MEMORY.equals(type)) {
                    ChartUtilities.writeChartAsPNG(out, chart, 225, 225);
                } else {
                    ChartUtilities.writeChartAsPNG(out, chart, 250, 250);
                }
            }

            out.flush();
            out.close();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:ecosim.gui.SummaryPane.java

/**
 *  Private method to build the binning chart.
 *
 *  @return A ChartPanel containing the binning chart.
 *//*from www.j  a  va  2s  .com*/
private ChartPanel makeBinningChart() {
    final DefaultXYDataset binData = new DefaultXYDataset();
    final NumberFormat nf = NumberFormat.getInstance();
    final NumberAxis xAxis = new NumberAxis("Sequence identity criterion");
    nf.setMinimumFractionDigits(2);
    xAxis.setLowerBound(Binning.binLevels[0]);
    xAxis.setUpperBound(1.0D);
    xAxis.setTickUnit(new NumberTickUnit(0.05D, nf));
    LogAxis yAxis = new LogAxis("Number of bins");
    yAxis.setBase(2.0D);
    yAxis.setNumberFormatOverride(NumberFormat.getInstance());
    yAxis.setTickUnit(new NumberTickUnit(2.0D));
    yAxis.setMinorTickMarksVisible(true);
    yAxis.setAutoRangeMinimumSize(4.0D);
    yAxis.setSmallestValue(1.0D);
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
    for (int i = 0; i < seriesColors.length; i++) {
        renderer.setSeriesPaint(i, seriesColors[i]);
        renderer.setSeriesStroke(i, new BasicStroke(seriesStroke[i]));
    }
    XYPlot plot = new XYPlot(binData, xAxis, yAxis, renderer);
    JFreeChart binChart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    binChart.setPadding(new RectangleInsets(0.0D, 0.0D, 0.0D, 10.0D));
    LegendTitle legend = new LegendTitle(plot);
    legend.setMargin(new RectangleInsets(1.0D, 1.0D, 1.0D, 1.0D));
    legend.setFrame(new LineBorder());
    legend.setBackgroundPaint(Color.white);
    legend.setPosition(RectangleEdge.BOTTOM);
    plot.addAnnotation(new XYTitleAnnotation(0.001D, 0.999D, legend, RectangleAnchor.TOP_LEFT));
    final ChartPanel pane = new ChartPanel(binChart, false, true, true, false, false);
    // Watch for changes to the Summary object.
    summary.addObserver(new Observer() {
        public void update(Observable o, Object obj) {
            Summary s = (Summary) obj;
            ParameterEstimate estimate = s.getEstimate();
            ArrayList<BinLevel> bins = s.getBins();
            if (bins.size() > 0) {
                double[][] values = new double[2][bins.size()];
                Double low = 1.0d;
                for (int i = 0; i < bins.size(); i++) {
                    BinLevel bin = bins.get(i);
                    values[0][i] = bin.getCrit();
                    values[1][i] = bin.getLevel();
                    if (values[0][i] < low)
                        low = values[0][i];
                }
                binData.addSeries("sequences", values);
                xAxis.setLowerBound(low);
                if (low > 0.95d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.005D, nf));
                } else if (low > 0.90d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.010D, nf));
                } else if (low > 0.80d - MasterVariables.EPSILON) {
                    xAxis.setTickUnit(new NumberTickUnit(0.025D, nf));
                }
                if (estimate != null) {
                    double[][] omega = new double[2][bins.size()];
                    double[][] sigma = new double[2][bins.size()];
                    double[] omegaLine = estimate.getOmega();
                    double[] sigmaLine = estimate.getSigma();
                    for (int i = 0; i < bins.size(); i++) {
                        double crit = 1.0D - values[0][i];
                        double snp = s.getLength() * crit;
                        omega[0][i] = values[0][i];
                        sigma[0][i] = values[0][i];
                        omega[1][i] = Math.pow(2.0D, snp * omegaLine[0] + omegaLine[1]);
                        sigma[1][i] = Math.pow(2.0D, snp * sigmaLine[0] + sigmaLine[1]);
                    }
                    if (-1.0D * omegaLine[0] > MasterVariables.EPSILON) {
                        binData.addSeries("omega", omega);
                    }
                    if (-1.0D * sigmaLine[0] > MasterVariables.EPSILON) {
                        binData.addSeries("sigma", sigma);
                    }
                }
                // Repaint the summary pane.
                pane.repaint();
            }
        }
    });
    return pane;
}

From source file:com.rapidminer.gui.plotter.charts.AbstractBarChartPlotter.java

public void paintBarChart(Graphics graphics) {
    int categoryCount = prepareData();
    String groupByName = groupByColumn >= 0 ? dataTable.getColumnName(groupByColumn) : null;
    String valueName = valueColumn >= 0 ? dataTable.getColumnName(valueColumn) : null;
    String maxClassesProperty = System.getProperty(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {//from  ww  w  .j a v  a  2  s . c o m
        if (maxClassesProperty != null)
            maxClasses = Integer.parseInt(maxClassesProperty);
    } catch (NumberFormatException e) {
        LogService.getGlobal().log(
                "Bar Chart plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
                LogService.WARNING);
    }
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

    if (categoryCount <= MAX_CATEGORIES) {
        JFreeChart chart = createChart(categoryDataSet, groupByName, valueName, createLegend);

        // set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        // legend settings
        LegendTitle legend = chart.getLegend();
        if (legend != null) {
            legend.setPosition(RectangleEdge.TOP);
            legend.setFrame(BlockBorder.NONE);
            legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        }

        Rectangle2D drawRect = new Rectangle2D.Double(0, 0, getWidth(), getHeight());
        chart.draw((Graphics2D) graphics, drawRect);
    } else {
        graphics.drawString("Too many columns (" + categoryCount + "), this chart is only able to plot up to "
                + MAX_CATEGORIES + " different categories", MARGIN, MARGIN);
    }
}

From source file:net.sf.mzmine.modules.visualization.spectra.SpectraPlot.java

public SpectraPlot(ActionListener masterPlot) {

    super(null, true);

    setBackground(Color.white);//from  w w w .ja  v a 2 s  .  c  om
    setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));

    // initialize the chart by default time series chart from factory
    chart = ChartFactory.createXYLineChart("", // title
            "m/z", // x-axis label
            "Intensity", // y-axis label
            null, // data set
            PlotOrientation.VERTICAL, // orientation
            true, // isotopeFlag, // create legend?
            true, // generate tooltips?
            false // generate URLs?
    );
    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    chartSubTitle = new TextTitle();
    chartSubTitle.setFont(subTitleFont);
    chartSubTitle.setMargin(5, 0, 0, 0);
    chart.addSubtitle(chartSubTitle);

    // legend constructed by ChartFactory
    LegendTitle legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // disable maximum size (we don't want scaling)
    setMaximumDrawWidth(Integer.MAX_VALUE);
    setMaximumDrawHeight(Integer.MAX_VALUE);
    setMinimumDrawHeight(0);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));

    // set rendering order
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);

    NumberFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    NumberFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();

    // set the X axis (retention time) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setNumberFormatOverride(mzFormat);
    xAxis.setUpperMargin(0.001);
    xAxis.setLowerMargin(0.001);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setNumberFormatOverride(intensityFormat);

    // set focusable state to receive key events
    setFocusable(true);

    // register key handlers
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("LEFT"), masterPlot, "PREVIOUS_SCAN");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke("RIGHT"), masterPlot, "NEXT_SCAN");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke('+'), this, "ZOOM_IN");
    GUIUtils.registerKeyHandler(this, KeyStroke.getKeyStroke('-'), this, "ZOOM_OUT");

    // add items to popup menu
    if (masterPlot instanceof SpectraVisualizerWindow) {
        JPopupMenu popupMenu = getPopupMenu();

        popupMenu.addSeparator();

        GUIUtils.addMenuItem(popupMenu, "Toggle centroid/continuous mode", masterPlot, "TOGGLE_PLOT_MODE");
        GUIUtils.addMenuItem(popupMenu, "Toggle displaying of data points in continuous mode", masterPlot,
                "SHOW_DATA_POINTS");
        GUIUtils.addMenuItem(popupMenu, "Toggle displaying of peak values", masterPlot, "SHOW_ANNOTATIONS");
        GUIUtils.addMenuItem(popupMenu, "Toggle displaying of picked peaks", masterPlot, "SHOW_PICKED_PEAKS");

        popupMenu.addSeparator();

        GUIUtils.addMenuItem(popupMenu, "Set axes range", masterPlot, "SETUP_AXES");

        GUIUtils.addMenuItem(popupMenu, "Set same range to all windows", masterPlot, "SET_SAME_RANGE");

        popupMenu.addSeparator();

        GUIUtils.addMenuItem(popupMenu, "Add isotope pattern", masterPlot, "ADD_ISOTOPE_PATTERN");
    }

}

From source file:com.rapidminer.gui.plotter.DistributionPlotter.java

public void paintComponent(Graphics graphics, int width, int height) {
    preparePlots();/*from  w  ww.j a  v a2s . co  m*/
    if (plot) {
        JFreeChart chart = null;
        try {
            if (!Double.isNaN(model.getUpperBound(plotColumn))) {
                chart = createNumericalChart();
            } else {
                chart = createNominalChart();
            }
        } catch (Exception e) {
            // do nothing - just do not draw the chart
        }

        if (chart != null) {
            // set the background color for the chart...
            chart.setBackgroundPaint(Color.white);

            // legend settings
            LegendTitle legend = chart.getLegend();
            if (legend != null) {
                legend.setPosition(RectangleEdge.TOP);
                legend.setFrame(BlockBorder.NONE);
                legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
            }
            Rectangle2D drawRect = new Rectangle2D.Double(0, 0, width, height);
            chart.draw((Graphics2D) graphics, drawRect);
        }
    }
}

From source file:io.github.mzmine.modules.plots.chromatogram.ChromatogramPlotWindowController.java

@FXML
public void initialize() {

    final JFreeChart chart = chartNode.getChart();
    final XYPlot plot = chart.getXYPlot();

    // Do not set colors and strokes dynamically. They are instead provided
    // by the dataset and configured in configureRenderer()
    plot.setDrawingSupplier(null);//from   ww w .j  a va2s .c  o  m
    plot.setDomainGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setRangeGridlinePaint(JavaFXUtil.convertColorToAWT(gridColor));
    plot.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setDomainCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor));
    plot.setRangeCrosshairPaint(JavaFXUtil.convertColorToAWT(crossHairColor));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    // chart properties
    chart.setBackgroundPaint(JavaFXUtil.convertColorToAWT(backgroundColor));

    // legend properties
    LegendTitle legend = chart.getLegend();
    // legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the X axis (retention time) properties
    NumberAxis xAxis = (NumberAxis) plot.getDomainAxis();
    xAxis.setLabel("Retention time (min)");
    xAxis.setUpperMargin(0.03);
    xAxis.setLowerMargin(0.03);
    xAxis.setRangeType(RangeType.POSITIVE);
    xAxis.setTickLabelInsets(new RectangleInsets(0, 0, 20, 20));

    // set the Y axis (intensity) properties
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setLabel("Intensity");
    yAxis.setRangeType(RangeType.POSITIVE);
    yAxis.setAutoRangeIncludesZero(true);

    // set the fixed number formats, because otherwise JFreeChart sometimes
    // shows exponent, sometimes it doesn't
    DecimalFormat mzFormat = MZmineCore.getConfiguration().getMZFormat();
    xAxis.setNumberFormatOverride(mzFormat);
    DecimalFormat intensityFormat = MZmineCore.getConfiguration().getIntensityFormat();
    yAxis.setNumberFormatOverride(intensityFormat);

    chartTitle = chartNode.getChart().getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);
    chartTitle.setText("Chromatogram");

    chartNode.setCursor(Cursor.CROSSHAIR);

    // Remove the dataset if it is removed from the list
    datasets.addListener((Change<? extends ChromatogramPlotDataSet> c) -> {
        while (c.next()) {
            if (c.wasRemoved()) {
                for (ChromatogramPlotDataSet ds : c.getRemoved()) {
                    int index = plot.indexOf(ds);
                    plot.setDataset(index, null);
                }
            }
        }
    });

    itemLabelsVisible.addListener((prop, oldVal, newVal) -> {
        for (ChromatogramPlotDataSet dataset : datasets) {
            int datasetIndex = plot.indexOf(dataset);
            XYItemRenderer renderer = plot.getRenderer(datasetIndex);
            renderer.setBaseItemLabelsVisible(newVal);
        }
    });

    legendVisible.addListener((prop, oldVal, newVal) -> {
        legend.setVisible(newVal);
    });
}

From source file:iDynoOptimizer.MOEAFramework26.src.org.moeaframework.analysis.diagnostics.LinePlot.java

@Override
protected void update() {
    XYDataset dataset = null;/*from w w w.  jav a 2  s .c  o  m*/

    //generate the plot data
    if (controller.getShowIndividualTraces()) {
        dataset = new DefaultTableXYDataset();

        for (ResultKey key : frame.getSelectedResults()) {
            generateIndividualSeries(key, (DefaultTableXYDataset) dataset);
        }
    } else {
        dataset = new YIntervalSeriesCollection();

        for (ResultKey key : frame.getSelectedResults()) {
            generateQuantileSeries(key, (YIntervalSeriesCollection) dataset);
        }
    }

    //create the chart
    JFreeChart chart = ChartFactory.createXYLineChart(metric, localization.getString("text.NFE"),
            localization.getString("text.value"), dataset, PlotOrientation.VERTICAL, false, true, false);
    final XYPlot plot = chart.getXYPlot();

    //setup the series renderer
    if (controller.getShowIndividualTraces()) {
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);

        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

            renderer.setSeriesStroke(i, new BasicStroke(1f, 1, 1));
            renderer.setSeriesPaint(i, paint);
        }

        plot.setRenderer(renderer);
    } else {
        DeviationRenderer renderer = new DeviationRenderer(true, false);

        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            Paint paint = frame.getPaintHelper().get(dataset.getSeriesKey(i));

            renderer.setSeriesStroke(i, new BasicStroke(3f, 1, 1));
            renderer.setSeriesPaint(i, paint);
            renderer.setSeriesFillPaint(i, paint);
        }

        plot.setRenderer(renderer);
    }

    //create the legend
    final LegendItemCollection items = plot.getLegendItems();
    Iterator<?> iterator = items.iterator();
    Set<ResultKey> uniqueKeys = new HashSet<ResultKey>();

    while (iterator.hasNext()) {
        LegendItem item = (LegendItem) iterator.next();

        if (uniqueKeys.contains(item.getSeriesKey())) {
            iterator.remove();
        } else {
            uniqueKeys.add((ResultKey) item.getSeriesKey());
        }
    }

    LegendItemSource source = new LegendItemSource() {

        @Override
        public LegendItemCollection getLegendItems() {
            return items;
        }

    };

    LegendTitle legend = new LegendTitle(source);
    legend.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    legend.setFrame(new LineBorder());
    legend.setBackgroundPaint(Color.WHITE);
    legend.setPosition(RectangleEdge.BOTTOM);
    chart.addLegend(legend);

    //scale the axes
    final NumberAxis domainAxis = new NumberAxis();
    domainAxis.setAutoRange(true);
    plot.setDomainAxis(domainAxis);

    //add overlay
    if (controller.getShowLastTrace() && !controller.getShowIndividualTraces()
            && (controller.getLastAccumulator() != null)
            && controller.getLastAccumulator().keySet().contains(metric)) {
        DefaultTableXYDataset dataset2 = new DefaultTableXYDataset();
        XYSeries series = new XYSeries(localization.getString("text.last"), false, false);

        for (int i = 0; i < controller.getLastAccumulator().size(metric); i++) {
            series.add((Number) controller.getLastAccumulator().get("NFE", i),
                    (Number) controller.getLastAccumulator().get(metric, i));
        }

        dataset2.addSeries(series);

        XYLineAndShapeRenderer renderer2 = new XYLineAndShapeRenderer(true, false);
        renderer2.setSeriesStroke(0, new BasicStroke(1f, 1, 1));
        renderer2.setSeriesPaint(0, Color.BLACK);

        plot.setDataset(1, dataset2);
        plot.setRenderer(1, renderer2);
        plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    }

    //update the chart in the GUI
    removeAll();
    add(new ChartPanel(chart), BorderLayout.CENTER);
    revalidate();
    repaint();
}

From source file:com.rapidminer.gui.plotter.charts.DeviationChartPlotter.java

@Override
public void updatePlotter() {
    int categoryCount = prepareData();
    String maxClassesProperty = ParameterService
            .getParameterValue(MainFrame.PROPERTY_RAPIDMINER_GUI_PLOTTER_COLORS_CLASSLIMIT);
    int maxClasses = 20;
    try {/*from w  ww .  j a  v a2 s .  com*/
        if (maxClassesProperty != null) {
            maxClasses = Integer.parseInt(maxClassesProperty);
        }
    } catch (NumberFormatException e) {
        // LogService.getGlobal().log("Deviation plotter: cannot parse property 'rapidminer.gui.plotter.colors.classlimit', using maximal 20 different classes.",
        // LogService.WARNING);
        LogService.getRoot().log(Level.WARNING,
                "com.rapidminer.gui.plotter.charts.DeviationChartPlotter.parsing_property_error");
    }
    boolean createLegend = categoryCount > 0 && categoryCount < maxClasses;

    JFreeChart chart = createChart(this.dataset, createLegend);

    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);

    // domain axis
    SymbolAxis axis = null;
    if (this.dataTable.isSupportingColumnWeights()) {
        List<Double> weightList = new LinkedList<Double>();
        for (int column = 0; column < dataTable.getNumberOfColumns(); column++) {
            if (!dataTable.isSpecial(column) && column != colorColumn) {
                weightList.add(this.dataTable.getColumnWeight(column));
            }
        }
        double[] weights = new double[weightList.size()];
        int index = 0;
        for (Double d : weightList) {
            weights[index++] = d;
        }
        axis = new WeightBasedSymbolAxis(null, domainAxisMap, weights);
    } else {
        axis = new SymbolAxis(null, domainAxisMap);
    }
    axis.setTickLabelFont(LABEL_FONT);
    axis.setLabelFont(LABEL_FONT_BOLD);

    // rotate labels
    if (isLabelRotating()) {
        axis.setTickLabelsVisible(true);
        axis.setVerticalTickLabels(true);
    }

    chart.getXYPlot().setDomainAxis(axis);

    // legend settings
    LegendTitle legend = chart.getLegend();
    if (legend != null) {
        legend.setPosition(RectangleEdge.TOP);
        legend.setFrame(BlockBorder.NONE);
        legend.setHorizontalAlignment(HorizontalAlignment.LEFT);
        legend.setItemFont(LABEL_FONT);
    }

    if (panel instanceof AbstractChartPanel) {
        panel.setChart(chart);
    } else {
        panel = new AbstractChartPanel(chart, getWidth(), getHeight() - MARGIN);
        final ChartPanelShiftController controller = new ChartPanelShiftController(panel);
        panel.addMouseListener(controller);
        panel.addMouseMotionListener(controller);
    }

    // ATTENTION: WITHOUT THIS WE GET SEVERE MEMORY LEAKS!!!
    panel.getChartRenderingInfo().setEntityCollection(null);
}