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

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

Introduction

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

Prototype

public void setRange(double lower, double upper) 

Source Link

Document

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

Usage

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.StackedBarChartRenderer.java

/**
 * // w  w w . j  a  va  2s .c om
 */
public void createChart() {

    CategoryDataset categorydataset = (CategoryDataset) this.datasetStrategy.getDataset();
    report = ChartFactory.createStackedBarChart(this.datasetStrategy.getTitle(),
            this.datasetStrategy.getYAxisLabel(), this.datasetStrategy.getXAxisLabel(), categorydataset,
            PlotOrientation.HORIZONTAL, true, true, false);
    // report.setBackgroundPaint( Color.lightGray );
    report.setAntiAlias(false);
    report.setPadding(new RectangleInsets(5.0d, 5.0d, 5.0d, 5.0d));
    CategoryPlot categoryplot = (CategoryPlot) report.getPlot();
    categoryplot.setBackgroundPaint(Color.white);
    categoryplot.setRangeGridlinePaint(Color.lightGray);
    NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();
    if (datasetStrategy instanceof CloverBarChartStrategy
            || datasetStrategy instanceof MultiCloverBarChartStrategy) {
        numberaxis.setRange(0.0D, StackedBarChartRenderer.NUMBER_AXIS_RANGE);
        numberaxis.setNumberFormatOverride(NumberFormat.getPercentInstance());
    } else {
        numberaxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    }
    numberaxis.setLowerMargin(0.0D);
    StackedBarRenderer stackedbarrenderer = (StackedBarRenderer) categoryplot.getRenderer();
    stackedbarrenderer.setDrawBarOutline(false);
    stackedbarrenderer.setBaseItemLabelsVisible(true);
    stackedbarrenderer.setBaseItemLabelGenerator(new StandardCategoryItemLabelGenerator());
    stackedbarrenderer.setBaseItemLabelFont(StackedBarRenderer.DEFAULT_VALUE_LABEL_FONT.deriveFont(Font.BOLD));
    int height = (categorydataset.getColumnCount() * ChartUtils.STANDARD_BARCHART_ENTRY_HEIGHT * 2)
            + ChartUtils.STANDARD_BARCHART_ADDITIONAL_HEIGHT + 10;
    if (height > ChartUtils.MINIMUM_HEIGHT) {
        super.setHeight(height);
    } else {
        super.setHeight(ChartUtils.MINIMUM_HEIGHT);
    }
    Paint[] paints = this.datasetStrategy.getPaintColor();

    for (int i = 0; i < categorydataset.getRowCount() && i < paints.length; i++) {
        stackedbarrenderer.setSeriesPaint(i, paints[i]);
    }

}

From source file:org.jfree.experimental.chart.swt.editor.SWTNumberAxisEditor.java

/**
 * Sets the properties of the specified axis to match 
 * the properties defined on this panel.
 *
 * @param axis  the axis./*w w  w. j  a va2 s  .  c  o m*/
 */
public void setAxisProperties(Axis axis) {
    super.setAxisProperties(axis);
    NumberAxis numberAxis = (NumberAxis) axis;
    numberAxis.setAutoRange(this.autoRange);
    if (!this.autoRange)
        numberAxis.setRange(this.minimumValue, this.maximumValue);
}

From source file:no.met.jtimeseries.netcdf.plot.SimplePlotProvider.java

/**
 * Get the list of all range axes to be used. This method will collate 
 * axes with the same units./*from w  w w.  j  a v  a2 s .c o  m*/
 * 
 * @param dataList  List to create axis from
 * @return An axis for plotting, with value elements
 */
