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:GUI.PlotCreator.java

private ChartPanel createWindIntensityByTimePanel() {
    JFreeChart jfreechart = ChartFactory.createScatterPlot(title, "Time(Hours)", "Wind Instensity",
            createWindIntensityByTime(), PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) jfreechart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);
    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(0, Color.GREEN);
    NumberAxis domain = (NumberAxis) xyPlot.getDomainAxis();
    //domain.setRange(0,24);
    domain.setTickUnit(new NumberTickUnit(1.0));
    domain.setVerticalTickLabels(true);/*w  ww.j a  va  2  s . c om*/

    return new ChartPanel(jfreechart);
}

From source file:gov.sandia.umf.platform.ui.jobs.Raster.java

public JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createScatterPlot(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );//from   ww  w  .java 2  s .  co  m

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setRangeGridlinePaint(Color.lightGray);
    plot.setDomainPannable(true);
    plot.setRangePannable(true);

    plot.setRenderer(new XYDotRenderer() {
        public void drawItem(java.awt.Graphics2D g2, XYItemRendererState state,
                java.awt.geom.Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis,
                ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState,
                int pass) {
            // Copied from org.jfree.chart.renderer.xy.XYDotRenderer.java and modified.
            // This would only need to be a couple of lines if they authors of jfreechart had not made dotWidth and dotHeight private members.
            // Yet another example of textbook OO programming gone awry. (Can anyone hear me scream?)

            if (!getItemVisible(series, item))
                return;

            int dotWidth = 1;

            double rasterLines = rangeAxis.getRange().getLength();
            int pixels = g2.getClipBounds().height;
            double height = pixels / rasterLines;
            if (height > 10)
                height -= 2;
            else if (height > 2)
                height -= 1;
            int dotHeight = (int) Math.min(20, Math.max(1, Math.floor(height)));

            double x = dataset.getXValue(series, item);
            double y = dataset.getYValue(series, item);
            if (Double.isNaN(y))
                return;
            double adjx = (dotWidth - 1) / 2.0;
            double adjy = (dotHeight - 1) / 2.0;

            RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
            RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
            double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
            double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

            g2.setPaint(Color.black);
            PlotOrientation orientation = plot.getOrientation();
            if (orientation == PlotOrientation.HORIZONTAL)
                g2.fillRect((int) transY, (int) transX, dotHeight, dotWidth);
            else
                g2.fillRect((int) transX, (int) transY, dotWidth, dotHeight);

            int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
            int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
            updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY,
                    orientation);
        }
    });

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits()); // Integer units only

    return chart;
}

From source file:mrmc.chart.StudyDesignPlot.java

/**
 * Constructs the chart/*from   w  w w.  j a  v  a  2s .c  o  m*/
 * 
 * @param dataset Representation of x-y data
 * @param title Title of chart
 * @param xaxis Label for x-axis
 * @param yaxis Label for y-axis
 * @return The chart
 */
private JFreeChart createChart(final DefaultXYDataset dataset, String title, String xaxis, String yaxis) {
    final JFreeChart chart = ChartFactory.createScatterPlot(title, xaxis, yaxis, dataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) chart.getPlot();
    NumberAxis rangeAxis = (NumberAxis) xyplot.getRangeAxis();
    ;

    rangeAxis.setLowerBound(-.5);

    rangeAxis.setTickUnit(new NumberTickUnit(1));
    XYItemRenderer renderer = xyplot.getRenderer();
    Rectangle square = new Rectangle(5, 5);
    renderer.setSeriesShape(0, square);
    renderer.setSeriesShape(1, square);
    renderer.setSeriesPaint(0, Color.white);
    renderer.setSeriesPaint(1, Color.black);
    return chart;

}

From source file:gov.nih.nci.ispy.ui.graphing.chart.plot.ISPYCorrelationScatterPlot.java

