Example usage for org.jfree.chart.axis ValueAxis setAutoRange

List of usage examples for org.jfree.chart.axis ValueAxis setAutoRange

Introduction

In this page you can find the example usage for org.jfree.chart.axis ValueAxis setAutoRange.

Prototype

public void setAutoRange(boolean auto) 

Source Link

Document

Sets a flag that determines whether or not the axis range is automatically adjusted to fit the data, and notifies registered listeners that the axis has been modified.

Usage

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java

protected void configureChart(final JFreeChart chart) {
    super.configureChart(chart);

    final XYPlot plot = chart.getXYPlot();
    final XYItemRenderer renderer = plot.getRenderer();

    if (StringUtils.isEmpty(getTooltipFormula()) == false) {
        renderer.setBaseToolTipGenerator(new FormulaXYZTooltipGenerator(getRuntime(), getTooltipFormula()));
    }/*  ww w  . j  a  v  a2s . c  om*/
    if (StringUtils.isEmpty(getUrlFormula()) == false) {
        renderer.setURLGenerator(new FormulaXYZURLGenerator(getRuntime(), getUrlFormula()));
    }

    renderer.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
    renderer.setBaseItemLabelsVisible(Boolean.TRUE.equals(getItemsLabelVisible()));
    if (getItemLabelFont() != null) {
        renderer.setBaseItemLabelFont(getItemLabelFont());
    }

    plot.setOrientation(computePlotOrientation());

    // May be an axis that supports dates
    final ValueAxis domainAxis = plot.getDomainAxis();
    if (domainAxis instanceof NumberAxis) {
        final NumberAxis numberAxis = (NumberAxis) domainAxis;
        numberAxis.setAutoRangeIncludesZero(isDomainIncludesZero());
        numberAxis.setAutoRangeStickyZero(isDomainStickyZero());
        if (getDomainPeriodCount() > 0) {
            if (getDomainTickFormat() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(getDomainPeriodCount(), getDomainTickFormat()));
            } else if (getDomainTickFormatString() != null) {
                final FastDecimalFormat formatter = new FastDecimalFormat(getDomainTickFormatString(),
                        getResourceBundleFactory().getLocale());
                numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new FastNumberTickUnit(getDomainPeriodCount()));
            }
        } else {
            if (getDomainTickFormat() != null) {
                numberAxis.setNumberFormatOverride(getDomainTickFormat());
            } else if (getDomainTickFormatString() != null) {
                final DecimalFormat formatter = new DecimalFormat(getDomainTickFormatString(),
                        new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setNumberFormatOverride(formatter);
            }
        }
    } else if (domainAxis instanceof DateAxis) {
        final DateAxis numberAxis = (DateAxis) domainAxis;

        if (getDomainPeriodCount() > 0 && getDomainTimePeriod() != null) {
            if (getDomainTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getDomainTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()),
                        (int) getDomainPeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getDomainTimePeriod()),
                        (int) getDomainPeriodCount()));
            }
        }
    }

    if (domainAxis != null) {
        domainAxis.setLabel(getDomainTitle());
        if (getDomainTitleFont() != null) {
            domainAxis.setLabelFont(getDomainTitleFont());
        }
        domainAxis.setVerticalTickLabels(isDomainVerticalTickLabels());
        if (getDomainTickFont() != null) {
            domainAxis.setTickLabelFont(getDomainTickFont());
        }
        final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
        if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
            if (getDomainMinimum() != 0) {
                domainAxis.setLowerBound(getDomainMinimum());
            }
            if (getDomainMaximum() != 1) {
                domainAxis.setUpperBound(getDomainMaximum());
            }
            if (getDomainMinimum() == 0 && getDomainMaximum() == 0) {
                domainAxis.setLowerBound(0);
                domainAxis.setUpperBound(1);
                domainAxis.setAutoRange(true);
            }
        } else {
            domainAxis.setLowerBound(getDomainMinimum());
            domainAxis.setUpperBound(getDomainMaximum());
            domainAxis.setAutoRange(isDomainAxisAutoRange());
        }
    }

    final ValueAxis rangeAxis = plot.getRangeAxis();
    if (rangeAxis instanceof NumberAxis) {
        final NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero());
        numberAxis.setAutoRangeStickyZero(isRangeStickyZero());

        if (getRangePeriodCount() > 0) {
            if (getRangeTickFormat() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat()));
            } else if (getRangeTickFormatString() != null) {
                final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(),
                        getResourceBundleFactory().getLocale());
                numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount()));
            }
        } else {
            if (getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(getRangeTickFormat());
            } else if (getRangeTickFormatString() != null) {
                final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(),
                        new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setNumberFormatOverride(formatter);
                standardTickUnitsApplyFormat(numberAxis, formatter);
            }
        }
    } else if (rangeAxis instanceof DateAxis) {
        final DateAxis numberAxis = (DateAxis) rangeAxis;

        if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) {
            if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()),
                        (int) getRangePeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(
                        new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount()));
            }
        } else {
            if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setDateFormatOverride(formatter);
            }
        }
    }

    if (rangeAxis != null) {
        rangeAxis.setLabel(getRangeTitle());
        if (getRangeTitleFont() != null) {
            rangeAxis.setLabelFont(getRangeTitleFont());
        }
        if (getRangeTickFont() != null) {
            rangeAxis.setTickLabelFont(getRangeTickFont());
        }
        final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
        if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
            if (getRangeMinimum() != 0) {
                rangeAxis.setLowerBound(getRangeMinimum());
            }
            if (getRangeMaximum() != 1) {
                rangeAxis.setUpperBound(getRangeMaximum());
            }
            if (getRangeMinimum() == 0 && getRangeMaximum() == 0) {
                rangeAxis.setLowerBound(0);
                rangeAxis.setUpperBound(1);
                rangeAxis.setAutoRange(true);
            }
        } else {
            rangeAxis.setLowerBound(getRangeMinimum());
            rangeAxis.setUpperBound(getRangeMaximum());
            rangeAxis.setAutoRange(isRangeAxisAutoRange());
        }
    }

    final String[] colors = getSeriesColor();
    for (int i = 0; i < colors.length; i++) {
        renderer.setSeriesPaint(i, parseColorFromString(colors[i]));
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.CategoricalChartExpression.java

protected void configureRangeAxis(final CategoryPlot cpl, final Font labelFont) {
    final ValueAxis rangeAxis = cpl.getRangeAxis();
    if (rangeAxis instanceof NumberAxis) {
        final NumberAxis numberAxis = (NumberAxis) rangeAxis;
        numberAxis.setAutoRangeIncludesZero(isRangeIncludesZero());
        numberAxis.setAutoRangeStickyZero(isRangeStickyZero());

        if (getRangePeriodCount() > 0) {
            if (getRangeTickFormat() != null) {
                numberAxis.setTickUnit(new NumberTickUnit(getRangePeriodCount(), getRangeTickFormat()));
            } else if (getRangeTickFormatString() != null) {
                final FastDecimalFormat formatter = new FastDecimalFormat(getRangeTickFormatString(),
                        getResourceBundleFactory().getLocale());
                numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(new FastNumberTickUnit(getRangePeriodCount()));
            }/* ww  w . ja  v  a  2s . com*/
        } else {
            if (getRangeTickFormat() != null) {
                numberAxis.setNumberFormatOverride(getRangeTickFormat());
            } else if (getRangeTickFormatString() != null) {
                final DecimalFormat formatter = new DecimalFormat(getRangeTickFormatString(),
                        new DecimalFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setNumberFormatOverride(formatter);
                standardTickUnitsApplyFormat(numberAxis, formatter);
            }
        }
    } else if (rangeAxis instanceof DateAxis) {
        final DateAxis numberAxis = (DateAxis) rangeAxis;

        if (getRangePeriodCount() > 0 && getRangeTimePeriod() != null) {
            if (getRangeTickFormatString() != null) {
                final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                        new DateFormatSymbols(getResourceBundleFactory().getLocale()));
                numberAxis.setTickUnit(new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()),
                        (int) getRangePeriodCount(), formatter));
            } else {
                numberAxis.setTickUnit(
                        new DateTickUnit(getDateUnitAsInt(getRangeTimePeriod()), (int) getRangePeriodCount()));
            }
        } else if (getRangeTickFormatString() != null) {
            final SimpleDateFormat formatter = new SimpleDateFormat(getRangeTickFormatString(),
                    new DateFormatSymbols(getResourceBundleFactory().getLocale()));
            numberAxis.setDateFormatOverride(formatter);
        }

    }

    if (rangeAxis != null) {
        rangeAxis.setLabelFont(labelFont);
        rangeAxis.setTickLabelFont(labelFont);

        if (getRangeTitleFont() != null) {
            rangeAxis.setLabelFont(getRangeTitleFont());
        }
        if (getRangeTickFont() != null) {
            rangeAxis.setTickLabelFont(getRangeTickFont());
        }
        final int level = getRuntime().getProcessingContext().getCompatibilityLevel();
        if (ClassicEngineBoot.isEnforceCompatibilityFor(level, 3, 8)) {
            if (getRangeMinimum() != 0) {
                rangeAxis.setLowerBound(getRangeMinimum());
            }
            if (getRangeMaximum() != 1) {
                rangeAxis.setUpperBound(getRangeMaximum());
            }
            if (getRangeMinimum() == 0 && getRangeMaximum() == 0) {
                rangeAxis.setAutoRange(true);
            }
        } else {
            if (isAutoRange()) {
                rangeAxis.setAutoRange(isAutoRange());
            } else {
                double factor = getScaleFactor();
                if (factor > DEFAULT_SCALE_FACTOR) {
                    // PRD-5340 hack
                    // this method is invoked after all series were populated
                    // hence the axis already has the graph's max and min values;
                    double lower = rangeAxis.getLowerBound();
                    if (lower < 0) {
                        lower *= factor;
                    } else if (lower > 0) {
                        lower /= factor;
                    }

                    double upper = rangeAxis.getUpperBound();
                    if (upper > 0) {
                        upper *= factor;
                    } else if (upper < 0) {
                        upper /= factor;
                    }
                    rangeAxis.setRange(lower, upper);
                } else {
                    // the 'scaleFactor' property is left intact or has an incorrect value
                    rangeAxis.setUpperBound(getRangeMaximum());
                    rangeAxis.setLowerBound(getRangeMinimum());
                }
            }
        }
    }
}