Example usage for org.jfree.chart.axis LogAxis setNumberFormatOverride

List of usage examples for org.jfree.chart.axis LogAxis setNumberFormatOverride

Introduction

In this page you can find the example usage for org.jfree.chart.axis LogAxis setNumberFormatOverride.

Prototype

public void setNumberFormatOverride(NumberFormat formatter) 

Source Link

Document

Sets the number format override and sends a change event to all registered listeners.

Usage

From source file:org.gwaspi.reports.PlinkReportLoaderCombined.java

private static void appendToCombinedRangePlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection tempChrData, boolean showlables) {
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesVisibleInLegend(0, showlables);
    renderer.setSeriesVisibleInLegend(1, showlables);
    //renderer.setBaseShape(new Ellipse2D.Float(0, 0, 2,2), false);

    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);/*  w  w w . ja va  2 s .c  om*/
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(GenericReportGenerator.FORMAT_P_VALUE);

        rangeAxis.setTickMarkOutsideLength(2.0f);
        rangeAxis.setMinorTickCount(2);
        rangeAxis.setMinorTickMarksVisible(true);
        rangeAxis.setAxisLineVisible(true);
        rangeAxis.setAutoRangeMinimumSize(0.0000005);
        rangeAxis.setLowerBound(1d);
        //rangeAxis.setAutoRangeIncludesZero(false);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", tempChrData,
            PlotOrientation.VERTICAL, true, false, false);

    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    final Marker thresholdLine = new ValueMarker(0.0000005);
    thresholdLine.setPaint(Color.red);
    if (showlables) {
        thresholdLine.setLabel("P = 510??");
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setAxisLineVisible(false);
    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    chrAxis.setAutoRangeIncludesZero(false);
    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}

From source file:org.gwaspi.reports.GenericReportGenerator.java

private static void appendToCombinedRangeManhattanPlot(CombinedRangeXYPlot combinedPlot, String chromosome,
        XYSeriesCollection currChrSC, boolean showlables, double threshold, Color background,
        Color backgroundAlternative, Color main) {

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(false, true);

    // Set dot shape of the currently appended Series
    renderer.setSeriesPaint(currChrSC.getSeriesCount() - 1, main);
    renderer.setSeriesVisibleInLegend(currChrSC.getSeriesCount() - 1, showlables);
    renderer.setSeriesShape(currChrSC.getSeriesCount() - 1, new Rectangle2D.Double(-1.0, -1.0, 2.0, 2.0));

    // Set range axis
    if (combinedPlot.getSubplots().isEmpty()) {
        LogAxis rangeAxis = new LogAxis("P value");
        rangeAxis.setBase(10);/*ww  w  . j a va  2s .  c o  m*/
        rangeAxis.setInverted(true);
        rangeAxis.setNumberFormatOverride(FORMAT_P_VALUE);

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

        TickUnitSource units = NumberAxis.createIntegerTickUnits();
        rangeAxis.setStandardTickUnits(units);

        combinedPlot.setRangeAxis(0, rangeAxis);
    }

    // Build subchart
    JFreeChart subchart = ChartFactory.createScatterPlot("", "Chr " + chromosome, "", currChrSC,
            PlotOrientation.VERTICAL, false, false, false);

    // Get subplot from subchart
    XYPlot subplot = (XYPlot) subchart.getPlot();
    subplot.setRenderer(renderer);
    subplot.setBackgroundPaint(null);

    // CHART BACKGROUD COLOR
    if (combinedPlot.getSubplots().size() % 2 == 0) {
        subplot.setBackgroundPaint(background); // Hue, saturation, brightness
    } else {
        subplot.setBackgroundPaint(backgroundAlternative); // Hue, saturation, brightness
    }

    // Add significance Threshold to subplot
    final Marker thresholdLine = new ValueMarker(threshold);
    thresholdLine.setPaint(Color.red);
    // Add legend to hetzyThreshold
    if (showlables) {
        thresholdLine.setLabel("P = " + FORMAT_P_VALUE.format(threshold));
    }
    thresholdLine.setLabelAnchor(RectangleAnchor.TOP_RIGHT);
    thresholdLine.setLabelTextAnchor(TextAnchor.BOTTOM_RIGHT);
    subplot.addRangeMarker(thresholdLine);

    // Chromosome Axis Labels
    NumberAxis chrAxis = (NumberAxis) subplot.getDomainAxis();
    chrAxis.setLabelAngle(1.0);
    chrAxis.setAutoRangeIncludesZero(false);
    chrAxis.setAxisLineVisible(true);

    chrAxis.setTickLabelsVisible(false);
    chrAxis.setTickMarksVisible(false);
    //      chrAxis.setNumberFormatOverride(Report_Analysis.FORMAT_SCIENTIFIC);
    //      TickUnitSource units = NumberAxis.createIntegerTickUnits();
    //      chrAxis.setStandardTickUnits(units);

    //combinedPlot.setGap(0);
    combinedPlot.add(subplot, 1);
}