private void createChart() {

    String title = "Correlation Scatter Plot  correlationCoefficient=" + nf.format(corrValue) + " N="
            + dataPoints.size();/*from w  w w  .  j  ava  2 s  .co  m*/

    corrChart = ChartFactory.createScatterPlot(title, xLabel, yLabel, null, PlotOrientation.VERTICAL, true,
            true, false);

    XYPlot plot = (XYPlot) corrChart.getPlot();

    plot.setNoDataMessage(null);
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setUseOutlinePaint(true);
    plot.setRangeCrosshairVisible(false);
    plot.setDomainCrosshairVisible(false);

    //        XYShapeAnnotation annotation = new XYShapeAnnotation(new Rectangle2D.Double(25.0, 25.0, 5, 5));
    //           
    //        plot.addAnnotation(annotation);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();

    //should determine axis range using datapoints.
    List<PlotPoint> plotPoints = new ArrayList<PlotPoint>(dataPoints);
    DataRange Xrange = PlotPoint.getDataRange(plotPoints, AxisType.X_AXIS);
    DataRange Yrange = PlotPoint.getDataRange(plotPoints, AxisType.Y_AXIS);

    //        Double xAbsMax = Math.max(Math.abs(Xrange.getMaxRange()), Math.abs(Xrange.getMinRange()));
    //        Double yAbsMax = Math.max(Math.abs(Yrange.getMaxRange()), Math.abs(Yrange.getMinRange()));
    //        
    //        Double maxAbsVal = Math.max(xAbsMax, yAbsMax);

    domainAxis.setAutoRangeIncludesZero(false);

    double xTick = 10.0;
    double yTick = 10.0;

    double xdist = Math.abs(Xrange.getMaxRange() - Xrange.getMinRange());
    double ydist = Math.abs(Yrange.getMaxRange() - Yrange.getMinRange());
    if (xdist < 10.0) {
        xTick = 1.0;
    }

    if (ydist < 10.0) {
        yTick = 1.0;
    }

    //        if (maxAbsVal <= 25.0) {
    //          tickUnit =5.0;
    //        }
    //        else if (maxAbsVal <= 50.0) {
    //          tickUnit = 10.0;
    //        }

    domainAxis.setTickUnit(new NumberTickUnit(xTick));
    rangeAxis.setTickUnit(new NumberTickUnit(yTick));

    //double glyphScaleFactor = (maxAbsVal*2.0)/600.0;   //assuming 600 pixels for the graph
    double xScale = xdist / 600.0;
    //double glyphScaleFactor = 1.0;
    double yScale = ydist / 600.0;

    //double adjAbsVal = Math.ceil(maxAbsVal + (glyphScaleFactor*8.0));

    //domainAxis.setRange(-maxAbsVal, maxAbsVal);
    double xMin = Xrange.getMinRange() - xScale * glyphSize;
    double xMax = Xrange.getMaxRange() + xScale * glyphSize;
    double yMin = Yrange.getMinRange() - yScale * glyphSize;
    double yMax = Yrange.getMaxRange() + yScale * glyphSize;

    domainAxis.setRange(xMin, xMax);

    //rangeAxis.setRange(-maxAbsVal, maxAbsVal);
    rangeAxis.setRange(yMin, yMax);
    Set<SampleInfo> infoSet = new HashSet<SampleInfo>();

    if ((colorBy == ColorByType.IHC_EXPRESSION_X) || (colorBy == ColorByType.IHC_EXPRESSION_Y)) {
        String geneName = null;
        if ((colorBy == ColorByType.IHC_EXPRESSION_X) && (ct1 != ContinuousType.GENE)) {
            logger.info("User attempted to color by ihc x on non gene continuous type.");
            //need to show validation error
            return;
        } else if ((colorBy == ColorByType.IHC_EXPRESSION_Y) && (ct2 != ContinuousType.GENE)) {
            logger.info("User attempted to color by ihc y on non gene continuous type.");
            //need to show validation error
            return;
        } else {
            if (colorBy == ColorByType.IHC_EXPRESSION_X) {
                //parse the gene name from the xLabel
                geneName = xLabel.substring(0, xLabel.indexOf('_'));
            } else if (colorBy == ColorByType.IHC_EXPRESSION_Y) {
                //parse the gene name from the yLabel
                geneName = yLabel.substring(0, yLabel.indexOf('_'));
            }
        }

        //Get the IHC data for the samples to be graphed   
        LevelOfExpressionIHCService loeService = LevelOfExpressionIHCService.getInstance();
        LossOfExpressionIHCService lossService = LossOfExpressionIHCService.getInstance();
        Set<String> sampleIds = new HashSet<String>();
        String labtrackId;
        SampleInfo info;
        for (ISPYPlotPoint corrPoint : dataPoints) {
            info = corrPoint.getSampleInfo();
            if (info != null) {
                labtrackId = corrPoint.getSampleInfo().getLabtrackId();
                sampleIds.add(labtrackId);
                infoSet.add(info);
            } else {
                logger.warn("Point id=" + corrPoint.getId() + " has no sample info. Skipping point");
            }
        }

        Collection<? extends Finding> loeFindings = loeService.getFindingsFromSampleInfo(infoSet);
        Collection<? extends Finding> lossFindings = lossService.getFindingsFromSampleInfo(infoSet);

        List<IHCFinding> findings = new ArrayList<IHCFinding>();

        for (Finding f : loeFindings) {
            findings.add((IHCFinding) f);
        }

        for (Finding f : lossFindings) {
            findings.add((IHCFinding) f);
        }

        //        Need to handle mapping names to IHC biomarker names.
        //EGFR (ok), FAK (PTK2), HER2 (ERBB2), Ki-67, P53, bcl2 (ok), p27, CYCLIN_D1 (CCND1)
        //Translate the gene names into the biomarker names 
        //used by ihc. This code should be removed once protein biomarker
        //alias is implmented.
        String ihcBiomarker = geneName;
        if (geneName.equalsIgnoreCase("PTK2")) {
            ihcBiomarker = "FAK";
            ihcBiomarkerType = IHCBiomarkerType.FAK;
        } else if (geneName.equalsIgnoreCase("ERBB2")) {
            ihcBiomarker = "HER2";
            ihcBiomarkerType = IHCBiomarkerType.HER2;
        } else if (geneName.equalsIgnoreCase("MKI67")) {
            //need to check this one
            ihcBiomarker = "Ki-67";
            ihcBiomarkerType = IHCBiomarkerType.KI67;
        } else if (geneName.equalsIgnoreCase("TP53")) {
            ihcBiomarker = "P53";
            ihcBiomarkerType = IHCBiomarkerType.P53;
        } else if (geneName.equalsIgnoreCase("Cdkn1b")) {
            ihcBiomarker = "P27";
            ihcBiomarkerType = IHCBiomarkerType.P27;
        } else if (geneName.equalsIgnoreCase("BCL2")) {
            ihcBiomarker = "BCL2";
            ihcBiomarkerType = IHCBiomarkerType.BCL2;
        } else if (geneName.equalsIgnoreCase("EGFR")) {
            ihcBiomarker = "EGFR";
            ihcBiomarkerType = IHCBiomarkerType.EGFR;
        } else if (geneName.equalsIgnoreCase("CCND1")) {
            ihcBiomarker = "CYCLIN_D1";
            ihcBiomarkerType = IHCBiomarkerType.CYCLIN_D1;
        }

        List<IHCFinding> filteredList = getIHCFindingsForBiomarker(findings, ihcBiomarker);

        //TEST Case
        //          Set<String> testIds = new HashSet<String>();
        //          testIds.add("212833");
        //          testIds.add("213152");

        //Collection<? extends Finding> loeFindings = loeService.getFindingsFromSampleIds(testIds);

        //Collection<? extends Finding> lossFindings = lossService.getFindingsFromSampleIds(sampleIds);

        ihcData = new HashMap<String, List<IHCFinding>>();
        IHCFinding loeFinding;
        List<IHCFinding> findingList;
        Specimen specimen = null;
        String patientDID = null;
        for (Finding finding : filteredList) {
            loeFinding = (IHCFinding) finding;
            specimen = loeFinding.getSpecimen();
            if ((specimen != null) && (specimen.getPatientDID() != null)) {
                patientDID = specimen.getPatientDID();
                findingList = ihcData.get(patientDID);

                if (findingList == null) {
                    findingList = new ArrayList<IHCFinding>();
                    ihcData.put(patientDID, findingList);
                }

                findingList.add(loeFinding);
            } else {
                logger.warn(
                        "loeFinding id=" + loeFinding.getId() + " has null specimen or patientDID. Skipping..");
            }

        }
        //          IHCFinding lossFinding;
        //          for (Finding finding : lossFindings) {
        //           lossFinding = (IHCFinding) finding;
        //            ihcData.put(lossFinding.getId(), lossFinding);
        //          }

    }

    createGlyphsAndAddToPlot(plot, xScale, yScale);

    // Paint p = new GradientPaint(0, 0, Color.white, 1000, 0, Color.green);
    //try and match the UI e9e9e9
    Paint p = new Color(233, 233, 233);

    corrChart.setBackgroundPaint(p);

    buildLegend();

}

