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:jprobix.ui.SPlotFinal.java

public static JPanel creteDemoPanel() {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Scatter plot demo", "X", "Y", samplexydataset2(),
            PlotOrientation.VERTICAL, true, true, false);

    Shape cross = ShapeUtilities.createDiagonalCross(3, 2);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesShape(5, cross);//from w w w  .  ja va 2s  . co  m
    renderer.setSeriesPaint(0, Color.YELLOW);

    XYDotRenderer xydotrenderer = new XYDotRenderer();
    xyPlot.setRenderer(xydotrenderer);
    xydotrenderer.setSeriesShape(0, cross);

    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    return new ChartPanel(jfreechart);
}

From source file:com.imaging100x.tracker.TrackerUtils.java

/**
* Create a frame with a plot of the data given in XYSeries
*//*  w w w  .  ja va  2 s  .  c  om*/
public static void plotData(String title, final XYSeries data, String xTitle, String yTitle, int xLocation,
        int yLocation) {
    // JFreeChart code
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(data);
    JFreeChart chart = ChartFactory.createScatterPlot(title, // Title
            xTitle, // x-axis Label
            yTitle, // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            false, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    final XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesPaint(0, Color.black);
    renderer.setSeriesFillPaint(0, Color.white);
    renderer.setSeriesLinesVisible(0, true);
    Shape circle = new Ellipse2D.Float(-2.0f, -2.0f, 4.0f, 4.0f);
    renderer.setSeriesShape(0, circle, false);
    renderer.setUseFillPaint(true);

    ChartFrame graphFrame = new ChartFrame(title, chart);
    graphFrame.getChartPanel().setMouseWheelEnabled(true);
    graphFrame.setPreferredSize(new Dimension(SIZE, SIZE));
    graphFrame.setResizable(true);
    graphFrame.pack();
    graphFrame.setLocation(xLocation, yLocation);
    graphFrame.setVisible(true);

    dataset.addChangeListener(new DatasetChangeListener() {

        public void datasetChanged(DatasetChangeEvent dce) {
            double xRange = data.getMaxX() - data.getMinX();
            double yRange = data.getMaxY() - data.getMinY();
            double xAvg = (data.getMaxX() + data.getMinX()) / 2;
            double yAvg = (data.getMaxY() + data.getMinY()) / 2;
            double range = xRange;
            if (yRange > range) {
                range = yRange;
            }
            double offset = 0.55 * range;
            plot.getDomainAxis().setRange(xAvg - offset, xAvg + offset);
            plot.getRangeAxis().setRange(yAvg - offset, yAvg + offset);
        }

    });

}

From source file:org.jfree.chart.demo.XYPolygonAnnotationDemo1.java

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("XYPolygonAnnotationDemo1", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    XYPolygonAnnotation xypolygonannotation = new XYPolygonAnnotation(
            new double[] { 2D, 5D, 2.5D, 8D, 3D, 5D, 2.5D, 2D }, null, null, new Color(200, 200, 255, 100));
    xypolygonannotation.setToolTipText("Target Zone");
    xylineandshaperenderer.addAnnotation(xypolygonannotation, Layer.BACKGROUND);
    return jfreechart;
}

From source file:org.jfree.chart.demo.XYPointerAnnotationDemo1.java

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("XYPointerAnnotationDemo1", "X", "Y", xydataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    jfreechart.setBackgroundPaint(Color.white);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation("Special point", 2.2000000000000002D, 6D,
            3.9269908169872414D);/*from  w  w  w  .j a va2s . co  m*/
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
    xypointerannotation.setToolTipText("The pointer has a tool tip!");
    xylineandshaperenderer.addAnnotation(xypointerannotation, Layer.BACKGROUND);
    return jfreechart;
}

From source file:audio.cords.old.RegressionDemo.java

private static JFreeChart createChart(XYSeriesCollection data) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, "X", "Y", data, PlotOrientation.VERTICAL, true,
            false, false);//from   w ww  .j  a va2s. c  o m
    XYPlot plot = (XYPlot) chart.getPlot();
    XYItemRenderer scatterRenderer = plot.getRenderer();
    StandardXYItemRenderer regressionRenderer = new StandardXYItemRenderer();
    regressionRenderer.setBaseSeriesVisibleInLegend(false);
    plot.setDataset(1, regress(data));
    plot.setRenderer(1, regressionRenderer);
    DrawingSupplier ds = plot.getDrawingSupplier();
    for (int i = 0; i < data.getSeriesCount(); i++) {
        Paint paint = ds.getNextPaint();
        scatterRenderer.setSeriesPaint(i, paint);
        regressionRenderer.setSeriesPaint(i, paint);
    }
    return chart;
}

