Search in sources :

Example 1 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.

the class IntervalXYItemLabelGenerator method createItemArray.

/**
 * Creates the array of items that can be passed to the
 * {@link MessageFormat} class for creating labels.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param series  the series (zero-based index).
 * @param item  the item (zero-based index).
 *
 * @return An array of seven items from the dataset formatted as
 *         <code>String</code> objects (never <code>null</code>).
 */
@Override
protected Object[] createItemArray(XYDataset dataset, int series, int item) {
    IntervalXYDataset intervalDataset = null;
    if (dataset instanceof IntervalXYDataset) {
        intervalDataset = (IntervalXYDataset) dataset;
    }
    Object[] result = new Object[7];
    result[0] = dataset.getSeriesKey(series).toString();
    double x = dataset.getXValue(series, item);
    double xs = x;
    double xe = x;
    double y = dataset.getYValue(series, item);
    double ys = y;
    double ye = y;
    if (intervalDataset != null) {
        xs = intervalDataset.getStartXValue(series, item);
        xe = intervalDataset.getEndXValue(series, item);
        ys = intervalDataset.getStartYValue(series, item);
        ye = intervalDataset.getEndYValue(series, item);
    }
    DateFormat xdf = getXDateFormat();
    if (xdf != null) {
        result[1] = xdf.format(new Date((long) x));
        result[2] = xdf.format(new Date((long) xs));
        result[3] = xdf.format(new Date((long) xe));
    } else {
        NumberFormat xnf = getXFormat();
        result[1] = xnf.format(x);
        result[2] = xnf.format(xs);
        result[3] = xnf.format(xe);
    }
    NumberFormat ynf = getYFormat();
    DateFormat ydf = getYDateFormat();
    if (Double.isNaN(y) && dataset.getY(series, item) == null) {
        result[4] = getNullYString();
    } else {
        if (ydf != null) {
            result[4] = ydf.format(new Date((long) y));
        } else {
            result[4] = ynf.format(y);
        }
    }
    if (Double.isNaN(ys) && intervalDataset != null && intervalDataset.getStartY(series, item) == null) {
        result[5] = getNullYString();
    } else {
        if (ydf != null) {
            result[5] = ydf.format(new Date((long) ys));
        } else {
            result[5] = ynf.format(ys);
        }
    }
    if (Double.isNaN(ye) && intervalDataset != null && intervalDataset.getEndY(series, item) == null) {
        result[6] = getNullYString();
    } else {
        if (ydf != null) {
            result[6] = ydf.format(new Date((long) ye));
        } else {
            result[6] = ynf.format(ye);
        }
    }
    return result;
}
Also used : IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) DateFormat(java.text.DateFormat) Date(java.util.Date) NumberFormat(java.text.NumberFormat)

Example 2 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.

the class CombinedXYPlotDemo1 method createCombinedChart.

/**
 * Creates an overlaid chart.
 *
 * @return The chart.
 */
