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

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

Introduction

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

Prototype

public void setBase(double base) 

Source Link

Document

Sets the base for the logarithm calculation 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);
        rangeAxis.setInverted(true);/*from  w w  w  .j  a  v  a 2s  .c o  m*/
        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:umberto.WeightedClusterCoefficient.ChartUtils.java

public static void scaleLogChart(JFreeChart chart, XYSeries dSeries, boolean normalized) {
    XYPlot plot = (XYPlot) chart.getPlot();
    final LogAxis logyAxis = new LogAxis(plot.getRangeAxis().getLabel());
    final LogAxis logxAxis = new LogAxis(plot.getDomainAxis().getLabel());
    //Set y axis format.
    //        DecimalFormat formaty = (DecimalFormat) DecimalFormat.getNumberInstance(Locale.ENGLISH);
    //        formaty.applyPattern("#0.0000");

    //set y axis/*from w  w w  . j a  va2s .c o m*/
    logyAxis.setBase(10);
    //        logyAxis.setNumberFormatOverride(formaty);
    logyAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH));
    //        logyAxis.setRange(0.01, 1.0);
    logyAxis.setAutoRange(true);
    plot.setRangeAxis(logyAxis);
    //set x axis
    logxAxis.setBase(10);
    logxAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.ENGLISH));
    logxAxis.setAutoRange(true);
    //logxAxis.setRange(0.00001, 1.0);//Se la voglio zoommare
    plot.setDomainAxis(logxAxis);
}

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);
        rangeAxis.setInverted(true);//from  w  ww .  j a  v  a2s.  co  m
        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:org.jgrasstools.gears.utils.chart.Scatter.java

public JFreeChart getChart() {
    if (chart == null) {
        chart = ChartFactory.createXYLineChart(title, // chart title
                xLabel,//  w w w.  j av  a 2 s. c  o m
                // domain axis label
                yLabel,
                // range axis label
                dataset,
                // data
                PlotOrientation.VERTICAL,
                // orientation
                false,
                // include legend
                true,
                // tooltips?
                false
        // URLs?
        );

        XYPlot plot = (XYPlot) chart.getPlot();
        if (xLog) {
            LogAxis xAxis = new LogAxis("");
            xAxis.setBase(10);
            plot.setDomainAxis(xAxis);
        }
        if (yLog) {
            LogAxis yAxis = new LogAxis("");
            yAxis.setBase(10);
            plot.setRangeAxis(yAxis);
        }

        ValueAxis rangeAxis = plot.getRangeAxis();
        if (rangeAxis instanceof NumberAxis) {
            NumberAxis axis = (NumberAxis) rangeAxis;
            axis.setAutoRangeIncludesZero(false);
        }

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        double x = 1.5;
        double w = x * 2;
        renderer.setSeriesShape(0, new Ellipse2D.Double(-x, x, w, w));
        setShapeLinesVisibility(plot);
    }
    return chart;
}

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

public MMPGraph(XYSeries series) {
    super();/*  w  w w . j a va 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:ecosim.gui.SummaryPane.java

/**
 *  Private method to build the binning chart.
 *
 *  @return A ChartPanel containing the binning chart.
 *//*from  ww  w.ja  va  2  s  . co m*/
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: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 {/*from   w ww .j a v  a  2s.co m*/
                        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  www  .  j ava  2s  .  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;
}

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

private ChartPanel getPanel(ArrayList<ChanDataBuffer> dbufs, boolean compact) throws WebUtilException {
    ChartPanel ret = null;//w  w w  . j av a  2s.  com
    try {
        float tfsMax = 0;
        for (ChanDataBuffer buf : dbufs) {
            ChanInfo ci = buf.getChanInfo();
            float fs = ci.getRate();
            tfsMax = Math.max(fs, tfsMax);
        }
        setFsMax(tfsMax);
        String gtitle = getTitle(dbufs, compact);
        int nbuf = dbufs.size();
        XYSeries[] xys = new XYSeries[nbuf];
        XYSeriesCollection mtds = new XYSeriesCollection();

        int cnum = 0;
        compact = dbufs.size() > 2 ? false : compact;
        float bw = 1.f;
        for (ChanDataBuffer dbuf : dbufs) {
            String legend = getLegend(dbuf, compact);

            xys[cnum] = new XYSeries(legend);

            bw = calcSpectrum(xys[cnum], dbuf);

            mtds.addSeries(xys[cnum]);
        }

        DefaultXYDataset ds = new DefaultXYDataset();
        String yLabel = pwrScale.toString();
        DecimalFormat dform = new DecimalFormat("0.0###");
        String xLabel;
        xLabel = String.format("Frequency Hz - (bw: %1$s, #fft: %2$,d, s/fft: %3$.2f, ov: %4$.2f)",
                dform.format(bw), nfft, secperfft, overlap);

        Double minx, miny, maxx, maxy;
        Double[] rng = new Double[4];
        if (fmin <= 0) {
            fmin = bw;
        }
        float searchFmax = fmax;
        if (fmax <= 0 || fmax == Float.MAX_VALUE) {
            fmax = tfsMax / 2;
            searchFmax = tfsMax / 2 * 0.8f;
        }
        PluginSupport.getRangeLimits(mtds, rng, 2, fmin, searchFmax);
        minx = rng[0];
        miny = rng[1];
        maxx = rng[2];
        maxy = rng[3];

        findSmallest(mtds);
        int exp;
        if (maxy == 0. && miny == 0.) {
            miny = -1.;
            exp = 0;
            logYaxis = false;
        } else {
            miny = miny > 0 ? miny : smallestY;
            maxy = maxy > 0 ? maxy : miny * 10;
            exp = PluginSupport.scaleRange(mtds, miny, maxy);
            if (!logYaxis) {
                yLabel += " x 1e-" + Integer.toString(exp);
            }
        }
        JFreeChart chart = ChartFactory.createXYLineChart(gtitle, xLabel, yLabel, ds, PlotOrientation.VERTICAL,
                true, false, false);
        XYPlot 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));
            rangeAxis.setStandardTickUnits(LogAxis.createLogTickUnits(Locale.US));
            plot.setRangeAxis(rangeAxis);
            plot.setRangeGridlinesVisible(true);
            plot.setRangeGridlinePaint(Color.BLACK);
        }
        if (logXaxis) {
            LogAxis domainAxis = new LogAxis(xLabel);
            domainAxis.setBase(2);
            domainAxis.setMinorTickCount(9);
            domainAxis.setMinorTickMarksVisible(true);
            domainAxis.setSmallestValue(smallestX);
            domainAxis.setNumberFormatOverride(new LogAxisNumberFormat());
            //domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
            plot.setDomainAxis(domainAxis);
            plot.setDomainGridlinesVisible(true);
            plot.setDomainGridlinePaint(Color.BLACK);
        }
        ValueAxis domainAxis = plot.getDomainAxis();
        if (fmin > Float.MIN_VALUE) {
            domainAxis.setLowerBound(fmin);
        }
        if (fmax != Float.MAX_VALUE) {
            domainAxis.setUpperBound(fmax);
        }
        plot.setDomainAxis(domainAxis);
        plot.setDataset(0, mtds);
        plot.setDomainGridlinePaint(Color.DARK_GRAY);
        plot.setRangeGridlinePaint(Color.DARK_GRAY);

        // 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);
        }
        plot.setBackgroundPaint(Color.WHITE);
        if (compact) {
            chart.removeLegend();
        }
        ret = new ChartPanel(chart);
    } catch (Exception ex) {
        throw new WebUtilException("Creating spectrum plot" + ex.getLocalizedMessage());
    }
    return ret;

}