private List<ValueAxis> getRangeAxis(List<NumberPhenomenon> dataList) {

    class AxisInfo {
        private final String unit;
        private double low = Double.MAX_VALUE;
        private double high = -Double.MAX_VALUE;

        public AxisInfo(String unit) {
            this.unit = unit;
        }

        public void add(NumberPhenomenon p) {
            if (p.getMinValue() < low)
                low = p.getMinValue();
            if (p.getMaxValue() > high)
                high = p.getMaxValue();
        }

        private double border() {
            if (unit.equals("%"))
                return 0;
            return (high - low) / 10.0;
        }

        public String getUnit() {
            return unit;
        }

        public NumberAxis getAxis() {
            NumberAxis rangeAxis = new NumberAxis(getUnit());
            rangeAxis.setRange(getLowValue(), getHighValue());
            return rangeAxis;
        }

        private double getLowValue() {
            if (unit.equals("%"))
                return 0;
            else if (low == 0)
                return 0;
            return low - border();
        }

        private double getHighValue() {
            if (unit.equals("%"))
                return 100;
            return high + border();
        }
    }

    Vector<AxisInfo> axisInfoList = new Vector<AxisInfo>();

    for (NumberPhenomenon p : dataList) {

        AxisInfo axisInfo = null;
        for (AxisInfo ai : axisInfoList)
            if (ai.getUnit().equals(p.getPhenomenonUnit())) {
                axisInfo = ai;
                break;
            }
        if (axisInfo == null) {
            axisInfo = new AxisInfo(p.getPhenomenonUnit());
            axisInfoList.add(axisInfo);
        }
        axisInfo.add(p);
    }

    Vector<ValueAxis> ret = new Vector<ValueAxis>();
    for (AxisInfo axisInfo : axisInfoList) {
        ret.add(axisInfo.getAxis());
    }

    return ret;
}

From source file:com.att.aro.ui.view.diagnostictab.CreateBarPlot.java

/**
 * Returns a XYPlot //  ww w  .ja  v a2s .  c  o  m
 * 
 * @return XYPlot.
 */
//createWakelockStatePlot color is yellow, other is gray, createAlarmPlot need to set numberAxis, create usereventplot
//createBurstPlot(),createRrcPlot() 
public XYPlot drawXYBarPlot(Color color, boolean setAxis) {
    // Create renderer
    XYBarRenderer barRenderer = new XYBarRenderer();
    barRenderer.setDrawBarOutline(false);
    barRenderer.setUseYInterval(true);
    barRenderer.setBasePaint(color);
    barRenderer.setAutoPopulateSeriesPaint(false);
    barRenderer.setShadowVisible(false);
    barRenderer.setGradientPaintTransformer(null);
    barRenderer.setBarPainter(new StandardXYBarPainter());
    NumberAxis axis = new NumberAxis();
    if (setAxis) {
        axis.setVisible(false);
        axis.setAutoRange(false);
        axis.setRange(0, 1);
    }
    // Create result plot
    XYPlot barPlot = new XYPlot(null, null, axis, barRenderer);
    barPlot.getRangeAxis().setVisible(false);
    return barPlot;
}

From source file:edu.scripps.fl.curves.plot.CurvePlot.java

public void setResponseRange(int min, int max) {
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setRange(min, max);
    plot.configureRangeAxes();/*from  w ww .j  av a2s  .  c o  m*/
}

From source file:org.jgrasstools.gears.utils.images.LineChartGenerator.java

/**
 * Creates the chart image and dumps it to file.
 * /*from w w w. java 2  s .  c o m*/
 * @param chartFile the file to which to write to.
 * @param autoRange flag to define if to auto define the range from the bounds.
 * @param withLegend flag to define the legend presence.
 * @param imageWidth the output image width (if -1 default is used).
 * @param imageHeight the output image height (if -1 default is used).
 * @throws IOException
 */
@SuppressWarnings("nls")
public void dumpChart(File chartFile, boolean autoRange, boolean withLegend, int imageWidth, int imageHeight)
        throws IOException {
    JFreeChart chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, collection,
            PlotOrientation.VERTICAL, withLegend, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    // plot.setDomainPannable(true);
    // plot.setRangePannable(true);

    // plot.setForegroundAlpha(0.85f);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (autoRange) {
        double delta = (max - min) * 0.1;
        yAxis.setRange(min - delta, max + delta);
        yAxis.setMinorTickCount(4);
        yAxis.setMinorTickMarksVisible(true);
    }
    // ValueAxis xAxis = plot.getDomainAxis();
    // xAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits(Locale.US));

    // XYItemRenderer renderer = plot.getRenderer();
    // renderer.setDrawBarOutline(false);
    // // flat bars look best...
    // renderer.setBarPainter(new StandardXYBarPainter());
    // renderer.setShadowVisible(false);

    if (!chartFile.getName().endsWith(".png")) {
        chartFile = FileUtilities.substituteExtention(chartFile, "png");
    }
    if (imageWidth == -1) {
        imageWidth = IMAGEWIDTH;
    }
    if (imageHeight == -1) {
        imageHeight = IMAGEHEIGHT;
    }
    BufferedImage bufferedImage = chart.createBufferedImage(imageWidth, imageHeight);
    ImageIO.write(bufferedImage, "png", chartFile);
}

From source file:beadAnalyzer.DrawPoints.java

