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:org.esa.snap.rcp.statistics.ScatterPlotPanel.java

ScatterPlotPanel(TopComponent parentDialog, String helpId) {
    super(parentDialog, helpId, CHART_TITLE, false);
    userSettingsMap = new HashMap<>();
    productRemovedListener = new ProductManager.Listener() {
        @Override/*from w w w.  j  a v  a  2s .co  m*/
        public void productAdded(ProductManager.Event event) {
        }

        @Override
        public void productRemoved(ProductManager.Event event) {
            final UserSettings userSettings = userSettingsMap.remove(event.getProduct());
            if (userSettings != null) {
                userSettings.dispose();
            }
        }
    };

    xAxisRangeControl = new AxisRangeControl("X-Axis");
    yAxisRangeControl = new AxisRangeControl("Y-Axis");
    scatterPlotModel = new ScatterPlotModel();
    bindingContext = new BindingContext(PropertyContainer.createObjectBacked(scatterPlotModel));
    scatterpointsDataset = new XYIntervalSeriesCollection();
    acceptableDeviationDataset = new XYIntervalSeriesCollection();
    regressionDataset = new XYIntervalSeriesCollection();
    r2Annotation = new XYTitleAnnotation(0, 0, new TextTitle(""));
    chart = ChartFactory.createScatterPlot(CHART_TITLE, "", "", scatterpointsDataset, PlotOrientation.VERTICAL,
            true, true, false);
    chart.getXYPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    createDomainAxisChangeListener();
    final PropertyChangeListener userSettingsUpdateListener = evt -> {
        if (getRaster() != null) {
            final VectorDataNode pointDataSourceValue = scatterPlotModel.pointDataSource;
            final AttributeDescriptor dataFieldValue = scatterPlotModel.dataField;
            final UserSettings userSettings = getUserSettings(getRaster().getProduct());
            userSettings.set(getRaster().getName(), pointDataSourceValue, dataFieldValue);
        }
    };

    bindingContext.addPropertyChangeListener(PROPERTY_NAME_DATA_FIELD, userSettingsUpdateListener);
    bindingContext.addPropertyChangeListener(PROPERTY_NAME_POINT_DATA_SOURCE, userSettingsUpdateListener);
}

From source file:GUI.PlotCreator.java

private ChartPanel createSeaCurrentDirectionByTimePanel() {
    JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "Time(Hours)", "Sea Current Direction",
            createSeaCurrentDirectionByTime(), PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    //XYItemRenderer renderer = xyPlot.getRenderer();
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setTickUnit(new NumberTickUnit(1.0));
    domain.setVerticalTickLabels(true);/*from w  ww  .  ja va  2 s .com*/

    return new ChartPanel(jfreechart);
}

From source file:org.jax.maanova.fit.gui.ResidualPlotPanel.java

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

    DefaultXYDataset xyDataSet = new DefaultXYDataset();
    for (int arrayIndex = 0; arrayIndex < xyData.length; arrayIndex++) {
        XYProbeData currData = xyData[arrayIndex];
        xyDataSet.addSeries(arrayIndex, new double[][] { currData.getXData(), currData.getYData() });
    }//from  w w w. j  av  a  2  s.co  m

    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.createMonochromeScatterPlotRenderer());
    if (this.viewArea != null) {
        PlotUtil.rescaleXYPlot(this.viewArea, xyPlot);
    }

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

From source file:be.ugent.maf.cellmissy.gui.controller.analysis.singlecell.PlateHeatMapController.java

/**
 * Plot the z-scores: simple scatterplot
 *///from   w  w  w  .  ja v a  2 s. c o m
private void plotZScores() {
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    Map<Well, Double> map = computeZScoresForMap();

    List<PlateCondition> plateConditionList = trackCoordinatesController.getPlateConditionList();

    for (int i = 0; i < plateConditionList.size(); i++) {
        // current condition
        PlateCondition condition = plateConditionList.get(i);
        XYSeries series = new XYSeries(i + "-" + condition);
        for (int j = 0; j < condition.getSingleCellAnalyzedWells().size(); j++) {
            // current well
            Well well = condition.getSingleCellAnalyzedWells().get(j);
            series.add(i + 1, map.get(well));
        }
        xySeriesCollection.addSeries(series);
    }

    JFreeChart jfreechart = ChartFactory.createScatterPlot("z*-score", "condition number", "z*-score",
            xySeriesCollection, PlotOrientation.VERTICAL, false, true, false);
    JFreeChartUtils.setupXYPlot(jfreechart.getXYPlot());
    jfreechart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // line for the median speed
    ValueMarker marker = new ValueMarker(0);
    marker.setPaint(Color.GRAY);
    Stroke dashedStroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f,
            new float[] { 1.0f, 3.0f }, 0.0f);
    marker.setStroke(dashedStroke);
    jfreechart.getXYPlot().addRangeMarker(marker);

    marker = new ValueMarker(3);
    marker.setPaint(Color.GRAY);
    marker.setStroke(dashedStroke);
    jfreechart.getXYPlot().addRangeMarker(marker);

    marker = new ValueMarker(-3);
    marker.setPaint(Color.GRAY);
    marker.setStroke(dashedStroke);
    jfreechart.getXYPlot().addRangeMarker(marker);

    XYItemRenderer renderer = jfreechart.getXYPlot().getRenderer();
    for (int i = 0; i < xySeriesCollection.getSeriesCount(); i++) {
        // plot lines according to conditions indexes
        int colorIndex = i % GuiUtils.getAvailableColors().length;
        Color color = GuiUtils.getAvailableColors()[colorIndex];
        color = new Color(color.getRed(), color.getGreen(), color.getBlue(), 127);
        renderer.setSeriesPaint(i, color);
        renderer.setSeriesShape(i, new Ellipse2D.Double(0, 0, 10, 10));
    }
    zScoreChartPanel.setChart(jfreechart);
}