From source file:MSUmpire.DIA.RTAlignedPepIonMapping.java

private void GenerateRTMapPNG(XYSeriesCollection xySeriesCollection, XYSeries series, float R2)
        throws IOException {
    new File(Workfolder + "/RT_Mapping/").mkdir();
    String pngfile = Workfolder + "/RT_Mapping/"
            + FilenameUtils.getBaseName(LCMSA.mzXMLFileName).substring(0,
                    Math.min(120, FilenameUtils.getBaseName(LCMSA.mzXMLFileName).length() - 1))
            + "_" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName).substring(0,
                    Math.min(120, FilenameUtils.getBaseName(LCMSB.mzXMLFileName).length() - 1))
            + "_RT.png";

    XYSeries smoothline = new XYSeries("RT fitting curve");
    for (XYZData data : regression.PredictYList) {
        smoothline.add(data.getX(), data.getY());
    }/*www .  j  a  va  2 s.c o m*/
    xySeriesCollection.addSeries(smoothline);
    xySeriesCollection.addSeries(series);
    JFreeChart chart = ChartFactory.createScatterPlot("Retention time mapping: R2=" + R2,
            "RT:" + FilenameUtils.getBaseName(LCMSA.mzXMLFileName),
            "RT:" + FilenameUtils.getBaseName(LCMSB.mzXMLFileName), xySeriesCollection,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyPlot = (XYPlot) chart.getPlot();
    xyPlot.setDomainCrosshairVisible(true);
    xyPlot.setRangeCrosshairVisible(true);

    XYItemRenderer renderer = xyPlot.getRenderer();
    renderer.setSeriesPaint(1, Color.blue);
    renderer.setSeriesPaint(0, Color.BLACK);
    renderer.setSeriesShape(1, new Ellipse2D.Double(0, 0, 3, 3));
    renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    renderer.setSeriesStroke(0, new BasicStroke(3.0f));
    xyPlot.setBackgroundPaint(Color.white);
    ChartUtilities.saveChartAsPNG(new File(pngfile), chart, 1000, 600);
}