From source file:netplot.GenericPlotPanel.java

void genericConfig(JFreeChart chart, XYPlot plot, int plotIndex) {
    if (!enableLegend) {
        chart.removeLegend();//from w  w w .  j  a  v  a 2s .c om
    }

    XYItemRenderer xyItemRenderer = plot.getRenderer();
    //May also be XYBarRenderer
    if (xyItemRenderer instanceof XYLineAndShapeRenderer) {
        XYToolTipGenerator xyToolTipGenerator = xyItemRenderer.getBaseToolTipGenerator();
        //If currently an XYLineAndShapeRenderer replace it so that we inc the colour for every plotIndex
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(linesEnabled, shapesEnabled);
        //Ensure we don't loose the tool tips on the new renderer
        renderer.setBaseToolTipGenerator(xyToolTipGenerator);
        renderer.setBasePaint(getPlotColour(plotIndex));
        renderer.setSeriesStroke(0, new BasicStroke(lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL),
                true);
        plot.setRenderer(plotIndex, renderer);
    }

    //If we have a new y axis then we need a new data set
    if (yAxisName != null && yAxisName.length() > 0) {
        if (logYAxis) {
            LogAxis yAxis = new LogAxis(yAxisName);
            yAxis.setAutoRange(false);
            yAxis.setNumberFormatOverride(new LogFormat(10, "10", true));
            yAxis.setRange(minScaleValue, maxScaleValue);
            yAxis.setLowerBound(minScaleValue);
            yAxis.setUpperBound(maxScaleValue);
            plot.setRangeAxis(yAxisIndex, yAxis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        } else {
            NumberAxis axis = new NumberAxis(yAxisName);
            axis.setAutoRangeIncludesZero(zeroOnYScale);
            if (autoScaleEnabled) {
                axis.setAutoRange(true);
            } else {
                Range range = new Range(minScaleValue, maxScaleValue);
                axis.setRangeWithMargins(range, true, true);
            }
            if (yAxisTickCount > 0) {
                NumberTickUnit tick = new NumberTickUnit(yAxisTickCount);
                axis.setTickUnit(tick);
            }
            plot.setRangeAxis(yAxisIndex, axis);
            plot.setRangeAxisLocation(yAxisIndex, AxisLocation.BOTTOM_OR_LEFT);
        }
        yAxisIndex++;
    }
    plot.mapDatasetToRangeAxis(plotIndex, yAxisIndex - 1);
    ValueAxis a = plot.getDomainAxis();
    if (xAxisName.length() > 0) {
        a.setLabel(xAxisName);
    }
    //We can enable/disable zero on the axis if we have a NumberAxis
    if (a instanceof NumberAxis) {
        ((NumberAxis) a).setAutoRangeIncludesZero(zeroOnXScale);
    }
}

From source file:net.sf.mzmine.modules.visualization.scatterplot.scatterplotchart.ScatterPlotChart.java

public ScatterPlotChart(ScatterPlotTopPanel topPanel, PeakList peakList) {

    super(null, true);

    this.peakList = peakList;
    this.topPanel = topPanel;

    // initialize the chart by default time series chart from factory
    chart = ChartFactory.createXYLineChart("", // title
            "", // x-axis label
            "", // y-axis label
            null, // data set
            PlotOrientation.VERTICAL, // orientation
            false, // create legend
            false, // generate tooltips
            false // generate URLs
    );//from  w ww.j  a v  a2 s . com

    chart.setBackgroundPaint(Color.white);
    setChart(chart);

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

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    plot.setSeriesRenderingOrder(SeriesRenderingOrder.FORWARD);
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // Set the domain log axis
    LogAxis logAxisDomain = new LogAxis();
    logAxisDomain.setMinorTickCount(1);
    logAxisDomain.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat());
    logAxisDomain.setAutoRange(true);
    plot.setDomainAxis(logAxisDomain);

    // Set the range log axis
    LogAxis logAxisRange = new LogAxis();
    logAxisRange.setMinorTickCount(1);
    logAxisRange.setNumberFormatOverride(MZmineCore.getConfiguration().getIntensityFormat());
    logAxisRange.setAutoRange(true);
    plot.setRangeAxis(logAxisRange);

    // Set crosshair properties
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    // Create data sets;
    mainDataSet = new ScatterPlotDataSet(peakList);
    plot.setDataset(0, mainDataSet);
    diagonalLineDataset = new DiagonalLineDataset();
    plot.setDataset(1, diagonalLineDataset);

    // Create renderers
    mainRenderer = new ScatterPlotRenderer();
    plot.setRenderer(0, mainRenderer);
    diagonalLineRenderer = new DiagonalLineRenderer();
    plot.setRenderer(1, diagonalLineRenderer);

    // Set tooltip properties
    ttm = new ComponentToolTipManager();
    ttm.registerComponent(this);
    setDismissDelay(Integer.MAX_VALUE);
    setInitialDelay(0);

    // add items to popup menu TODO: add other Show... items
    JPopupMenu popupMenu = getPopupMenu();
    popupMenu.addSeparator();
    GUIUtils.addMenuItem(popupMenu, "Show Chromatogram", this, "TIC");

}