protected JFreeChart createChart(final IntervalXYDataset dataset, final String title, final String units) {
    final JFreeChart chart = ChartFactory.createXYBarChart(title, "Pixel [" + units + "]", false, "Count",
            dataset, PlotOrientation.VERTICAL, false, // legend
            false, false);/*  w w  w . j  a  va 2  s.  c  o  m*/

    NumberAxis range = (NumberAxis) chart.getXYPlot().getDomainAxis();
    range.setRange(getMin(), getMax());

    XYPlot plot = chart.getXYPlot();
    XYBarRenderer renderer = (XYBarRenderer) plot.getRenderer();

    renderer.setSeriesPaint(0, Color.red);
    renderer.setDrawBarOutline(true);
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setBarPainter(new StandardXYBarPainter());

    return chart;
}

From source file:org.amanzi.awe.distribution.ui.widgets.DistributionChartWidget.java

public void updateChartType(final ChartType chartType) {
    final CategoryPlot plot = (CategoryPlot) distributionChart.getPlot();

    switch (chartType) {
    case LOGARITHMIC:
        final LogarithmicAxis logAxis = new LogarithmicAxis("Logarithmic");
        logAxis.setAllowNegativesFlag(true);
        plot.setRangeAxis(logAxis);/*from   www  .j av  a  2s .c  o m*/

        logAxis.setAutoRange(true);
        break;
    case COUNTS:
        final NumberAxis countAxis = new NumberAxis("Counts");
        countAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

        plot.setRangeAxis(countAxis);
        countAxis.setAutoRange(true);
        break;
    case PERCENTS:
        final NumberAxis percentageAxis = new NumberAxis("Percentage");
        percentageAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        percentageAxis.setRange(0, 100);

        plot.setRangeAxis(percentageAxis);
        break;
    }

    dataset.updateDelegate(chartType);

    update();
}

From source file:sim.app.sugarscape.Charts.java

JFreeChart createGiniChart() {
    JFreeChart chart3 = ChartFactory.createXYLineChart("Lorenz Curve", "Population Percentage",
            "Percentage of Total Wealth", new XYSeriesCollection(model.lorenz_curve), PlotOrientation.VERTICAL,
            true, true, false);//from  w  ww  .  j  av  a 2 s.  co  m
    XYPlot plot = chart3.getXYPlot();
    ValueAxis yAxis = plot.getRangeAxis();
    //xAxis.setFixedDimension(100);
    yAxis.setFixedDimension(1.0);
    //yAxis.setRange(0,1);
    ValueAxis xAxis = plot.getDomainAxis();
    xAxis.setFixedDimension(50);

    //StandardXYItemRenderer 
    XYItemRenderer renderer = plot.getRenderer();
    renderer.setSeriesPaint(0, Color.black);
    NumberAxis axis2 = new NumberAxis("Average Agent Vision");

    //axis2.setAutoRangeIncludesZero(false);
    axis2.setRange(0, 12);
    plot.setRangeAxis(1, axis2);
    plot.setRangeAxisLocation(1, AxisLocation.BOTTOM_OR_RIGHT);
    //XYSeriesCollection vision = new XYSeriesCollection(lorenz_agent_vision);
    //plot.setDataset(1, vision);
    return chart3;
}

From source file:SciTK.PlotXYStep.java

/** Initialization routine (common to both constructors) */
private void init(String x_label, String y_label, String window_title, double x_min, double x_max) {
    chart = ChartFactory.createXYStepChart("", x_label, y_label, data, PlotOrientation.VERTICAL, false, true,
            false);//from   www . j  a v  a2s . c  om

    chart.setBackgroundPaint(Color.white);
    XYPlot plot = chart.getXYPlot(); // the plot itself

    // Use a step renderer for this type of chart:
    XYStepRenderer renderer = new XYStepRenderer();
    renderer.setBaseStroke(new BasicStroke(2.0f));
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    renderer.setDefaultEntityRadius(6);
    renderer.setLegendItemLabelGenerator(new MultipleXYSeriesLabelGenerator());
    // need to tell the plot to use this renderer
    plot.setRenderer(renderer);

    // create new axis with range set by dataset max/min:
    NumberAxis domainAxis = new NumberAxis(x_label);
    domainAxis.setRange(x_min, x_max);
    plot.setDomainAxis(domainAxis);

    // for some reason default is white, change it to black:
    setGridlineColor(Color.BLACK);

    super.window_title = window_title;
    super.initUI();
}