From source file:PointingMap.java

public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {

    Connection conn = null;//www. ja va 2s .c  om
    Statement stmt = null;
    ResultSet rs = null;
    ResultSetMetaData rsm = null;

    OutputStream out = response.getOutputStream();
    try {

        String dbHost = request.getParameter("dbHost");
        String dbName = request.getParameter("dbName");

        conn = connect(dbHost, dbName);

        // get & plot target catalog
        String targetCatQuery = "select " + "ra2000Hours, dec2000Deg " + "from TargetCat limit 200";

        stmt = conn.createStatement();
        rs = stmt.executeQuery(targetCatQuery);
        rsm = rs.getMetaData();
        //int colCount = rsm.getColumnCount();

        XYSeries series = new XYSeries("Target Catalog");
        int raColIndex = 1;
        int decColIndex = 2;
        while (rs.next()) {
            series.add(rs.getDouble(raColIndex), rs.getDouble(decColIndex));
        }

        XYDataset data = new XYSeriesCollection(series);
        stmt.close();

        // Get latest primary beam pointing position
        String latestPointingQuery = "select " + "actId, ts, " + "raHours, decDeg " + "from TscopePointReq "
                + "where atabeam = 'primary' " + "order by actId desc limit 1";

        stmt = conn.createStatement();
        rs = stmt.executeQuery(latestPointingQuery);
        rsm = rs.getMetaData();
        //int colCount = rsm.getColumnCount();

        int actId = -1;
        String timeString = "";
        double pointingRaHours = -1;
        double pointingDecDeg = -1;

        int actIdIndex = 1;
        int timeIndex = 2;
        raColIndex = 3;
        decColIndex = 4;

        while (rs.next()) {
            actId = rs.getInt(actIdIndex);
            timeString = rs.getString(timeIndex);
            pointingRaHours = rs.getDouble(raColIndex);
            pointingDecDeg = rs.getDouble(decColIndex);
        }

        String plotTitle = "ATA Primary Pointing" + " (Act Id: " + actId + ")" + " " + timeString;

        JFreeChart chart = ChartFactory.createScatterPlot(plotTitle, "RA (Hours)", // x-axis label
                "Dec (Deg)", // y axis label
                data, PlotOrientation.VERTICAL, false, // legend 
                true, // tooltips
                false // urls
        );

        // plot RA hours with higher values to the left
        //chart.getXYPlot().getDomainAxis().setInverted(true);
        chart.getXYPlot().getDomainAxis().setLowerBound(-1);
        chart.getXYPlot().getDomainAxis().setUpperBound(25);

        // increase axis label fonts for better readability
        Font axisFont = new Font("Serif", Font.BOLD, 14);
        chart.getXYPlot().getDomainAxis().setLabelFont(axisFont);
        chart.getXYPlot().getDomainAxis().setTickLabelFont(axisFont);
        chart.getXYPlot().getRangeAxis().setLabelFont(axisFont);
        chart.getXYPlot().getRangeAxis().setTickLabelFont(axisFont);

        // show current pointing as crosshairs
        chart.getXYPlot().setDomainCrosshairValue(pointingRaHours);
        chart.getXYPlot().setRangeCrosshairValue(pointingDecDeg);
        chart.getXYPlot().setDomainCrosshairVisible(true);
        chart.getXYPlot().setRangeCrosshairVisible(true);
        chart.getXYPlot().setDomainCrosshairPaint(Color.BLACK);
        chart.getXYPlot().setRangeCrosshairPaint(Color.BLACK);

        Stroke stroke = new BasicStroke(2);
        chart.getXYPlot().setDomainCrosshairStroke(stroke);
        chart.getXYPlot().setRangeCrosshairStroke(stroke);

        // set hat creek dec range
        chart.getXYPlot().getRangeAxis().setLowerBound(-40);
        chart.getXYPlot().getRangeAxis().setUpperBound(90);

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) chart.getXYPlot().getRenderer();
        int seriesIndex = 0;
        renderer.setSeriesPaint(seriesIndex, Color.BLUE);

        Shape circularShape = new Ellipse2D.Double(-1.0, -1.0, 1.2, 1.2);
        renderer.setSeriesShape(seriesIndex, circularShape);

        // Default shape [0-9]: 0=square 1=circle 2=uptriangle 3=diamond...
        //renderer.setShape(DefaultDrawingSupplier.DEFAULT_SHAPE_SEQUENCE[1]);
        response.setContentType("image/png");
        int width = 800;
        int height = 600;
        ChartUtilities.writeChartAsPNG(out, chart, width, height);

    } catch (Exception e) {
        throw new ServletException(e);
    } finally {

        try {
            if (stmt != null) {
                stmt.close();
            }

            if (conn != null) {
                conn.close();
            }

        } catch (SQLException sql) {
        }

    }

}