From source file:ecosim.gui.SummaryPane.java

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

From source file:com.wattzap.view.graphs.MMPGraph.java

public MMPGraph(XYSeries series) {
    super();/*from w  w w .jav  a 2  s. com*/

    NumberAxis yAxis = new NumberAxis(userPrefs.messages.getString("poWtt"));
    yAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    double maxY = series.getMaxY();
    yAxis.setRange(0, maxY + 20);
    yAxis.setTickLabelPaint(Color.white);
    yAxis.setLabelPaint(Color.white);

    LogAxis xAxis = new LogAxis(userPrefs.messages.getString("time"));
    xAxis.setTickLabelPaint(Color.white);
    xAxis.setBase(4);
    xAxis.setAutoRange(false);

    xAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    xAxis.setRange(1, series.getMaxX() + 500);
    xAxis.setNumberFormatOverride(new NumberFormat() {

        @Override
        public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos) {

            long millis = (long) number * 1000;

            if (millis >= 60000) {
                return new StringBuffer(String.format("%d m %d s",
                        TimeUnit.MILLISECONDS.toMinutes((long) millis),
                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            } else {
                return new StringBuffer(String.format("%d s",

                        TimeUnit.MILLISECONDS.toSeconds((long) millis)
                                - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes((long) millis))));
            }
        }

        @Override
        public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos) {
            return new StringBuffer(String.format("%s", number));
        }

        @Override
        public Number parse(String source, ParsePosition parsePosition) {
            return null;
        }
    });

    XYPlot plot = new XYPlot(new XYSeriesCollection(series), xAxis, yAxis,
            new XYLineAndShapeRenderer(true, false));

    JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);

    chart.setBackgroundPaint(Color.gray);
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.darkGray);
    /*plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);*/

    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelPaint(Color.white);
    domainAxis.setLabelPaint(Color.white);

    chartPanel = new ChartPanel(chart);
    chartPanel.setSize(100, 800);
    chartPanel.setFillZoomRectangle(true);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setBackground(Color.gray);

    setLayout(new BorderLayout());
    add(chartPanel, BorderLayout.CENTER);
    setBackground(Color.black);
    chartPanel.revalidate();
    setVisible(true);
}

