Example usage for org.jfree.chart ChartFactory createScatterPlot

List of usage examples for org.jfree.chart ChartFactory createScatterPlot

Introduction

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

Prototype

public static JFreeChart createScatterPlot(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a scatter plot with default settings.

Usage

From source file:com.diversityarrays.kdxplore.scatterplot.ScatterPlotPanel.java

private void generateChart(boolean recreateDataSet, Bag<String> missingOrBad, Bag<String> suppressed) {

    if (recreateDataSet) {
        currentDataSet = createSampleDataSet(missingOrBad, suppressed);
    }/*  www. j a  v a  2 s  .  c  om*/

    XYSeriesCollection dataset = currentDataSet;

    PlotOrientation orientation = PlotOrientation.VERTICAL;
    boolean show = true;
    boolean toolTips = true;
    boolean urls = true;

    chart = ChartFactory.createScatterPlot(getTitle(), xAxisName, yAxisName, dataset, orientation, show,
            toolTips, urls);

    if (DEBUG) {
        System.out.println("Generated new ScatterPlot"); //$NON-NLS-1$
    }

    TraitColorProvider traitColorProvider = colorProviderFactory.get();

    XYPlot xyPlot = (XYPlot) chart.getPlot();
    XYItemRenderer xyr = xyPlot.getRendererForDataset(dataset);

    boolean anyDisplayValues = false;
    if (!xNumberToTraitValue.numberToTraitValue.isEmpty()) {
        anyDisplayValues = true;
    } else {
        for (NumberToTraitValue n2tv : numberToTraitValueBySeriesIndex.values()) {
            if (!n2tv.numberToTraitValue.isEmpty()) {
                anyDisplayValues = true;
                break;
            }
        }
    }
    if (anyDisplayValues) {
        xyr.setBaseToolTipGenerator(new MyXYToolTipGenerator());
    }

    for (TraitInstance ti : traitInstances) {
        ColorPair colorPair = traitColorProvider.getTraitInstanceColor(ti);
        if (colorPair != null) {
            if (DEBUG) {
                System.out.println("Got a color back for: " + InstanceIdentifierUtil.getInstanceIdentifier(ti)); //$NON-NLS-1$
            }

            String validName = traitNameStyle.makeTraitInstanceName(ti);
            if (seriesCountByTraitName.get(validName) != null) {
                xyr.setSeriesPaint(seriesCountByTraitName.get(validName), colorPair.getBackground());
            }
        }
    }
    xyPlot.setRenderer(xyr);

    chartPanel.setChart(chart);

    dataxMin = xyPlot.getDomainAxis().getLowerBound();
    dataxMax = xyPlot.getDomainAxis().getUpperBound();

    datayMin = xyPlot.getRangeAxis().getLowerBound();
    datayMax = xyPlot.getRangeAxis().getUpperBound();
}

From source file:ca.sqlpower.wabit.swingui.chart.ChartSwingUtil.java

/**
 * This is a helper method for creating a line chart. This should only do
 * the chart creation and not setting up the dataset. The calling method
 * should do the logic for the dataset setup.
 * @param c //ww w  .  j av  a2s  .  c  o  m
 * 
 * @param xyCollection
 *            The dataset to display a chart for.
 * @param chartType
 *            The chart type. This must be a valid chart type that can be
 *            created from an XY dataset. At current only line and scatter
 *            are supported
 * @param legendPosition
 *            The position of the legend.
 * @param chartName
 *            The name of the chart.
 * @param yaxisName
 *            The name of the y axis.
 * @param xaxisName
 *            The name of the x axis.
 * @return A chart of the specified chartType based on the given dataset.
 */
private static JFreeChart createChartFromXYDataset(Chart c, XYDataset xyCollection, ChartType chartType,
        LegendPosition legendPosition, String chartName, String yaxisName, String xaxisName) {
    boolean showLegend = !legendPosition.equals(LegendPosition.NONE);
    JFreeChart chart;
    if (chartType.equals(ChartType.LINE)) {
        chart = ChartFactory.createXYLineChart(chartName, xaxisName, yaxisName, xyCollection,
                PlotOrientation.VERTICAL, showLegend, true, false);
    } else if (chartType.equals(ChartType.SCATTER)) {
        chart = ChartFactory.createScatterPlot(chartName, xaxisName, yaxisName, xyCollection,
                PlotOrientation.VERTICAL, showLegend, true, false);
    } else {
        throw new IllegalArgumentException("Unknown chart type " + chartType + " for an XY dataset.");
    }
    if (chart == null)
        return null;
    XYPlot plot = (XYPlot) chart.getPlot();

    // XXX the following instance check is brittle; there are many ways to represent a time
    // series in JFreeChart. This check uses knowledge of the inner workings of DatasetUtil.
    if (xyCollection instanceof TimePeriodValuesCollection) {
        logger.debug("Switching x-axis to date axis so labels render properly");
        plot.setDomainAxis(new DateAxis(xaxisName));
        // TODO user-settable date format
        // axis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
    }

    if (legendPosition != LegendPosition.NONE) {
        chart.getLegend().setPosition(legendPosition.getRectangleEdge());
    }

    if (!c.isAutoXAxisRange()) {
        XYPlot xyplot = chart.getXYPlot();
        ValueAxis axis = xyplot.getDomainAxis();
        axis.setAutoRange(false);
        axis.setRange(c.getXAxisMinRange(), c.getXAxisMaxRange());
    }
    if (!c.isAutoYAxisRange()) {
        XYPlot xyplot = chart.getXYPlot();
        ValueAxis axis = xyplot.getRangeAxis();
        axis.setAutoRange(false);
        axis.setRange(c.getYAxisMinRange(), c.getYAxisMaxRange());
    }

    return chart;
}

From source file:uk.ac.leeds.ccg.andyt.projects.moses.process.RegressionReport.java

public static JFreeChart[] createScatterPlots(String[] a_Variables, double[][] a_SARExpectedData,
        double[][] a_CASObservedData, String xAxisLabel, String yAxisLabel) throws IOException {
    JFreeChart[] result;/*from   w  w  w .j  a va2s.c  o m*/
    String title = null;
    boolean legend = false;
    boolean tooltips = false;
    boolean urls = false;
    result = new JFreeChart[a_CASObservedData.length];
    double[][] data;
    double[] a_RegressionParameters;
    // double[][] data = new double[ _CASObservedData.length ][ 2 ];
    for (int i = 0; i < a_CASObservedData.length; i++) {
        title = a_Variables[i + 1];
        data = new double[2][a_CASObservedData[i].length];
        for (int j = 0; j < a_CASObservedData[i].length; j++) {
            data[0][j] = a_SARExpectedData[i][j];
            data[1][j] = a_CASObservedData[i][j];
        }
        DefaultXYDataset pointsDefaultXYDataset = new DefaultXYDataset();
        // pointsDefaultXYDataset.addSeries( "t_ScatterPlot" + i, data );
        pointsDefaultXYDataset.addSeries(a_Variables[i + 1], data);
        result[i] = ChartFactory.createScatterPlot(title, xAxisLabel, yAxisLabel, pointsDefaultXYDataset,
                //PlotOrientation.HORIZONTAL,
                PlotOrientation.VERTICAL, legend, tooltips, urls);
    }
    return result;
}

From source file:de.xirp.chart.ChartManager.java

/**
 * Returns a scatter chart. The chart is generated fromm the given
 * {@link de.xirp.db.Record} and key array. The
 * record is evaluated from the given start to the given stop time
 * or evaluated completely if the <code>origTime</code> flag is
 * set to <code>true</code>.
 * //from  ww w  .  jav a  2  s .  co m
 * @param record
 *            The record containing the data.
 * @param keys
 *            The keys to use.
 * @param start
 *            The start time.
 * @param stop
 *            The stop time.
 * @param origTime
 *            A flag indicating if the original time should be
 *            used.
 * @return A scatter chart.
 * @see org.jfree.chart.JFreeChart
 * @see de.xirp.db.Record
 */
private static JFreeChart createScatterChart(Record record, String[] keys, long start, long stop,
        boolean origTime) {

    String chartTitle = createChartTitle(record, keys);

    List<Observed> all = new ArrayList<Observed>();
    TimeSeriesCollection dataset = createTimeSeriesAndFillAllObservedList(all, record, keys, origTime, start,
            stop);

    JFreeChart chart = ChartFactory.createScatterPlot(chartTitle, I18n.getString("ChartManager.text.time"), //$NON-NLS-1$
            I18n.getString("ChartManager.text.value"), dataset, PlotOrientation.VERTICAL, true, true, false); //$NON-NLS-1$

    XYPlot plot = (XYPlot) chart.getPlot();
    setXYPlot(plot, new Date(record.getStart()));
    XYDotRenderer dr = new XYDotRenderer();
    dr.setDotWidth(3);
    dr.setDotHeight(3);
    plot.setRenderer(dr);

    exportAutomatically(all, chart);

    return chart;
}

From source file:org.gwaspi.gui.reports.ManhattanPlotZoom.java

private JFreeChart createChart(XYDataset dataset, ChromosomeKey chr) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, "", "P value", dataset, PlotOrientation.VERTICAL,
            true, false, false);/*from  w  w w.j  a  v a2 s .  com*/

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);

    // CHART BACKGROUD COLOR
    chart.setBackgroundPaint(Color.getHSBColor(0.1f, 0.1f, 1.0f)); // Hue, saturation, brightness
    plot.setBackgroundPaint(manhattan_back); // Hue, saturation, brightness 9

    // GRIDLINES
    plot.setDomainGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setDomainGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7
    plot.setDomainMinorGridlinePaint(manhattan_back); // Hue, saturation, brightness 9
    plot.setRangeGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeMinorGridlineStroke(new BasicStroke(0.0f));
    plot.setRangeGridlinePaint(manhattan_back.darker().darker()); // Hue, saturation, brightness 7
    plot.setRangeMinorGridlinePaint(manhattan_back.darker()); // Hue, saturation, brightness 8

    plot.setDomainMinorGridlinesVisible(true);
    plot.setRangeMinorGridlinesVisible(true);

    // DOTS RENDERER
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, manhattan_dot);
    //      renderer.setSeriesOutlinePaint(0, Color.DARK_GRAY);
    //      renderer.setUseOutlinePaint(true);
    // Set dot shape of the currently appended Series
    renderer.setSeriesShape(0, new Rectangle2D.Double(0.0, 0.0, 2, 2));

    renderer.setSeriesVisibleInLegend(0, false);

    NumberAxis positionAxis = (NumberAxis) plot.getDomainAxis();
    //      domainAxis.setAutoRangeIncludesZero(false);
    //      domainAxis.setTickMarkInsideLength(2.0f);
    //      domainAxis.setTickMarkOutsideLength(2.0f);
    //      domainAxis.setMinorTickCount(2);
    //      domainAxis.setMinorTickMarksVisible(true);
    positionAxis.setLabelAngle(1.0);
    positionAxis.setAutoRangeIncludesZero(false);
    positionAxis.setAxisLineVisible(true);
    positionAxis.setTickLabelsVisible(true);
    positionAxis.setTickMarksVisible(true);

    // ADD INVERSE LOG(10) Y AXIS
    LogAxis logPAxis = new LogAxis("P value");
    logPAxis.setBase(10);
    logPAxis.setInverted(true);
    logPAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE);

    logPAxis.setTickMarkOutsideLength(2.0f);
    logPAxis.setMinorTickCount(2);
    logPAxis.setMinorTickMarksVisible(true);
    logPAxis.setAxisLineVisible(true);
    logPAxis.setUpperMargin(0);

    TickUnitSource units = NumberAxis.createIntegerTickUnits();
    logPAxis.setStandardTickUnits(units);
    plot.setRangeAxis(0, logPAxis);

    // Add significance Threshold to subplot
    //threshold = 0.5/rdMatrixMetadata.getMarkerSetSize();  // (0.05/10? SNPs => 5*10-?)
    final Marker thresholdLine = new ValueMarker(threshold);
    thresholdLine.setPaint(Color.red);
    // Add legend to threshold
    thresholdLine.setLabel("P = " + GenericReportGenerator.FORMAT_P_VALUE.format(threshold));
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    plot.addRangeMarker(thresholdLine);

    // Marker label if below threshold
    XYItemRenderer lblRenderer = plot.getRenderer();

    // THRESHOLD AND SELECTED LABEL GENERATOR
    MySeriesItemLabelGenerator lblGenerator = new MySeriesItemLabelGenerator(threshold, chr);
    lblRenderer.setSeriesItemLabelGenerator(0, lblGenerator);
    lblRenderer.setSeriesItemLabelFont(0, new Font("SansSerif", Font.PLAIN, 12));
    lblRenderer.setSeriesPositiveItemLabelPosition(0, new ItemLabelPosition(ItemLabelAnchor.CENTER,
            TextAnchor.TOP_LEFT, TextAnchor.BOTTOM_LEFT, Math.PI / 4.0));

    // TOOLTIP GENERATOR
    MyXYToolTipGenerator tooltipGenerator = new MyXYToolTipGenerator(chr);

    lblRenderer.setBaseToolTipGenerator(tooltipGenerator);

    lblRenderer.setSeriesItemLabelsVisible(0, true);

    return chart;
}

