Example usage for org.jfree.chart.axis LogarithmicAxis setExpTickLabelsFlag

List of usage examples for org.jfree.chart.axis LogarithmicAxis setExpTickLabelsFlag

Introduction

In this page you can find the example usage for org.jfree.chart.axis LogarithmicAxis setExpTickLabelsFlag.

Prototype

public void setExpTickLabelsFlag(boolean flgVal) 

Source Link

Document

Sets the 'expTickLabelsFlag' flag.

Usage

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

private static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createScatterPlot("Logarithmic Axis Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    LogarithmicAxis logarithmicaxis = new LogarithmicAxis("X");
    logarithmicaxis.setExpTickLabelsFlag(true);
    logarithmicaxis.setStrictValuesFlag(false);
    LogarithmicAxis logarithmicaxis1 = new LogarithmicAxis("Y");
    logarithmicaxis1.setAllowNegativesFlag(true);
    logarithmicaxis1.setLog10TickLabelsFlag(true);
    xyplot.setDomainAxis(logarithmicaxis);
    xyplot.setRangeAxis(logarithmicaxis1);
    return jfreechart;
}

From source file:hudson.plugins.plot.Plot.java

/**
 * Generates the plot and stores it in the plot instance variable.
 *
 * @param forceGenerate/*from   ww  w.  j  a v  a 2 s  .co m*/
 *            if true, force the plot to be re-generated even if the on-disk
 *            data hasn't changed
 */
private void generatePlot(boolean forceGenerate) {
    class Label implements Comparable<Label> {
        final private Integer buildNum;
        final private String buildDate;
        final private String text;

        public Label(String buildNum, String buildTime, String text) {
            this.buildNum = Integer.parseInt(buildNum);
            synchronized (DATE_FORMAT) {
                this.buildDate = DATE_FORMAT.format(new Date(Long.parseLong(buildTime)));
            }
            this.text = text;
        }

        public Label(String buildNum, String buildTime) {
            this(buildNum, buildTime, null);
        }

        public int compareTo(Label that) {
            return this.buildNum - that.buildNum;
        }

        @Override
        public boolean equals(Object o) {
            return o instanceof Label && ((Label) o).buildNum.equals(buildNum);
        }

        @Override
        public int hashCode() {
            return buildNum.hashCode();
        }

        public String numDateString() {
            return "#" + buildNum + " (" + buildDate + ")";
        }

        @Override
        public String toString() {
            return text != null ? text : numDateString();
        }
    }
    // LOGGER.info("Determining if we should generate plot " +
    // getCsvFileName());
    File csvFile = new File(project.getRootDir(), getCsvFileName());
    if (csvFile.lastModified() == csvLastModification && plot != null && !forceGenerate) {
        // data hasn't changed so don't regenerate the plot
        return;
    }
    if (rawPlotData == null || csvFile.lastModified() > csvLastModification) {
        // data has changed or has not been loaded so load it now
        loadPlotData();
    }
    // LOGGER.info("Generating plot " + getCsvFileName());
    csvLastModification = csvFile.lastModified();
    PlotCategoryDataset dataset = new PlotCategoryDataset();
    for (String[] record : rawPlotData) {
        // record: series y-value, series label, build number, build date,
        // url
        int buildNum;
        try {
            buildNum = Integer.valueOf(record[2]);
            if (!reportBuild(buildNum) || buildNum > getRightBuildNum()) {
                continue; // skip this record
            }
        } catch (NumberFormatException nfe) {
            LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe);
            continue; // skip this record all together
        }
        Number value = null;
        try {
            value = Integer.valueOf(record[0]);
        } catch (NumberFormatException nfe) {
            try {
                value = Double.valueOf(record[0]);
            } catch (NumberFormatException nfe2) {
                LOGGER.log(Level.SEVERE, "Exception converting to number", nfe2);
                continue; // skip this record all together
            }
        }
        String series = record[1];
        Label xlabel = getUrlUseDescr() ? new Label(record[2], record[3], descriptionForBuild(buildNum))
                : new Label(record[2], record[3]);
        String url = null;
        if (record.length >= 5)
            url = record[4];
        dataset.setValue(value, url, series, xlabel);
    }

    String urlNumBuilds = getURLNumBuilds();
    int numBuilds;
    if (StringUtils.isBlank(urlNumBuilds)) {
        numBuilds = Integer.MAX_VALUE;
    } else {
        try {
            numBuilds = Integer.parseInt(urlNumBuilds);
        } catch (NumberFormatException nfe) {
            LOGGER.log(Level.SEVERE, "Exception converting to integer", nfe);
            numBuilds = Integer.MAX_VALUE;
        }
    }

    dataset.clipDataset(numBuilds);
    plot = createChart(dataset);
    CategoryPlot categoryPlot = (CategoryPlot) plot.getPlot();
    categoryPlot.setDomainGridlinePaint(Color.black);
    categoryPlot.setRangeGridlinePaint(Color.black);
    categoryPlot.setDrawingSupplier(Plot.supplier);
    CategoryAxis domainAxis = new ShiftedCategoryAxis(Messages.Plot_Build());
    categoryPlot.setDomainAxis(domainAxis);
    domainAxis.setCategoryLabelPositions(CategoryLabelPositions.UP_90);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.03);
    domainAxis.setCategoryMargin(0.0);
    for (Object category : dataset.getColumnKeys()) {
        Label label = (Label) category;
        if (label.text != null) {
            domainAxis.addCategoryLabelToolTip(label, label.numDateString());
        } else {
            domainAxis.addCategoryLabelToolTip(label, descriptionForBuild(label.buildNum));
        }
    }
    // Replace the range axis by a logarithmic axis if the option is
    // selected
    if (isLogarithmic()) {
        LogarithmicAxis logAxis = new LogarithmicAxis(getYaxis());
        logAxis.setExpTickLabelsFlag(true);
        categoryPlot.setRangeAxis(logAxis);
    }

    // optionally exclude zero as default y-axis value
    ValueAxis rangeAxis = categoryPlot.getRangeAxis();
    if ((rangeAxis != null) && (rangeAxis instanceof NumberAxis)) {
        if (hasYaxisMinimum()) {
            ((NumberAxis) rangeAxis).setLowerBound(getYaxisMinimum());
        }
        if (hasYaxisMaximum()) {
            ((NumberAxis) rangeAxis).setUpperBound(getYaxisMaximum());
        }
        ((NumberAxis) rangeAxis).setAutoRangeIncludesZero(!getExclZero());
    }

    AbstractCategoryItemRenderer renderer = (AbstractCategoryItemRenderer) categoryPlot.getRenderer();
    int numColors = dataset.getRowCount();
    for (int i = 0; i < numColors; i++) {
        renderer.setSeriesPaint(i, new Color(Color.HSBtoRGB((1f / numColors) * i, 1f, 1f)));
    }
    renderer.setBaseStroke(new BasicStroke(2.0f));
    renderer.setBaseToolTipGenerator(new StandardCategoryToolTipGenerator(Messages.Plot_Build() + " {1}: {2}",
            NumberFormat.getInstance()));
    renderer.setBaseItemURLGenerator(new PointURLGenerator());
    if (renderer instanceof LineAndShapeRenderer) {
        String s = getUrlStyle();
        LineAndShapeRenderer lasRenderer = (LineAndShapeRenderer) renderer;
        if ("lineSimple".equalsIgnoreCase(s)) {
            lasRenderer.setShapesVisible(false); // TODO: deprecated, may be unnecessary
        } else {
            lasRenderer.setShapesVisible(true); // TODO: deprecated, may be unnecessary
        }
    }
}