From source file:org.pf.midea.SimulationController.java

@Override
public void run() {
    textAreaNumeric.setText("");
    XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
    double progress = 0;
    double progressStep = 100.0 / (planCells.length * (hSquareHigh - hSquareLow + hSquareStep) / hSquareStep);
    progressBar.setValue(0);//from w  w  w .  j  av a  2  s .c om
    for (int i = 0; i < planCells.length; i++) {
        XYSeries xySeries;
        if (showLineNumbers)
            xySeries = new XYSeries(String.valueOf(i + 1) + ") " + planCells[i].getShortDescription());
        else
            xySeries = new XYSeries(planCells[i].getShortDescription());
        textAreaNumeric.append(planCells[i].getDescription() + "\n");
        textAreaNumeric.setCaretPosition(textAreaNumeric.getDocument().getLength());

        PlanStates.SourceType currentSourceType = planCells[i].getSourceCell().getSourceType();
        PlanStates.CodeType currentCodeType = planCells[i].getCodeCell().getCodeType();
        PlanStates.ModulationType currentModulationType = planCells[i].getModulationCell().getModulationType();
        PlanStates.ChannelType currentChannelType = planCells[i].getChannelCell().getChannelType();
        PlanStates.ErrorsType currentErrorsType = planCells[i].getErrorsCell().getErrorsType();

        BinaryNumber[] sourcePoints = null;
        switch (currentSourceType) {
        case ST_TEST:
            sourcePoints = ConstellationPointsGenerator.getTestPoints(currentModulationType, iterationsCount);
            break;
        case ST_RANDOM:
            sourcePoints = ConstellationPointsGenerator.getRandomPoints(currentModulationType, iterationsCount);
            break;
        }

        Coder coder = null;
        Decoder decoder = null;
        switch (currentCodeType) {
        case CT_NONE:
            coder = new CoderNone();
            decoder = new DecoderNone();
            break;
        case CT_HAMMING74:
            coder = new CoderHamming74();
            decoder = new DecoderHamming74();
            break;
        case CT_CYCLIC:
            coder = new CoderCyclic85();
            decoder = new DecoderCyclic85();
            break;
        case CT_BCH155:
            coder = new CoderBCH155();
            decoder = new DecoderBCH155();
            break;
        }

        Modulator modulator = null;
        Demodulator demodulator = null;
        switch (currentModulationType) {
        case MT_ASK:
            modulator = new ModulatorASK();
            demodulator = new DemodulatorASK();
            break;
        case MT_FSK:
            modulator = new ModulatorFSK();
            demodulator = new DemodulatorFSK();
            break;
        case MT_BPSK:
            modulator = new ModulatorBPSK();
            demodulator = new DemodulatorBPSK();
            break;
        case MT_QPSK:
            modulator = new ModulatorQPSK();
            demodulator = new DemodulatorQPSK();
            break;
        case MT_8PSK:
            modulator = new Modulator8PSK();
            demodulator = new Demodulator8PSK();
            break;
        case MT_16PSK:
            modulator = new Modulator16PSK();
            demodulator = new Demodulator16PSK();
            break;
        case MT_32PSK:
            modulator = new Modulator32PSK();
            demodulator = new Demodulator32PSK();
            break;
        case MT_16QAM:
            modulator = new Modulator16QAM();
            demodulator = new Demodulator16QAM();
            break;
        case MT_32QAM:
            modulator = new Modulator32QAM();
            demodulator = new Demodulator32QAM();
            break;
        case MT_64QAM:
            modulator = new Modulator64QAM();
            demodulator = new Demodulator64QAM();
            break;
        case MT_256QAM:
            modulator = new Modulator256QAM();
            demodulator = new Demodulator256QAM();
            break;
        }

        Channel channel = null;
        switch (currentChannelType) {
        case CHT_AWGN:
            channel = new ChannelAWGN();
            break;
        case CHT_RAYLEIGH:
            channel = new ChannelRayleigh();
            break;
        }

        BinaryNumber[] encoded = coder.encode(sourcePoints);
        Signal[] modulated = modulator.modulate(encoded);

        double error = 0;

        for (double h = hSquareLow; h <= hSquareHigh; h += hSquareStep) {
            double realH;
            if (dBs)
                realH = StatisticsTools.decibelsToTimes(h);
            else
                realH = h;

            Signal[] noised = channel.noise(realH, modulated);
            BinaryNumber[] demodulated = demodulator.demodulate(noised);
            noised = null;
            System.gc();
            BinaryNumber[] decoded = decoder.decode(demodulated);
            demodulated = null;
            System.gc();
            switch (currentErrorsType) {
            case ET_SER:
                error = StatisticsTools.getSER(sourcePoints, decoded);
                break;
            case ET_BER:
                error = StatisticsTools.getBER(sourcePoints, decoded);
                break;
            }
            decoded = null;
            System.gc();

            if (error > 0) {
                xySeries.add(h, error);
                textAreaNumeric.append(String.valueOf(h) + "\t" + String.valueOf(error) + "\n");
                textAreaNumeric.setCaretPosition(textAreaNumeric.getDocument().getLength());
            }

            progress += progressStep;
            progressBar.setValue((int) Math.round(progress));
        }
        xySeriesCollection.addSeries(xySeries);
        textAreaNumeric.append("\n");
        textAreaNumeric.setCaretPosition(textAreaNumeric.getDocument().getLength());
    }

    JFreeChart chart = ChartFactory.createXYLineChart("", dBs ? "" : "", "?",
            xySeriesCollection, PlotOrientation.VERTICAL, true, true, false);
    chart.getLegend().setPosition(RectangleEdge.RIGHT);
    XYPlot xyPlot = chart.getXYPlot();

    for (int i = 0; i < planCells.length; i++) {
        xyPlot.getRenderer().setSeriesStroke(i, new BasicStroke(planCells[i].getLineWidth()));
        if (planCells[i].getLineColor() != null)
            xyPlot.getRenderer().setSeriesPaint(i, planCells[i].getLineColor());

        if (showLineNumbers) {
            XYSeries currentSeries = xySeriesCollection.getSeries(i);
            double annotationY = currentSeries.getY(0).doubleValue();
            double annotationX = currentSeries.getX(0).doubleValue();
            for (int j = 1; j < currentSeries.getItemCount(); j++)
                if (currentSeries.getY(j).doubleValue() == 0) {
                    annotationY = currentSeries.getY(j - 1).doubleValue();
                    annotationX = currentSeries.getX(j - 1).doubleValue();
                    break;
                } else {
                    annotationY = currentSeries.getY(j).doubleValue();
                    annotationX = currentSeries.getX(j).doubleValue();
                }
            XYTextAnnotation annotation = new XYTextAnnotation(String.valueOf(i + 1), annotationX, annotationY);
            annotation.setBackgroundPaint(Color.WHITE);
            annotation.setFont(new Font("Dialog", 0, 14));
            xyPlot.addAnnotation(annotation);
        }
    }

    xyPlot.setBackgroundPaint(Color.WHITE);
    xyPlot.setDomainGridlinePaint(Color.GRAY);
    xyPlot.setRangeGridlinePaint(Color.GRAY);
    NumberAxis domainAxis = new NumberAxis("h, " + (dBs ? "" : ""));
    LogAxis rangeAxis = new LogAxis("?");
    rangeAxis.setNumberFormatOverride(new HumanNumberFormat(1));
    domainAxis.setTickLabelFont(new Font("Dialog", 0, 14));
    rangeAxis.setTickLabelFont(new Font("Dialog", 0, 14));
    xyPlot.setDomainAxis(domainAxis);
    xyPlot.setRangeAxis(rangeAxis);

    ChartPanel nestedPanel = new ChartPanel(chart);
    chartPanel.removeAll();
    chartPanel.add(nestedPanel, new CellConstraints());
    chartPanel.updateUI();
}