From source file:org.yooreeka.util.gui.ScatterGui.java

public final JFreeChart createScatterPlot(double[] valX, double[] valY) {

    XYSeries xydata = null;/*  w  w w .j  av a  2 s  . com*/

    if (checkX(valX) && checkY(valX.length, valY)) {

        xydata = new XYSeries(getTitle());

        for (int i = 0; i < loopInt; i++) {
            xydata.add(valX[i], valY[i]);
        }
    } else {
        P.println(errMsg.toString());
    }

    XYSeriesCollection xycollection = new XYSeriesCollection(xydata);

    //TODO: Externalize the hardcoded values later
    final JFreeChart chart = ChartFactory.createScatterPlot(getTitle() + " (Scatter Plot)", getXLabel(),
            getYLabel(), xycollection, PlotOrientation.VERTICAL, true, // does it have a legend?
            true, // does it have tooltips?
            false); // does it have URLs?

    return chart;
}

From source file:uk.ac.rdg.evoportal.pages.ScaleTestDetail.java

public ScaleTestDetail(PageParameters params) {
    String idStr = params.getString("id");
    final long testID = Long.parseLong(idStr);
    ScaleTest scaleTest = ScaleTestsDataProvider.get(testID);
    int percentageDone = scaleTest.getPercentageDone();
    String testName = scaleTest.getLabel();
    int iterations = scaleTest.getIterations();
    add(new Label("id", idStr));
    add(new Label("name", testName));
    add(new Label("its", Integer.toString(iterations)));
    add(new Label("pcDone", percentageDone + "%"));
    add(new TextArea("controlBlock", new Model<String>(scaleTest.getBPBlock())));
    SortedSet<Integer> nodesSet = new TreeSet<Integer>();
    List<ScaleTestComputeJob> results = scaleTest.getScaleTestComputeJobs();
    double[][] runSeries = new double[2][results.size()];
    int j = 0;//from   w w w  . j a  va  2s.com
    double testSize = (double) iterations;
    for (Iterator<ScaleTestComputeJob> i = results.iterator(); i.hasNext();) {
        ScaleTestComputeJob result = i.next();
        int nodes = result.getNodes();
        int duration = result.getDuration();
        runSeries[0][j] = (double) nodes;
        runSeries[1][j] = (double) duration; // in seconds
        nodesSet.add(result.getNodes());
        double m = ((double) duration / testSize);
        calc.putMultipler(nodes, m);
        j++;
    }
    List<Integer> iterationsChoices = Arrays.asList(
            new Integer[] { 100000, 200000, 300000, 400000, 500000, 1000000, 1200000, 1300000, 1400000, 1500000,
                    2000000, 3000000, 4000000, 5000000, 6000000, 7000000, 8000000, 9000000, 10000000 });
    Form calcForm = new Form("calcForm", new CompoundPropertyModel(calc));
    calcForm.setVisible(false);
    // only render image if test is completed with all jobs stopped
    boolean isResultsReady = percentageDone == 100;
    if (isResultsReady) {
        DefaultXYDataset xyData = new DefaultXYDataset();
        xyData.addSeries(testName, runSeries);
        JFreeChart scaleChart = ChartFactory.createScatterPlot("Scale test results for " + testName,
                "Number of nodes", "Time to run in seconds", xyData, PlotOrientation.VERTICAL, true, true,
                true);
        add(new ScaleTestResultsChart("chart", scaleChart, 600, 300));
        calc.setIterations(iterationsChoices.get(0));
        calc.setNodes(nodesSet.first());
        calcForm.setVisible(true);
    } else {
        add(new Image("chart"));
    }

    final Label durationText = new Label("durationString");
    durationText.setOutputMarkupId(true);
    DropDownChoice iterationsDropDown = new DropDownChoice("iterations", iterationsChoices);
    iterationsDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(durationText);
        }
    });
    DropDownChoice nodesDropDown = new DropDownChoice("nodes", Arrays.asList(nodesSet.toArray()));
    nodesDropDown.add(new AjaxFormComponentUpdatingBehavior("onchange") {
        @Override
        protected void onUpdate(AjaxRequestTarget target) {
            target.addComponent(durationText);
        }
    });
    calcForm.add(iterationsDropDown);
    calcForm.add(nodesDropDown);
    calcForm.add(durationText);
    add(calcForm);
    ScaleTestComputeJobsDataProvider scaleTestComputeJobsDataProvider = new ScaleTestComputeJobsDataProvider(
            testID);
    add(new ScaleTestComputeJobsDataView("jobDetails", scaleTestComputeJobsDataProvider, testID));
    if (!isResultsReady) {
        AjaxSelfUpdatingTimerBehavior timer = new AjaxSelfUpdatingTimerBehavior(Duration.seconds(15)) {
            @Override
            protected void onPostProcessTarget(AjaxRequestTarget target) {
                ScaleTest refreshedScaleTest = ScaleTestsDataProvider.get(testID);
                int pcDone = refreshedScaleTest.getPercentageDone();
                get("pcDone").replaceWith(new Label("pcDone", pcDone + "%"));
                if (pcDone == 100) {
                    setResponsePage(ScaleTestDetail.class, new PageParameters("id=" + testID));
                }
            }
        };
        add(timer);
    }
}