From source file:keel.GraphInterKeel.datacf.visualizeData.VisualizePanelCharts2D.java

private void ViewChartjButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ViewChartjButtonActionPerformed
    // Show comparing chart
    if ((this.attribute1jComboBox.getSelectedIndex() == -1)
            || (this.attribute2jComboBox.getSelectedIndex() == -1)) {
        JOptionPane.showMessageDialog(this, "There are no attributes selected", "Error", 2);
    } else if (((VisualizePanel) (this.getParent()).getParent()).getData()
            .getAttributeTypeIndex(this.attribute1jComboBox.getSelectedIndex()).equals("nominal")
            && ((VisualizePanel) (this.getParent()).getParent()).getData()
                    .getAttributeTypeIndex(this.attribute2jComboBox.getSelectedIndex()).equals("nominal")) {
        // Error message
        JOptionPane.showMessageDialog(this, "Only one attribute can be nominal", "Error", 2);
    } else if (((VisualizePanel) (this.getParent()).getParent()).getData()
            .getAttributeTypeIndex(this.attribute1jComboBox.getSelectedIndex()).equals("nominal")) {
        // Nominal in x axis --> vertical
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        boolean legend = false;
        for (int i = 0; i < ((VisualizePanel) (this.getParent()).getParent()).getData().getNData(); i++) {
            String column = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                    this.attribute1jComboBox.getSelectedIndex());
            String row = "";
            if (((VisualizePanel) (this.getParent()).getParent()).getOutAttribute() != -1
                    && this.attribute1jComboBox
                            .getSelectedIndex() != ((VisualizePanel) (this.getParent()).getParent())
                                    .getOutAttribute()) {
                row = "Class " + ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        ((VisualizePanel) (this.getParent()).getParent()).getOutAttribute());
                legend = true;//from  w w w .  j av  a2 s  . co  m
            }
            String valor = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                    this.attribute2jComboBox.getSelectedIndex());
            if (valor != null && column != null) {
                if (dataset.getColumnIndex(column) == -1 || dataset.getRowIndex(row) == -1) {
                    dataset.addValue(Double.valueOf(valor).doubleValue(), row, column);
                } else {
                    dataset.incrementValue(Double.valueOf(valor).doubleValue(), row, column);
                }
            }
        }

        this.chart2 = ChartFactory.createBarChart3D("",
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute1jComboBox.getSelectedIndex()),
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute2jComboBox.getSelectedIndex()),
                dataset, PlotOrientation.VERTICAL, legend, false, false);
        this.chart2.setTitle(this.attribute1jComboBox.getSelectedItem().toString() + " vs "
                + this.attribute2jComboBox.getSelectedItem().toString());
        this.chart2.setBackgroundPaint(new Color(0xFFFFFF));
        BufferedImage image = this.chart2.createBufferedImage(600, 450);
        this.imagejLabel.setIcon(new ImageIcon(image));
        this.topdfjButton.setEnabled(true);
        this.topngjButton.setEnabled(true);
    } else if (((VisualizePanel) (this.getParent()).getParent()).getData()
            .getAttributeTypeIndex(this.attribute2jComboBox.getSelectedIndex()).equals("nominal")) {
        // Nominal in y axis --> horizontal
        DefaultCategoryDataset dataset = new DefaultCategoryDataset();
        boolean legend = false;
        try {
            for (int i = 0; i < ((VisualizePanel) (this.getParent()).getParent()).getData().getNData(); i++) {
                String column = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute2jComboBox.getSelectedIndex());
                String row = "";
                if (((VisualizePanel) (this.getParent()).getParent()).getOutAttribute() != -1
                        && this.attribute2jComboBox
                                .getSelectedIndex() != ((VisualizePanel) (this.getParent()).getParent())
                                        .getOutAttribute()) {
                    row = "Class " + ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                            ((VisualizePanel) (this.getParent()).getParent()).getOutAttribute());
                    legend = true;
                }
                String valor = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute1jComboBox.getSelectedIndex());
                if (valor != null) {
                    if (dataset.getColumnIndex(column) == -1 || dataset.getRowIndex(row) == -1) {
                        dataset.addValue(Double.valueOf(valor).doubleValue(), row, column);
                    } else {
                        dataset.incrementValue(Double.valueOf(valor).doubleValue(), row, column);
                    }
                }
            }
        } catch (ArrayIndexOutOfBoundsException exp) {
            JOptionPane.showMessageDialog(this,
                    "The data set contains some errors. This attribute can not be visualized", "Error", 2);
        }
        this.chart2 = ChartFactory.createBarChart3D("",
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute2jComboBox.getSelectedIndex()),
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute1jComboBox.getSelectedIndex()),
                dataset, PlotOrientation.HORIZONTAL, legend, false, false);
        this.chart2.setTitle(this.attribute1jComboBox.getSelectedItem().toString() + " vs "
                + this.attribute2jComboBox.getSelectedItem().toString());
        this.chart2.setBackgroundPaint(new Color(0xFFFFFF));
        BufferedImage image = this.chart2.createBufferedImage(579, 330);
        this.imagejLabel.setIcon(new ImageIcon(image));
        this.topdfjButton.setEnabled(true);
        this.topngjButton.setEnabled(true);
    } else {
        XYSeriesCollection juegoDatos = new XYSeriesCollection();
        boolean legend = false;
        if (((VisualizePanel) (this.getParent()).getParent()).getOutAttribute() != -1) {
            legend = true;
            Vector outputRang = ((VisualizePanel) (this.getParent()).getParent()).getData()
                    .getRange(((VisualizePanel) (this.getParent()).getParent()).getOutAttribute());
            XYSeries series[] = new XYSeries[outputRang.size()];
            for (int i = 0; i < outputRang.size(); i++) {
                series[i] = new XYSeries("Class " + outputRang.elementAt(i));
                juegoDatos.addSeries(series[i]);
            }
            for (int i = 0; i < ((VisualizePanel) (this.getParent()).getParent()).getData().getNData(); i++) {
                int clase = outputRang.indexOf(((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getDataIndex(i, ((VisualizePanel) (this.getParent()).getParent()).getOutAttribute()));
                String valor1 = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute1jComboBox.getSelectedIndex());
                String valor2 = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute2jComboBox.getSelectedIndex());
                if (valor1 != null) {
                    series[clase].add(Double.valueOf(valor1).doubleValue(),
                            Double.valueOf(valor2).doubleValue());
                }
            }
        } else {
            XYSeries series = new XYSeries("Regresin");
            juegoDatos.addSeries(series);
            for (int i = 0; i < ((VisualizePanel) (this.getParent()).getParent()).getData().getNData(); i++) {
                String valor1 = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute1jComboBox.getSelectedIndex());
                String valor2 = ((VisualizePanel) (this.getParent()).getParent()).getData().getDataIndex(i,
                        this.attribute2jComboBox.getSelectedIndex());
                if (valor1 != null) {
                    series.add(Double.valueOf(valor1).doubleValue(), Double.valueOf(valor2).doubleValue());
                }
            }

        }
        // Numeric values
        this.chart2 = ChartFactory.createScatterPlot("",
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute1jComboBox.getSelectedIndex()),
                ((VisualizePanel) (this.getParent()).getParent()).getData()
                        .getAttributeIndex(this.attribute2jComboBox.getSelectedIndex()),
                juegoDatos, PlotOrientation.VERTICAL, legend, false, false);
        this.chart2.setTitle(this.attribute1jComboBox.getSelectedItem().toString() + " vs "
                + this.attribute2jComboBox.getSelectedItem().toString());
        this.chart2.setBackgroundPaint(new Color(0xFFFFFF));
        BufferedImage image = this.chart2.createBufferedImage(579, 330);
        this.imagejLabel.setIcon(new ImageIcon(image));
        this.topdfjButton.setEnabled(true);
        this.topngjButton.setEnabled(true);
    }
}

