Example usage for org.jfree.data Range Range

List of usage examples for org.jfree.data Range Range

Introduction

In this page you can find the example usage for org.jfree.data Range Range.

Prototype

public Range(double lower, double upper) 

Source Link

Document

Creates a new range.

Usage

From source file:com.intel.stl.ui.common.view.ComponentFactory.java

public static JFreeChart createBulletChart(CategoryDataset dataset, double[] thresholds, Color[] colors) {
    if (thresholds.length != colors.length) {
        throw new IllegalArgumentException(
                "Inconsistant array sizes: thresholds=" + thresholds.length + " colors=" + colors.length);
    }/*www  . j  a v a 2 s  . c o m*/

    JFreeChart jfreechart = ChartFactory.createBarChart(null, null, null, dataset, PlotOrientation.HORIZONTAL,
            false, true, false);
    CategoryPlot categoryplot = jfreechart.getCategoryPlot();
    categoryplot.setBackgroundPaint(null);
    categoryplot.setOutlinePaint(null);

    categoryplot.getDomainAxis().setVisible(false);

    NumberAxis rangeAxis = (NumberAxis) categoryplot.getRangeAxis();
    rangeAxis.setVisible(false);
    rangeAxis.setRange(new Range(0, 1.0));

    double last = 0.0;
    for (int i = 0; i < thresholds.length; i++) {
        IntervalMarker marker = new IntervalMarker(last, thresholds[i], colors[i]);
        categoryplot.addRangeMarker(marker, Layer.BACKGROUND);
        last = thresholds[i];
    }

    BarRenderer renderer = (BarRenderer) categoryplot.getRenderer();
    renderer.setShadowVisible(false);
    renderer.setMaximumBarWidth(0.33);
    renderer.setSeriesPaint(0, UIConstants.INTEL_DARK_GRAY);

    return jfreechart;
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Iterates over the data items of the xy dataset to find
 * the range bounds.// www.  ja  v a2s .  co  m
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines, for an
 *          {@link IntervalXYDataset}, whether the y-interval or just the
 *          y-value is used to determine the overall range.
 *
 * @return The range (possibly <code>null</code>).
 *
 * @since 1.0.10
 */
public static Range iterateRangeBounds(XYDataset dataset, boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();

    // handle three cases by dataset type
    if (includeInterval && dataset instanceof IntervalXYDataset) {
        // handle special case of IntervalXYDataset
        IntervalXYDataset ixyd = (IntervalXYDataset) dataset;
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value = ixyd.getYValue(series, item);
                double lvalue = ixyd.getStartYValue(series, item);
                double uvalue = ixyd.getEndYValue(series, item);
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                    maximum = Math.max(maximum, value);
                }
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                    maximum = Math.max(maximum, lvalue);
                }
                if (!Double.isNaN(uvalue)) {
                    minimum = Math.min(minimum, uvalue);
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    } else if (includeInterval && dataset instanceof OHLCDataset) {
        // handle special case of OHLCDataset
        OHLCDataset ohlc = (OHLCDataset) dataset;
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double lvalue = ohlc.getLowValue(series, item);
                double uvalue = ohlc.getHighValue(series, item);
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                }
                if (!Double.isNaN(uvalue)) {
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    } else {
        // standard case - plain XYDataset
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value = dataset.getYValue(series, item);
                if (!Double.isNaN(value)) {
                    minimum = Math.min(minimum, value);
                    maximum = Math.max(maximum, value);
                }
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Iterates over the data items of the xyz dataset to find
 * the z-dimension bounds.// w  w  w  . j  a  v  a 2s .com
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  include the z-interval (if the dataset has a
 *     z-interval.
 *
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateZBounds(XYZDataset dataset, boolean includeInterval) {
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();

    for (int series = 0; series < seriesCount; series++) {
        int itemCount = dataset.getItemCount(series);
        for (int item = 0; item < itemCount; item++) {
            double value = dataset.getZValue(series, item);
            if (!Double.isNaN(value)) {
                minimum = Math.min(minimum, value);
                maximum = Math.max(maximum, value);
            }
        }
    }

    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:ro.nextreports.engine.chart.JFreeChartExporter.java

private void setAxisRange(ValueAxis rangeAxis, Number min, Number max) {
    if (rangeAxis == null) {
        return;/*from ww  w  . j  av  a  2s . co  m*/
    }

    YRange yRange = new YRange(min, max);
    yRange = yRange.update();
    rangeAxis.setRange(new Range(yRange.getMin().doubleValue(), yRange.getMax().doubleValue()));
}

From source file:gda.plots.SimplePlot.java

/**
 * @param minVal/*from   ww  w.java 2 s.  com*/
 */
public void setXRangeMin(double minVal) {
    double maxval = linearXAxis.getRange().getUpperBound();
    linearXAxis.setRange(new Range(minVal, maxval));
    logarithmicXAxis.setRange(new Range(minVal, maxval));
}

From source file:org.jfree.data.general.DatasetUtils.java

/**
 * Returns the range of x-values in the specified dataset for the
 * data items belonging to the visible series.
 * //from  w w w.  j  a  va 2 s .c om
 * @param dataset  the dataset ({@code null} not permitted).
 * @param visibleSeriesKeys  the visible series keys ({@code null} not
 *     permitted).
 * @param includeInterval  a flag that determines whether or not the
 *     y-interval for the dataset is included (this only applies if the
 *     dataset is an instance of IntervalXYDataset).
 * 
 * @return The x-range (possibly {@code null}).
 * 
 * @since 1.0.13
 */
public static Range iterateToFindDomainBounds(XYDataset dataset, List visibleSeriesKeys,
        boolean includeInterval) {
    Args.nullNotPermitted(dataset, "dataset");
    Args.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");

    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;

    if (includeInterval && dataset instanceof IntervalXYDataset) {
        // handle special case of IntervalXYDataset
        IntervalXYDataset ixyd = (IntervalXYDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.indexOf(seriesKey);
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double xvalue = ixyd.getXValue(series, item);
                double lvalue = ixyd.getStartXValue(series, item);
                double uvalue = ixyd.getEndXValue(series, item);
                if (!Double.isNaN(xvalue)) {
                    minimum = Math.min(minimum, xvalue);
                    maximum = Math.max(maximum, xvalue);
                }
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                }
                if (!Double.isNaN(uvalue)) {
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    } else {
        // standard case - plain XYDataset
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.indexOf(seriesKey);
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double x = dataset.getXValue(series, item);
                if (!Double.isNaN(x)) {
                    minimum = Math.min(minimum, x);
                    maximum = Math.max(maximum, x);
                }
            }
        }
    }

    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}

From source file:gda.plots.SimplePlot.java

/**
 * @param maxVal/*  ww  w .ja v  a2  s  . c  om*/
 */
public void setXRangeMax(double maxVal) {
    double minval = linearXAxis.getRange().getLowerBound();
    linearXAxis.setRange(new Range(minval, maxVal));
    logarithmicXAxis.setRange(new Range(minval, maxVal));
}

From source file:gda.plots.SimplePlot.java

/**
 * @param minVal/*from   www . ja  v  a  2 s . com*/
 */
public void setYRangeMin(double minVal) {
    double maxval = linearYAxis.getRange().getUpperBound();
    linearYAxis.setRange(new Range(minVal, maxval));
    logarithmicYAxis.setRange(new Range(minVal, maxval));
    if (linearYAxisTwo != null) {
        linearYAxisTwo.setRange(new Range(minVal, maxval));
        logarithmicYAxisTwo.setRange(new Range(minVal, maxval));
    }
}

From source file:gda.plots.SimplePlot.java

/**
 * @param maxVal//  www .  ja v  a  2s .  co  m
 */
public void setYRangeMax(double maxVal) {
    double minval = linearYAxis.getRange().getLowerBound();
    linearYAxis.setRange(new Range(minval, maxVal));
    logarithmicYAxis.setRange(new Range(minval, maxVal));
    if (linearYAxisTwo != null) {
        linearYAxisTwo.setRange(new Range(minval, maxVal));
        logarithmicYAxisTwo.setRange(new Range(minval, maxVal));
    }
}

From source file:org.jfree.data.general.DatasetUtilities.java

/**
 * Returns the range of x-values in the specified dataset for the
 * data items belonging to the visible series.
 * //from   w  ww .jav a2s  .c  o m
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param visibleSeriesKeys  the visible series keys (<code>null</code> not
 *     permitted).
 * @param includeInterval  a flag that determines whether or not the
 *     y-interval for the dataset is included (this only applies if the
 *     dataset is an instance of IntervalXYDataset).
 * 
 * @return The x-range (possibly <code>null</code>).
 * 
 * @since 1.0.13
 */
public static Range iterateToFindDomainBounds(XYDataset dataset, List visibleSeriesKeys,
        boolean includeInterval) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");

    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;

    if (includeInterval && dataset instanceof IntervalXYDataset) {
        // handle special case of IntervalXYDataset
        IntervalXYDataset ixyd = (IntervalXYDataset) dataset;
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.indexOf(seriesKey);
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double lvalue = ixyd.getStartXValue(series, item);
                double uvalue = ixyd.getEndXValue(series, item);
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                }
                if (!Double.isNaN(uvalue)) {
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    } else {
        // standard case - plain XYDataset
        Iterator iterator = visibleSeriesKeys.iterator();
        while (iterator.hasNext()) {
            Comparable seriesKey = (Comparable) iterator.next();
            int series = dataset.indexOf(seriesKey);
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double x = dataset.getXValue(series, item);
                if (!Double.isNaN(x)) {
                    minimum = Math.min(minimum, x);
                    maximum = Math.max(maximum, x);
                }
            }
        }
    }

    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}