From source file:org.limy.eclipse.qalab.task.DistanceGraphTask.java

/**
 * @param dataset /*  w ww. j  a  v a  2  s  .c om*/
 * @throws IOException 
 * 
 */
private void drawGraph(XYDataset dataset) throws IOException {

    JFreeChart chart = ChartFactory.createScatterPlot("Distance from the Main Sequence", "Instability",
            "Abstractness", dataset, PlotOrientation.VERTICAL, false, false, false);

    XYPlot plot = chart.getXYPlot();

    plot.getRenderer().addAnnotation(
            new XYLineAnnotation(-0.1, 1.1, 1.1, -0.1, new BasicStroke(2), new Color(50, 220, 50)),
            Layer.BACKGROUND);

    plot.getRenderer().setShape(new Ellipse2D.Double(-4, -4, 8, 8));
    plot.getRenderer().setPaint(new Color(0xec, 0x76, 0x37));

    plot.getDomainAxis().setRangeWithMargins(0, 1);
    plot.getRangeAxis().setRangeWithMargins(0, 1);

    chart.getTitle().setPaint(Color.BLUE);

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairPaint(Color.GRAY);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairPaint(Color.GRAY);

    LimyGraphUtils.writeImagePng(chart, out, 400, 380);

}

From source file:org.gwaspi.gui.qqPlot.java