From source file:audio.cords.SimplestChart.java

private static JFreeChart createChart(XYSeriesCollection data) {
    JFreeChart chart = ChartFactory.createScatterPlot(null, "X", "Y", data, PlotOrientation.VERTICAL, true,
            false, false);/*from w  ww. ja va 2  s  .co  m*/
    XYPlot plot = (XYPlot) chart.getPlot();
    XYItemRenderer scatterRenderer = plot.getRenderer();

    //        plot.getDomainAxis().resizeRange(2);
    //        plot.getRangeAxis().resizeRange(2);
    plot.zoom(2);

    //StandardXYItemRenderer regressionRenderer = new StandardXYItemRenderer();
    //regressionRenderer.setBaseSeriesVisibleInLegend(false);
    //plot.setDataset(1, regress(data));
    //plot.setRenderer(1, regressionRenderer);
    DrawingSupplier ds = plot.getDrawingSupplier();
    for (int i = 0; i < data.getSeriesCount(); i++) {
        Paint paint = ds.getNextPaint();
        scatterRenderer.setSeriesPaint(i, paint);
        //regressionRenderer.setSeriesPaint(i, paint);
    }
    return chart;
}

From source file:neuronspike.NetPlot.java

private JFreeChart createChart() {
    JFreeChart chart = ChartFactory.createScatterPlot(label, x_label, y_label, series, PlotOrientation.VERTICAL,
            true, true, false);
    return chart;
}

From source file:org.drugis.addis.gui.LyndOBrienChartFactory.java

public static JFreeChart buildScatterPlot(LyndOBrienModel model) {
    XYDataset data = new ScatterPlotDataset(model);
    JFreeChart chart = ChartFactory.createScatterPlot("Benefit-Risk plane", model.getXAxisName(),
            model.getYAxisName(), data, PlotOrientation.VERTICAL, false, false, false);

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setUseOutlinePaint(true);// www  .java2 s.c o m
    renderer.setSeriesShape(0, new Ellipse2D.Double(-2.0, 2.0, 4.0, 4.0));

    // draw lines through origin.
    chart.getXYPlot().setDomainZeroBaselineVisible(true);
    chart.getXYPlot().setRangeZeroBaselineVisible(true);

    // Explicitly set the stroke-width to avoid a rendering error in Linux
    Stroke stroke = new BasicStroke(1.0f);
    chart.getXYPlot().setDomainZeroBaselineStroke(stroke);
    return chart;
}

From source file:lifnetwork.ChartSave.java

public ChartSave() {
    super(ChartFactory.createScatterPlot("Population Fire", "Time (s)", "Neuron #", (new XYSeriesCollection()),
            PlotOrientation.VERTICAL, false, false, false));
    fireChart = this.getChart();
    fireChart.setNotify(false);//from w  w w.j a  v a 2s . co m
    XYPlot plot = fireChart.getXYPlot();
    plot.setBackgroundPaint(Color.WHITE);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesShapesVisible(0, true);
    renderer.setSeriesShape(0, new Rectangle2D.Double(0, 0, 1, 1));
    fireCollection = (XYSeriesCollection) plot.getDataset();
    fireSeries = new XYSeries("fires");
    fireCollection.addSeries(fireSeries);
}

From source file:edu.gmu.cs.sim.util.media.chart.ScatterPlotGenerator.java

protected void buildChart() {
    DefaultXYDataset dataset = new DefaultXYDataset();
    chart = ChartFactory.createScatterPlot("Untitled Chart", "Untitled X Axis", "Untitled Y Axis", dataset,
            PlotOrientation.VERTICAL, false, true, false);
    chart.setAntiAlias(true);//w w  w  . j ava2  s .c o  m
    //chartPanel = new ScrollableChartPanel(chart, true); 
    chartPanel = buildChartPanel(chart);
    //chartHolder.getViewport().setView(chartPanel);
    setChartPanel(chartPanel);
    chart.getXYPlot().setRenderer(new XYLineAndShapeRenderer(false, true));
    //              ((StandardLegend) chart.getLegend()).setDisplaySeriesShapes(true);

    // this must come last because the chart must exist for us to set its dataset
    setSeriesDataset(dataset);
}