From source file:org.esa.beam.visat.toolviews.stat.ScatterPlotPanel.java

ScatterPlotPanel(ToolView parentDialog, String helpId) {
    super(parentDialog, helpId, CHART_TITLE, false);
    userSettingsMap = new HashMap<>();
    productRemovedListener = new ProductManager.Listener() {
        @Override/*from   w  ww. ja  v a2  s .  c  o m*/
        public void productAdded(ProductManager.Event event) {
        }

        @Override
        public void productRemoved(ProductManager.Event event) {
            final UserSettings userSettings = userSettingsMap.remove(event.getProduct());
            if (userSettings != null) {
                userSettings.dispose();
            }
        }
    };

    xAxisRangeControl = new AxisRangeControl("X-Axis");
    yAxisRangeControl = new AxisRangeControl("Y-Axis");
    scatterPlotModel = new ScatterPlotModel();
    bindingContext = new BindingContext(PropertyContainer.createObjectBacked(scatterPlotModel));
    scatterpointsDataset = new XYIntervalSeriesCollection();
    acceptableDeviationDataset = new XYIntervalSeriesCollection();
    regressionDataset = new XYIntervalSeriesCollection();
    r2Annotation = new XYTitleAnnotation(0, 0, new TextTitle(""));
    chart = ChartFactory.createScatterPlot(CHART_TITLE, "", "", scatterpointsDataset, PlotOrientation.VERTICAL,
            true, true, false);
    chart.getXYPlot().setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    createDomainAxisChangeListener();
    final PropertyChangeListener userSettingsUpdateListener = new PropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (getRaster() != null) {
                final VectorDataNode pointDataSourceValue = scatterPlotModel.pointDataSource;
                final AttributeDescriptor dataFieldValue = scatterPlotModel.dataField;
                final UserSettings userSettings = getUserSettings(getRaster().getProduct());
                userSettings.set(getRaster().getName(), pointDataSourceValue, dataFieldValue);
            }
        }
    };

    bindingContext.addPropertyChangeListener(PROPERTY_NAME_DATA_FIELD, userSettingsUpdateListener);
    bindingContext.addPropertyChangeListener(PROPERTY_NAME_POINT_DATA_SOURCE, userSettingsUpdateListener);
}

From source file:ch.zhaw.ias.dito.ui.AnalysisPanel.java

private JFreeChart createQuestionChart(String title, double[][] values) {
    JFreeChart chart = ChartFactory.createScatterPlot(title, null, null, new MdsXYDataset(values),
            PlotOrientation.VERTICAL, false, true, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setRenderer(1, new VectorRenderer());
    plot.setDataset(1, getVectorDataset(values));
    plot.getRenderer().setBaseItemLabelsVisible(true);

    plot.getRenderer().setBaseItemLabelPaint(Color.BLUE);
    plot.getRenderer().setBaseItemLabelGenerator(new XYItemLabelGenerator() {
        @Override//from  w w  w  .  j av  a  2 s.  co m
        public String generateLabel(XYDataset dataset, int series, int item) {
            //return "#" + (item + 1);
            return "#" + (item + 1) + ":" + Config.INSTANCE.getDitoConfig().getQuestion(item + 1).getName();
        }
    });
    plot.getRenderer().setBaseToolTipGenerator(new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return "#" + (item + 1) + ":" + Config.INSTANCE.getDitoConfig().getQuestion(item + 1).getName();
        }
    });
    return chart;
}

From source file:org.gephi.statistics.plugin.EigenvectorCentrality.java

/** 
 * /*from  w w  w. j ava  2  s  .c o  m*/
 * @return 
 */