/**
 * Runs the test.// w  w w .j  a  v  a  2s  .co m
 */
public void run() {

    this.finished = false;

    List<XYSeries> seriesArray = new ArrayList<XYSeries>();

    Random generator = new Random();
    int seriesNb = -1;
    XYSeriesCollection dataSeries = new XYSeriesCollection();
    XYSeries seriesData = new XYSeries("X");
    XYSeries seriesUpper = new XYSeries("Upper bound");
    XYSeries seriesLower = new XYSeries("Lower bound");

    int N = 10000;
    List<Double> rndChiSqrDist1 = org.gwaspi.statistics.Chisquare.getChiSquareDistributionDf1(N, 1.0f);
    Collections.sort(rndChiSqrDist1);
    List<Double> rndChiSqrDist2 = org.gwaspi.statistics.Chisquare.getChiSquareDistributionDf1(N, 1.0f);
    Collections.sort(rndChiSqrDist2);
    for (int i = 0; i < rndChiSqrDist1.size(); i++) {
        double obsVal = rndChiSqrDist1.get(i) + (generator.nextDouble() * 0.00001);
        double expVal = rndChiSqrDist2.get(i);

        // constant chi-square boundaries
        //         double upperVal = expVal*1.05;
        //         double lowerVal = expVal*0.95;
        //         double upperVal = expVal+Math.pow(Math.E,(1.96*Math.sqrt(1/expVal)));
        //         double lowerVal = expVal-Math.pow(Math.E,(1.96*Math.sqrt(1/expVal)));
        double upperVal = expVal + 1.96 * Math.sqrt(0.05 * (1 - 0.05 / N));
        double lowerVal = expVal - 1.96 * Math.sqrt(0.05 * (1 - 0.05 / N));

        seriesData.add(obsVal, expVal);
        seriesLower.add(expVal, lowerVal);
        seriesUpper.add(expVal, upperVal);
    }

    dataSeries.addSeries(seriesData);
    dataSeries.addSeries(seriesLower);
    dataSeries.addSeries(seriesUpper);
    final XYDataset data = dataSeries;

    // create a scatter chart...
    final boolean withLegend = true;
    JFreeChart chart = ChartFactory.createScatterPlot("QQ-plot", "Obs X", "Exp X", data,
            PlotOrientation.VERTICAL, withLegend, false, false);

    final XYPlot plot = chart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.gray);
    renderer.setSeriesPaint(2, Color.gray);

    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setSeriesShape(0, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));
    renderer.setSeriesShape(1, new Rectangle2D.Double(-2.0, 0.0, 4.0, 0.0));
    renderer.setSeriesShape(2, new Rectangle2D.Double(-2.0, 0.0, 4.0, 0.0));

    plot.setRenderer(renderer);

    try {
        ChartUtilities.saveChartAsPNG(new File(System.getProperty("user.home") + "/Desktop/QQ_plot.png"), chart,
                400, 400);
    } catch (IOException ex) {
        log.error("Problem occurred creating chart", ex);
    }
}