From source file:edu.fullerton.viewerplugin.XYPlotter.java

private ChartPanel getPanel(double[][] data) throws WebUtilException {
    ChartPanel ret = null;/*from  ww w  .  jav  a2  s  .  c om*/
    try {
        XYSeries xys;
        XYSeriesCollection mtds = new XYSeriesCollection();
        String mylegend = legend == null || legend.isEmpty() ? "series 1" : legend;

        xys = new XYSeries(legend);

        int len = data.length;
        double minx = Double.MAX_VALUE;
        double maxx = Double.MIN_VALUE;
        double miny = Double.MAX_VALUE;
        double maxy = Double.MIN_VALUE;
        boolean gotZeroX = false;
        boolean gotZeroY = false;

        for (int i = 0; i < len; i++) {
            double x = data[i][0];
            double y = data[i][1];
            if (x == 0) {
                gotZeroX = true;
            } else {
                minx = Math.min(minx, x);
                maxx = Math.max(maxx, x);
            }
            if (y == 0) {
                gotZeroY = true;
            } else {
                miny = Math.min(miny, y);
                maxy = Math.max(maxy, y);
            }
        }
        // this kludge lets us plot a 0 on a log axis
        double fakeZeroX = 0.;
        double fakeZeroY = 0.;
        if (gotZeroX) {
            if (logXaxis) {
                fakeZeroX = minx / 10;
            } else {
                minx = Math.min(0, minx);
                maxx = Math.max(0, maxx);
            }
        }
        if (gotZeroY) {
            if (logYaxis) {
                fakeZeroY = miny / 10;
            } else {
                miny = Math.min(0, miny);
                maxy = Math.max(0, maxy);
            }
        }
        for (int i = 0; i < len; i++) {
            double x = data[i][0];
            double y = data[i][1];
            x = x == 0 ? fakeZeroX : x;
            y = y == 0 ? fakeZeroY : y;
            xys.add(x, y);
        }
        mtds.addSeries(xys);

        DefaultXYDataset ds = new DefaultXYDataset();

        int exp;
        if (maxy == 0. && miny == 0.) {
            miny = -1.;
            exp = 0;
            logYaxis = false;
        } else {

            maxy = maxy > miny ? maxy : miny * 10;
            exp = PluginSupport.scaleRange(mtds, miny, maxy);
            if (!logYaxis && exp > 0) {
                yLabel += " x 1e-" + Integer.toString(exp);
            }
        }
        JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, ds, PlotOrientation.VERTICAL,
                true, false, false);
        org.jfree.chart.plot.XYPlot plot = (org.jfree.chart.plot.XYPlot) chart.getPlot();
        if (logYaxis) {
            LogAxis rangeAxis = new LogAxis(yLabel);
            double smallest = miny * Math.pow(10, exp);
            rangeAxis.setSmallestValue(smallest);
            rangeAxis.setMinorTickCount(9);

            LogAxisNumberFormat lanf = new LogAxisNumberFormat();
            lanf.setExp(exp);
            rangeAxis.setNumberFormatOverride(lanf);
            rangeAxis.setRange(smallest, maxy * Math.pow(10, exp));
            plot.setRangeAxis(rangeAxis);
        }
        if (logXaxis) {
            LogAxis domainAxis = new LogAxis(xLabel);
            domainAxis.setMinorTickCount(9);
            domainAxis.setSmallestValue(minx);
            domainAxis.setNumberFormatOverride(new LogAxisNumberFormat());
            plot.setDomainAxis(domainAxis);
        }
        ValueAxis domainAxis = plot.getDomainAxis();
        if (fmin != null && fmin > 0) {
            domainAxis.setLowerBound(fmin);
        }
        if (fmax != null && fmax > 0) {
            domainAxis.setUpperBound(fmax);
        }
        plot.setDomainAxis(domainAxis);
        plot.setDataset(0, mtds);

        // Set the line thickness
        XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
        BasicStroke str = new BasicStroke(lineThickness);
        int n = plot.getSeriesCount();
        for (int i = 0; i < n; i++) {
            r.setSeriesStroke(i, str);
        }

        if (legend == null || legend.isEmpty()) {
            chart.removeLegend();
        }
        ret = new ChartPanel(chart);
    } catch (Exception ex) {
        throw new WebUtilException("Creating spectrum plot" + ex.getLocalizedMessage());
    }
    return ret;

}

