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

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

Introduction

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

Prototype

public void setAutoRangeIncludesZero(boolean flag) 

Source Link

Document

Sets the flag that indicates whether or not the axis range, if automatically calculated, is forced to include zero.

Usage

From source file:org.utgenome.core.cui.DrawHistogram.java

public void execute() throws Exception {

    InputStream in = null;/*from   www  .  j a v  a2 s. com*/
    if ("-".equals(input)) {
        _logger.info("reading from STDIN");
        in = new StandardInputStream();
    } else {
        _logger.info("reading from " + input);
        in = new FileInputStream(input);
    }

    List<Double> data = new ArrayList<Double>();
    BufferedReader dataSetInput = new BufferedReader(new InputStreamReader(in));
    int lineCount = 1;
    try {
        // read data set
        boolean cutOffTail = !Double.isNaN(xMax);
        boolean cutOffHead = !Double.isNaN(xMin);
        for (String line; (line = dataSetInput.readLine()) != null; lineCount++) {

            if (lineCount % 100000 == 0)
                _logger.info(String.format("read %,d data points", lineCount));

            if (line.startsWith("#"))
                continue;
            double v = Double.parseDouble(line);
            if (cutOffTail && v > xMax)
                continue;
            if (cutOffHead && v < xMin)
                continue;

            data.add(v);
        }

        double[] value = new double[data.size()];
        for (int i = 0; i < data.size(); ++i) {
            value[i] = data.get(i);
        }

        // draw histogram
        HistogramDataset dataSet = new HistogramDataset();
        dataSet.setType(HistogramType.FREQUENCY);
        dataSet.addSeries("data", value, numBins);
        JFreeChart chart = ChartFactory.createHistogram(null, null, "Frequency", dataSet,
                PlotOrientation.VERTICAL, false, false, false);

        if (title != null) {
            chart.setTitle(title);
        }

        ValueAxis domainAxis = chart.getXYPlot().getDomainAxis();
        if (cutOffHead) {
            domainAxis.setLowerBound(xMin);
        }
        if (cutOffTail) {
            domainAxis.setUpperBound(xMax);
        }
        if (xLabel != null) {
            domainAxis.setLabel(xLabel);
        }

        if (yLog) {
            LogarithmicAxis logAxis = new LogarithmicAxis("Frequency");
            logAxis.setAllowNegativesFlag(true);
            logAxis.setAutoRangeIncludesZero(true);
            chart.getXYPlot().setRangeAxis(logAxis);
        }

        if (!Double.isNaN(yMin)) {
            chart.getXYPlot().getRangeAxis().setLowerBound(yMin);
        }
        if (!Double.isNaN(yMax)) {
            chart.getXYPlot().getRangeAxis().setUpperBound(yMax);
        }

        File outputFile = new File(output);
        _logger.info("output to " + outputFile);
        ChartUtilities.saveChartAsPNG(outputFile, chart, width, height);

    } catch (Exception e) {
        throw new Exception(String.format("error at line %d: %s", lineCount, e));
    }

}