@Override
public String getReport() {
    //distribution of values 
    Map<Double, Integer> dist = new HashMap<Double, Integer>();
    for (int i = 0; i < centralities.length; i++) {
        Double d = centralities[i];
        if (dist.containsKey(d)) {
            Integer v = dist.get(d);
            dist.put(d, v + 1);
        } else {
            dist.put(d, 1);
        }
    }

    //Distribution series 
    XYSeries dSeries = ChartUtils.createXYSeries(dist, "Eigenvector Centralities");

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);

    JFreeChart chart = ChartFactory.createScatterPlot("Eigenvector Centrality Distribution", "Score", "Count",
            dataset, PlotOrientation.VERTICAL, true, false, false);
    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dSeries, true);
    String imageFile = ChartUtils.renderChart(chart, "eigenvector-centralities.png");

    String report = "<HTML> <BODY> <h1>Eigenvector Centrality Report</h1> " + "<hr>" + "<h2> Parameters: </h2>"
            + "Network Interpretation:  " + (isDirected ? "directed" : "undirected") + "<br>"
            + "Number of iterations: " + numRuns + "<br>" + "Sum change: " + sumChange
            + "<br> <h2> Results: </h2>" + imageFile + "</BODY></HTML>";

    return report;

}

From source file:SciTK.PlotXY.java

/**
* Initialize the chart itself/*from w ww. ja v  a2  s  .  c o  m*/
*/
private void init(String x_label, String y_label, String window_title) {
    chart = ChartFactory.createScatterPlot("", x_label, y_label, data, PlotOrientation.VERTICAL, true, true,
            false);

    // for some reason default is white, change it to black:
    setGridlineColor(Color.BLACK);

    super.window_title = window_title;
    super.initUI();
}

From source file:GUI.PlotCreator.java

private ChartPanel createSeaCurrentSpeedByHPanel() {
    JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "H", "Sea Current Speed",
            createSeaCurrentSpeedDataByH(), PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    //XYItemRenderer renderer = xyPlot.getRenderer();
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    domain.setVerticalTickLabels(true);/*  w ww.j a  v  a  2 s .  c om*/
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    xyPlot.setRenderer(renderer);
    return new ChartPanel(jfreechart);
}

From source file:com.vgi.mafscaling.VECalc.java

protected void createChart(JPanel plotPanel, String xAxisName, String yAxisName) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, null, null, null, PlotOrientation.VERTICAL, false,
            true, false);//  w  w  w.  java  2  s.c o  m
    chart.setBorderVisible(true);

    chartPanel = new ChartPanel(chart, true, true, true, true, true);
    chartPanel.setAutoscrolls(true);
    chartPanel.setMouseZoomable(false);

    GridBagConstraints gbl_chartPanel = new GridBagConstraints();
    gbl_chartPanel.anchor = GridBagConstraints.CENTER;
    gbl_chartPanel.insets = new Insets(3, 3, 3, 3);
    gbl_chartPanel.weightx = 1.0;
    gbl_chartPanel.weighty = 1.0;
    gbl_chartPanel.fill = GridBagConstraints.BOTH;
    gbl_chartPanel.gridx = 0;
    gbl_chartPanel.gridy = 1;
    plotPanel.add(chartPanel, gbl_chartPanel);

    XYLineAndShapeRenderer lineRenderer = new XYLineAndShapeRenderer();
    lineRenderer.setUseFillPaint(true);
    lineRenderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new DecimalFormat("0.00"), new DecimalFormat("0.00")));

    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
    lineRenderer.setSeriesStroke(0, stroke);
    lineRenderer.setSeriesPaint(0, Color.RED);
    lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));

    lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
        private static final long serialVersionUID = 7593430826693873496L;

        public String generateLabel(XYDataset dataset, int series) {
            XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
            return xys.getDescription();
        }
    });

    NumberAxis xAxis = new NumberAxis(xAxisName);
    xAxis.setAutoRangeIncludesZero(false);
    NumberAxis yAxis = new NumberAxis(yAxisName);
    yAxis.setAutoRangeIncludesZero(false);

    XYSeriesCollection lineDataset = new XYSeriesCollection();

    XYPlot plot = chart.getXYPlot();
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    plot.setDomainGridlinePaint(Color.DARK_GRAY);
    plot.setRangeGridlinePaint(Color.DARK_GRAY);
    plot.setBackgroundPaint(new Color(224, 224, 224));

    plot.setDataset(0, lineDataset);
    plot.setRenderer(0, lineRenderer);
    plot.setDomainAxis(0, xAxis);
    plot.setRangeAxis(0, yAxis);
    plot.mapDatasetToDomainAxis(0, 0);
    plot.mapDatasetToRangeAxis(0, 0);

    LegendTitle legend = new LegendTitle(plot.getRenderer());
    legend.setItemFont(new Font("Arial", 0, 10));
    legend.setPosition(RectangleEdge.TOP);
    chart.addLegend(legend);
}