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

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

Introduction

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

Prototype

public void setRange(Range range, boolean turnOffAutoRange, boolean notify) 

Source Link

Document

Sets the range for the axis and, if requested, sends a change event to all registered listeners.

Usage

From source file:sturesy.voting.gui.VotingEvaluationPanelUI.java

private JFreeChart createChart(final CategoryDataset dataset, String questiontext, Color background,
        boolean showAnswers, List<Integer> correctAnswers, boolean showPercent) {
    String valueAxisLabel = Localize.getString(showPercent ? "label.votes.percent" : "label.votes.absolute");

    final JFreeChart chart = ChartFactory.createBarChart(questiontext, Localize.getString("label.answers"),
            valueAxisLabel, dataset, PlotOrientation.VERTICAL, false, true, false);

    chart.setBackgroundPaint(background);

    final CategoryPlot plot = chart.getCategoryPlot();
    plot.setNoDataMessage("NO DATA!");

    final CategoryItemRenderer renderer = new AnswersBarRenderer(showAnswers, correctAnswers);

    renderer.setBaseItemLabelsVisible(true);
    renderer.setBaseItemLabelFont(renderer.getBaseItemLabelFont().deriveFont(16.0f));

    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.CENTER, TextAnchor.CENTER,
            TextAnchor.CENTER, 45.0);//from  www .j  a v  a 2s  . com

    renderer.setBasePositiveItemLabelPosition(p);

    plot.setRenderer(renderer);

    // change the margin at the top of the range axis...
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setLowerMargin(0.15);
    rangeAxis.setUpperMargin(0.15);
    double upperrange = rangeAxis.getRange().getUpperBound();

    if (showPercent) {
        renderer.setBaseItemLabelGenerator(new AppendPercentRenderer());
        rangeAxis.setRange(new Range(0, upperrange > 100 ? 100 : upperrange), false, false);
    } else {
        renderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    }

    plot.getDomainAxis().setMaximumCategoryLabelLines(5);
    return chart;

}

From source file:edu.wisc.ssec.mcidasv.control.McIDASVHistogramWrapper.java

/**
 * Modify the low and high values of the domain axis.
 *
 * @param lowVal Low value./*from   ww w  . ja  v  a 2s  .c  o  m*/
 * @param hiVal High value.
 * @param notify Whether or not listeners should be notified.
 *
 * @return {@code false} if {@link #plot} is {@code null}. {@code true}
 * otherwise.
 */
protected boolean modifyRange(double lowVal, double hiVal, boolean notify) {
    try {
        if (plot == null) {
            return false;
        }
        ValueAxis domainAxis = plot.getDomainAxis();
        org.jfree.data.Range newRange = new org.jfree.data.Range(lowVal, hiVal);
        domainAxis.setRange(newRange, domainAxis.isAutoRange(), notify);
        return true;
    } catch (Exception e) {
        return true;
    }
}

From source file:ucar.unidata.idv.control.McVHistogramWrapper.java

/**
 * Modify the low and high values of the domain axis.
 *
 * @param lowVal Low value./*from  w w  w.j  a va  2  s . c  om*/
 * @param hiVal High value.
 * @param notify Whether or not listeners should be notified.
 *
 * @return {@code false} if {@link #plot} is {@code null}. {@code true}
 * otherwise.
 */
public boolean modifyRange(double lowVal, double hiVal, boolean notify) {
    try {
        if (plot == null) {
            return false;
        }
        ValueAxis domainAxis = plot.getDomainAxis();
        org.jfree.data.Range newRange = new org.jfree.data.Range(lowVal, hiVal);
        domainAxis.setRange(newRange, domainAxis.isAutoRange(), notify);
        return true;
    } catch (Exception e) {
        return true;
    }
}

From source file:lucee.runtime.tag.Chart.java

private void setScale(JFreeChart chart) {
    Plot plot = chart.getPlot();/*from  ww  w  . ja  v a 2  s  .  co  m*/
    if (plot instanceof CategoryPlot) {
        CategoryPlot cp = (CategoryPlot) plot;
        ValueAxis rangeAxis = cp.getRangeAxis();
        Range r = rangeAxis.getRange();
        double lower = r.getLowerBound();
        double upper = r.getUpperBound();

        if (labelFormat == LabelFormatUtil.LABEL_FORMAT_DATE && rangeAxis.getRange().getLowerBound() == 0) {
            lower = smallest;
            upper = biggest;
            try {
                DateTime d = Caster.toDate(Caster.toDouble(lower), true, null, null);
                lower = DateAdd.call(pageContext, "yyyy", -1, d).castToDoubleValue(lower);
            } catch (PageException e) {
            }
        }
        if (!Double.isNaN(scalefrom))
            lower = scalefrom;
        if (!Double.isNaN(scaleto))
            upper = scaleto;
        rangeAxis.setRange(new Range(lower, upper), true, true);
    } else if (plot instanceof XYPlot) {
        XYPlot cp = (XYPlot) plot;
        ValueAxis rangeAxis = cp.getRangeAxis();
        Range r = rangeAxis.getRange();
        double lower = r.getLowerBound();
        double upper = r.getUpperBound();

        if (labelFormat == LabelFormatUtil.LABEL_FORMAT_DATE && rangeAxis.getRange().getLowerBound() == 0) {
            lower = smallest;
            upper = biggest;
            try {
                DateTime d = Caster.toDate(Caster.toDouble(lower), true, null, null);
                lower = DateAdd.call(pageContext, "yyyy", -1, d).castToDoubleValue(lower);
            } catch (PageException e) {
            }
        }
        if (!Double.isNaN(scalefrom))
            lower = scalefrom;
        if (!Double.isNaN(scaleto))
            upper = scaleto;
        rangeAxis.setRange(new Range(lower, upper), true, true);
    }
}