private static JFreeChart createCombinedChart() {
    // create plot ...
    IntervalXYDataset data1 = createDataset1();
    XYItemRenderer renderer1 = new XYLineAndShapeRenderer(true, false);
    renderer1.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    renderer1.setSeriesStroke(0, new BasicStroke(4.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL));
    renderer1.setSeriesPaint(0, Color.blue);
    DateAxis domainAxis = new DateAxis("Year");
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.02);
    ValueAxis rangeAxis = new NumberAxis("$billion");
    XYPlot plot1 = new XYPlot(data1, null, rangeAxis, renderer1);
    plot1.setBackgroundPaint(Color.lightGray);
    plot1.setDomainGridlinePaint(Color.white);
    plot1.setRangeGridlinePaint(Color.white);
    // add a second dataset and renderer...
    IntervalXYDataset data2 = createDataset2();
    XYBarRenderer renderer2 = new XYBarRenderer() {

        public Paint getItemPaint(int series, int item) {
            XYDataset dataset = getPlot().getDataset();
            if (dataset.getYValue(series, item) >= 0.0) {
                return Color.red;
            } else {
                return Color.green;
            }
        }
    };
    renderer2.setSeriesPaint(0, Color.red);
    renderer2.setDrawBarOutline(false);
    renderer2.setBaseToolTipGenerator(new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, new SimpleDateFormat("d-MMM-yyyy"), new DecimalFormat("0.00")));
    XYPlot plot2 = new XYPlot(data2, null, new NumberAxis("$billion"), renderer2);
    plot2.setBackgroundPaint(Color.lightGray);
    plot2.setDomainGridlinePaint(Color.white);
    plot2.setRangeGridlinePaint(Color.white);
    CombinedXYPlot cplot = new CombinedXYPlot(domainAxis, rangeAxis);
    cplot.add(plot1, 3);
    cplot.add(plot2, 2);
    cplot.setGap(8.0);
    cplot.setDomainGridlinePaint(Color.white);
    cplot.setDomainGridlinesVisible(true);
    // return a new chart containing the overlaid plot...
    JFreeChart chart = new JFreeChart("CombinedXYPlotDemo1", JFreeChart.DEFAULT_TITLE_FONT, cplot, false);
    chart.setBackgroundPaint(Color.white);
    LegendTitle legend = new LegendTitle(cplot);
    chart.addSubtitle(legend);
    return chart;
}
Also used : BasicStroke(java.awt.BasicStroke) DateAxis(org.jfree.chart.axis.DateAxis) NumberAxis(org.jfree.chart.axis.NumberAxis) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYLineAndShapeRenderer(org.jfree.chart.renderer.xy.XYLineAndShapeRenderer) DecimalFormat(java.text.DecimalFormat) CombinedXYPlot(org.jfree.experimental.chart.plot.CombinedXYPlot) LegendTitle(org.jfree.chart.title.LegendTitle) JFreeChart(org.jfree.chart.JFreeChart) StandardXYToolTipGenerator(org.jfree.chart.labels.StandardXYToolTipGenerator) XYPlot(org.jfree.chart.plot.XYPlot) CombinedXYPlot(org.jfree.experimental.chart.plot.CombinedXYPlot) ValueAxis(org.jfree.chart.axis.ValueAxis) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) XYDataset(org.jfree.data.xy.XYDataset) XYItemRenderer(org.jfree.chart.renderer.xy.XYItemRenderer) SimpleDateFormat(java.text.SimpleDateFormat) XYBarRenderer(org.jfree.chart.renderer.xy.XYBarRenderer)

Example 3 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.

the class DatasetUtilities method iterateToFindRangeBounds.

/**
 * Returns the range of y-values in the specified dataset for the
 * data items belonging to the visible series and with x-values in the
 * given range.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param visibleSeriesKeys  the visible series keys (<code>null</code> not
 *     permitted).
 * @param xRange  the x-range (<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 y-range (possibly <code>null</code>).
 *
 * @since 1.0.13
 */
public static Range iterateToFindRangeBounds(XYDataset dataset, List visibleSeriesKeys, Range xRange, boolean includeInterval) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    ParamChecks.nullNotPermitted(visibleSeriesKeys, "visibleSeriesKeys");
    ParamChecks.nullNotPermitted(xRange, "xRange");
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    // handle three cases by dataset type
    if (includeInterval && dataset instanceof OHLCDataset) {
        // handle special case of OHLCDataset
        OHLCDataset ohlc = (OHLCDataset) 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 x = ohlc.getXValue(series, item);
                if (xRange.contains(x)) {
                    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 if (includeInterval && dataset instanceof BoxAndWhiskerXYDataset) {
        // handle special case of BoxAndWhiskerXYDataset
        BoxAndWhiskerXYDataset bx = (BoxAndWhiskerXYDataset) 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 x = bx.getXValue(series, item);
                if (xRange.contains(x)) {
                    Number lvalue = bx.getMinRegularValue(series, item);
                    Number uvalue = bx.getMaxRegularValue(series, item);
                    if (lvalue != null) {
                        minimum = Math.min(minimum, lvalue.doubleValue());
                    }
                    if (uvalue != null) {
                        maximum = Math.max(maximum, uvalue.doubleValue());
                    }
                }
            }
        }
    } else 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 x = ixyd.getXValue(series, item);
                if (xRange.contains(x)) {
                    double lvalue = ixyd.getStartYValue(series, item);
                    double uvalue = ixyd.getEndYValue(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);
                double y = dataset.getYValue(series, item);
                if (xRange.contains(x)) {
                    if (!Double.isNaN(y)) {
                        minimum = Math.min(minimum, y);
                        maximum = Math.max(maximum, y);
                    }
                }
            }
        }
    }
    if (minimum == Double.POSITIVE_INFINITY) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}