From source file:org.ala.spatial.web.services.GDMWSController.java

public static void generateCharts123(String outputdir) {
    try {//from  ww w  . j a v  a 2  s .c om
        IniReader ir = new IniReader(outputdir + "/gdm_params.txt");
        double intercept = ir.getDoubleValue("GDMODEL", "Intercept");

        // 1. read the ObservedVsPredicted.csv file
        System.out.println("Loading csv data");
        CSVReader csv = new CSVReader(new FileReader(outputdir + "ObservedVsPredicted.csv"));
        List<String[]> rawdata = csv.readAll();
        double[][] dataCht1 = new double[2][rawdata.size() - 1];
        double[][] dataCht2 = new double[2][rawdata.size() - 1];

        // for Chart 1: obs count
        int[] obscount = new int[11];
        for (int i = 0; i < obscount.length; i++) {
            obscount[i] = 0;
        }

        System.out.println("populating data");
        for (int i = 1; i < rawdata.size(); i++) {
            String[] row = rawdata.get(i);
            double obs = Double.parseDouble(row[4]);
            dataCht1[0][i - 1] = Double.parseDouble(row[6]);
            dataCht1[1][i - 1] = obs;

            dataCht2[0][i - 1] = Double.parseDouble(row[5]) - intercept;
            dataCht2[1][i - 1] = obs;

            int obc = (int) Math.round(obs * 10);
            obscount[obc]++;
        }

        DefaultXYDataset dataset1 = new DefaultXYDataset();
        dataset1.addSeries("", dataCht1);

        DefaultXYDataset dataset2 = new DefaultXYDataset();
        dataset2.addSeries("", dataCht2);

        DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();
        for (int i = 0; i < obscount.length; i++) {
            String col = "0." + i + "-0." + (i + 1);
            if (i == 10) {
                col = "0.9-1.0";
            }
            dataset3.addValue(obscount[i] + 100, "col", col);
        }
        generateChartByType("Response Histogram", "Observed Dissimilarity Class", "Number of Site Pairs",
                dataset3, outputdir, "bar", "resphist");

        XYDotRenderer renderer = new XYDotRenderer();
        //Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
        //renderer.setSeriesShape(0, cross);
        renderer.setDotWidth(3);
        renderer.setDotHeight(3);
        renderer.setSeriesPaint(0, Color.BLACK);

        JFreeChart jChart1 = ChartFactory.createScatterPlot(
                "Observed versus predicted compositional dissimilarity",
                "Predicted Compositional Dissimilarity", "Observed Compositional Dissimilarity", dataset1,
                PlotOrientation.VERTICAL, false, false, false);
        jChart1.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        XYPlot plot = (XYPlot) jChart1.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRenderer(0, renderer);

        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        double dMinPred = domain.getRange().getLowerBound();
        double dMaxPred = domain.getRange().getUpperBound();

        double dMinObs = range.getRange().getLowerBound();
        double dMaxObs = range.getRange().getUpperBound();

        System.out.println("1..pred.min.max: " + dMinPred + ", " + dMaxPred);

        int regressionLineSegs = 10;
        double dInc = (dMaxPred - dMinPred) / regressionLineSegs;
        double[][] dataReg1 = new double[2][regressionLineSegs + 1];
        DefaultXYDataset dsReg1 = new DefaultXYDataset();
        int i = 0;
        for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) {
            dataReg1[0][i] = d;
            dataReg1[1][i] = d;
        }
        dsReg1.addSeries("", dataReg1);
        XYSplineRenderer regressionRenderer = new XYSplineRenderer();
        regressionRenderer.setBaseSeriesVisibleInLegend(true);
        regressionRenderer.setSeriesPaint(0, Color.RED);
        regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f));
        regressionRenderer.setBaseShapesVisible(false);
        plot.setDataset(1, dsReg1);
        plot.setRenderer(1, regressionRenderer);

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/obspredissim.png"), jChart1, 600, 400);

        // For chart 3
        JFreeChart jChart2 = ChartFactory.createScatterPlot(
                "Observed compositional dissimilarity vs predicted ecological distance",
                "Predicted ecological distance", "Observed Compositional Dissimilarity", dataset2,
                PlotOrientation.VERTICAL, false, false, false);
        jChart2.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        plot = (XYPlot) jChart2.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRenderer(0, renderer);

        domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        dMinPred = domain.getRange().getLowerBound();
        dMaxPred = domain.getRange().getUpperBound();

        dMinObs = range.getRange().getLowerBound();
        dMaxObs = range.getRange().getUpperBound();

        System.out.println("2.pred.min.max: " + dMinPred + ", " + dMaxPred);

        regressionLineSegs = 10;
        dInc = (dMaxPred - dMinPred) / regressionLineSegs;
        dataReg1 = new double[2][regressionLineSegs + 1];
        dsReg1 = new DefaultXYDataset();
        i = 0;
        for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) {
            dataReg1[0][i] = d;
            dataReg1[1][i] = (1.0 - Math.exp(-d));
        }
        dsReg1.addSeries("", dataReg1);
        regressionRenderer.setBaseSeriesVisibleInLegend(true);
        regressionRenderer.setSeriesPaint(0, Color.RED);
        regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f));
        regressionRenderer.setBaseShapesVisible(false);
        plot.setDataset(1, dsReg1);
        plot.setRenderer(1, regressionRenderer);

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/dissimdist.png"), jChart2, 600, 400);

    } catch (Exception e) {
        System.out.println("Unable to generate charts 2 and 3:");
        e.printStackTrace(System.out);
    }
}