From source file:eu.planets_project.tb.impl.chart.ExperimentChartServlet.java

public JFreeChart createXYChart(String expId) {
    ExperimentPersistencyRemote edao = ExperimentPersistencyImpl.getInstance();
    long eid = Long.parseLong(expId);
    log.info("Building experiment chart for eid = " + eid);
    Experiment exp = edao.findExperiment(eid);

    final String expName = exp.getExperimentSetup().getBasicProperties().getExperimentName();
    final XYSeries series = new XYSeries(expName);

    for (BatchExecutionRecordImpl batch : exp.getExperimentExecutable().getBatchExecutionRecords()) {
        int i = 1;
        for (ExecutionRecordImpl exr : batch.getRuns()) {
            //log.info("Found Record... "+exr+" stages: "+exr.getStages());
            if (exr != null && exr.getStages() != null) {
                // Look up the object, so we can get the name.
                DigitalObjectRefBean dh = new DataHandlerImpl().get(exr.getDigitalObjectReferenceCopy());
                String dobName = "Object " + i;
                if (dh != null)
                    dobName = dh.getName();

                for (ExecutionStageRecordImpl exsr : exr.getStages()) {
                    Double time = exsr.getDoubleMeasurement(TecRegMockup.PROP_SERVICE_TIME);
                    Double size = exsr.getDoubleMeasurement(TecRegMockup.PROP_DO_SIZE);
                    // Look for timing:
                    if (time != null && size != null && size.doubleValue() > 0.0 && time.doubleValue() > 0.0) {
                        series.add(size, time);
                        /*
                        if( exsr.isMarkedAsSuccessful() ) {
                        dataset.addValue( time, "Succeded", dobName);
                        } else {//  www . ja v a2 s  .com
                        dataset.addValue( time, "Failed", dobName);
                        }
                        */
                    }
                }
            }
            // Increment, for the next run.
            i++;
        }
    }
    // Create the chart.
    JFreeChart chart = ChartFactory.createScatterPlot(null, "Size [bytes]", "Time [s]",
            new XYSeriesCollection(series), PlotOrientation.VERTICAL, true, true, false);

    XYPlot plot = (XYPlot) chart.getPlot();
    LogAxis xAxis = new LogAxis("Size [bytes]");
    // Set the base appropriately:
    xAxis.setBase(1024.0);
    //        xAxis.setTickUnit( new NumberTickUnit(128.0) );
    //        xAxis.getTickUnit().getMinorTickCount();
    // FIXME This should really be a KB/MB/etc number formatter...
    xAxis.setNumberFormatOverride(new LogFormat(1024.0, "1024", true));
    //        LogAxis yAxis = new LogAxis("Y");
    //        yAxis.setNumberFormatOverride(new LogFormat(10.0, "10", true));
    plot.setDomainAxis(xAxis);
    //        plot.setRangeAxis(yAxis);

    // Add some tool-tips
    plot.getRenderer().setBaseToolTipGenerator(new StandardXYToolTipGenerator());

    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  ww .  j  ava  2  s  .c  o  m

    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;
}