Also used : OHLCDataset(org.jfree.data.xy.OHLCDataset) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Iterator(java.util.Iterator) Range(org.jfree.data.Range) BoxAndWhiskerXYDataset(org.jfree.data.statistics.BoxAndWhiskerXYDataset)

Example 4 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.

the class DatasetUtilities method iterateDomainBounds.

/**
 * Iterates over the items in an {@link XYDataset} to find
 * the range of x-values.
 *
 * @param dataset  the dataset (<code>null</code> not permitted).
 * @param includeInterval  a flag that determines, for an
 *          {@link IntervalXYDataset}, whether the x-interval or just the
 *          x-value is used to determine the overall range.
 *
 * @return The range (possibly <code>null</code>).
 */
public static Range iterateDomainBounds(XYDataset dataset, boolean includeInterval) {
    ParamChecks.nullNotPermitted(dataset, "dataset");
    double minimum = Double.POSITIVE_INFINITY;
    double maximum = Double.NEGATIVE_INFINITY;
    int seriesCount = dataset.getSeriesCount();
    double lvalue, uvalue;
    if (includeInterval && dataset instanceof IntervalXYDataset) {
        IntervalXYDataset intervalXYData = (IntervalXYDataset) dataset;
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                double value = intervalXYData.getXValue(series, item);
                lvalue = intervalXYData.getStartXValue(series, item);
                uvalue = intervalXYData.getEndXValue(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 {
        for (int series = 0; series < seriesCount; series++) {
            int itemCount = dataset.getItemCount(series);
            for (int item = 0; item < itemCount; item++) {
                lvalue = dataset.getXValue(series, item);
                uvalue = lvalue;
                if (!Double.isNaN(lvalue)) {
                    minimum = Math.min(minimum, lvalue);
                    maximum = Math.max(maximum, uvalue);
                }
            }
        }
    }
    if (minimum > maximum) {
        return null;
    } else {
        return new Range(minimum, maximum);
    }
}
Also used : IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Range(org.jfree.data.Range)

Example 5 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project SIMVA-SoS by SESoS.

the class DatasetUtilities method iterateRangeBounds.

/**
 * Iterates over the data items of the xy dataset to find
 * the range bounds.
 *
 * @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);
    }
}
Also used : OHLCDataset(org.jfree.data.xy.OHLCDataset) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Range(org.jfree.data.Range)

Aggregations

IntervalXYDataset (org.jfree.data.xy.IntervalXYDataset)22 PlotOrientation (org.jfree.chart.plot.PlotOrientation)7 RectangleEdge (org.jfree.ui.RectangleEdge)7 EntityCollection (org.jfree.chart.entity.EntityCollection)6 OHLCDataset (org.jfree.data.xy.OHLCDataset)5 Rectangle2D (java.awt.geom.Rectangle2D)4 Range (org.jfree.data.Range)4 Paint (java.awt.Paint)3 Line2D (java.awt.geom.Line2D)3 XYItemLabelGenerator (org.jfree.chart.labels.XYItemLabelGenerator)3 AlphaComposite (java.awt.AlphaComposite)2 Composite (java.awt.Composite)2 Stroke (java.awt.Stroke)2 Iterator (java.util.Iterator)2 JFreeChart (org.jfree.chart.JFreeChart)2 DateAxis (org.jfree.chart.axis.DateAxis)2 XYPlot (org.jfree.chart.plot.XYPlot)2 XYBarRenderer (org.jfree.chart.renderer.xy.XYBarRenderer)2 XYItemRenderer (org.jfree.chart.renderer.xy.XYItemRenderer)2 DomainInfo (org.jfree.data.DomainInfo)2