From source file:org.pentaho.chart.plugin.jfreechart.JFreeChartFactoryEngine.java

protected JFreeChart makeScatterChart(ChartModel chartModel, XYDataModel data) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    dataset.addSeries(createXYSeries(data));

    org.pentaho.chart.model.TwoAxisPlot twoAxisPlot = (org.pentaho.chart.model.TwoAxisPlot) chartModel
            .getPlot();/*from  www .  j  a va2  s  .co  m*/

    String title = "";
    if ((chartModel.getTitle() != null) && (chartModel.getTitle().getText() != null)
            && (chartModel.getTitle().getText().trim().length() > 0)) {
        title = chartModel.getTitle().getText();
    }

    AxesLabels axesLabels = getAxesLabels(chartModel);
    PlotOrientation plotOrientation = (twoAxisPlot.getOrientation() == Orientation.HORIZONTAL)
            ? PlotOrientation.HORIZONTAL
            : PlotOrientation.VERTICAL;
    boolean showLegend = (chartModel.getLegend() != null) && (chartModel.getLegend().getVisible());
    JFreeChart chart = ChartFactory.createScatterPlot(title, axesLabels.domainAxisLabel,
            axesLabels.rangeAxisLabel, dataset, plotOrientation, showLegend, true, false);

    initXYPlot(chart, chartModel);
    initChart(chart, chartModel);

    return chart;
}

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

private int generateTestCaseScatterCharts(String baseName, String extension) {
    int nOfFiles = 0;
    List<DriverImpl> driverInfoList = _testSuite.getDriverInfoList();

    try {//from   w w w .j a v  a 2  s  .  c  om
        // Get number of tests from first driver
        final int nOfTests = driverInfoList.get(0).getAggregateTestCases().size();

        DefaultTableXYDataset xyDataset = new DefaultTableXYDataset();

        // Generate charts
        for (DriverImpl di : driverInfoList) {
            XYSeries xySeries = new XYSeries(di.getName(), true, false);
            for (int j = 0; j < nOfTests; j++) {
                TestCaseImpl tc = (TestCaseImpl) di.getAggregateTestCases().get(j);
                try {
                    xySeries.add(tc.getDoubleParamNoNaN(Constants.RESULT_VALUE_X),
                            tc.getDoubleParamNoNaN(Constants.RESULT_VALUE));
                } catch (SeriesException e) {
                    // Ignore duplicate x-valued points
                }

            }
            xyDataset.addSeries(xySeries);
        }

        String resultUnit = _testSuite.getParam(Constants.RESULT_UNIT);
        String resultUnitX = _testSuite.getParam(Constants.RESULT_UNIT_X);

        JFreeChart chart = ChartFactory.createScatterPlot("Results Per Test", resultUnitX, resultUnit,
                xyDataset, PlotOrientation.VERTICAL, true, true, false);

        // Set log scale depending on japex.resultAxis[_X]
        XYPlot plot = chart.getXYPlot();
        if (_testSuite.getParam(Constants.RESULT_AXIS_X).equalsIgnoreCase("logarithmic")) {
            LogarithmicAxis logAxisX = new LogarithmicAxis(resultUnitX);
            logAxisX.setAllowNegativesFlag(true);
            plot.setDomainAxis(logAxisX);
        }
        if (_testSuite.getParam(Constants.RESULT_AXIS).equalsIgnoreCase("logarithmic")) {
            LogarithmicAxis logAxis = new LogarithmicAxis(resultUnit);
            logAxis.setAllowNegativesFlag(true);
            plot.setRangeAxis(logAxis);
        }

        chart.setAntiAlias(true);
        ChartUtilities.saveChartAsJPEG(new File(baseName + Integer.toString(nOfFiles) + extension), chart,
                _chartWidth, _chartHeight);
        nOfFiles++;
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        e.printStackTrace();
    }

    return nOfFiles;
}

From source file:org.jax.maanova.test.gui.VolcanoPlotPanel.java

private void updateDataPoints() {
    this.cachedXYData = null;
    XYProbeData xyData = this.getXYData();

    DefaultXYDataset xyDataSet = new DefaultXYDataset();
    int[] selectedIndices = this.selectedIndices;
    if (selectedIndices.length == 0) {
        xyDataSet.addSeries("data", new double[][] { xyData.getXData(), xyData.getYData() });
    } else {//  ww  w.j ava 2s. c  o m
        double[] xData = xyData.getXData();
        double[] yData = xyData.getYData();
        int[] dataIndices = xyData.getProbeIndices();

        double[] normalXData = new double[xData.length - selectedIndices.length];
        double[] normalYData = new double[xData.length - selectedIndices.length];

        double[] selectedXData = new double[selectedIndices.length];
        double[] selectedYData = new double[selectedIndices.length];

        int selectionIndex = 0;
        for (int i = 0; i < xData.length; i++) {
            if (selectionIndex < selectedIndices.length && dataIndices[i] == selectedIndices[selectionIndex]) {
                // this is one of the selected points
                selectedXData[selectionIndex] = xData[i];
                selectedYData[selectionIndex] = yData[i];

                selectionIndex++;
            } else {
                // this is not a selected point
                normalXData[i - selectionIndex] = xData[i];
                normalYData[i - selectionIndex] = yData[i];
            }
        }

        xyDataSet.addSeries("data", new double[][] { normalXData, normalYData });
        xyDataSet.addSeries("selected data", new double[][] { selectedXData, selectedYData });
    }

    JFreeChart scatterPlot = ChartFactory.createScatterPlot(this.chartConfigurationDialog.getChartTitle(),
            this.chartConfigurationDialog.getXAxisLabel(), this.chartConfigurationDialog.getYAxisLabel(),
            xyDataSet, PlotOrientation.VERTICAL, false, false, false);

    XYPlot xyPlot = (XYPlot) scatterPlot.getPlot();
    xyPlot.setRenderer(PlotUtil.createSimpleScatterPlotRenderer());
    if (this.viewArea != null) {
        PlotUtil.rescaleXYPlot(this.viewArea, xyPlot);
    }

    this.saveGraphImageAction.setChart(scatterPlot);
    this.chartPanel.setChart(scatterPlot);
}