Search in sources :

Example 11 with IntervalXYDataset

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

the class YIntervalRenderer method drawItem.

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param dataArea  the area within which the plot is being drawn.
 * @param info  collects information about the drawing.
 * @param plot  the plot (can be used to obtain standard color
 *              information etc).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot
 *                        (<code>null</code> permitted).
 * @param pass  the pass index (ignored here).
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item, CrosshairState crosshairState, int pass) {
    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    IntervalXYDataset intervalDataset = (IntervalXYDataset) dataset;
    double x = intervalDataset.getXValue(series, item);
    double yLow = intervalDataset.getStartYValue(series, item);
    double yHigh = intervalDataset.getEndYValue(series, item);
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
    double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
    double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);
    Paint p = getItemPaint(series, item);
    Stroke s = getItemStroke(series, item);
    Line2D line = null;
    Shape shape = getItemShape(series, item);
    Shape top = null;
    Shape bottom = null;
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yyLow, xx, yyHigh, xx);
        top = ShapeUtilities.createTranslatedShape(shape, yyHigh, xx);
        bottom = ShapeUtilities.createTranslatedShape(shape, yyLow, xx);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(xx, yyLow, xx, yyHigh);
        top = ShapeUtilities.createTranslatedShape(shape, xx, yyHigh);
        bottom = ShapeUtilities.createTranslatedShape(shape, xx, yyLow);
    } else {
        throw new IllegalStateException();
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);
    g2.fill(top);
    g2.fill(bottom);
    // PLUS an additional item label near the lower y-value.
    if (isItemLabelVisible(series, item)) {
        drawItemLabel(g2, orientation, dataset, series, item, xx, yyHigh, false);
        drawAdditionalItemLabel(g2, orientation, dataset, series, item, xx, yyLow);
    }
    // add an entity for the item...
    if (entities != null) {
        addEntity(entities, line.getBounds(), dataset, series, item, 0.0, 0.0);
    }
}
Also used : Stroke(java.awt.Stroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) EntityCollection(org.jfree.chart.entity.EntityCollection) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 12 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project Openfire by igniterealtime.

the class GraphEngine method generateSparklineBarGraph.

/**
     * Generates a Sparkline Bar Graph.
     *
     * @param def the key of the statistic object.
     * @return the generated chart.
     */
public JFreeChart generateSparklineBarGraph(String key, String color, Statistic[] def, long startTime, long endTime, int dataPoints) {
    Color backgroundColor = getBackgroundColor();
    IntervalXYDataset dataset = (IntervalXYDataset) populateData(key, def, startTime, endTime, dataPoints);
    JFreeChart chart = ChartFactory.createXYBarChart(// chart title
    null, // domain axis label
    null, true, // range axis label
    null, // data
    dataset, PlotOrientation.VERTICAL, // include legend
    false, // tooltips?
    false, // URLs?
    false);
    chart.setBackgroundPaint(backgroundColor);
    chart.setBorderVisible(false);
    chart.setBorderPaint(null);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setDomainGridlinesVisible(false);
    plot.setDomainCrosshairVisible(false);
    plot.setRangeCrosshairVisible(false);
    plot.setBackgroundPaint(backgroundColor);
    plot.setRangeGridlinesVisible(false);
    GraphDefinition graphDef = GraphDefinition.getDefinition(color);
    Color plotColor = graphDef.getInlineColor(0);
    plot.getRenderer().setSeriesPaint(0, plotColor);
    plot.getRenderer().setBaseItemLabelsVisible(false);
    plot.getRenderer().setBaseOutlinePaint(backgroundColor);
    plot.setOutlineStroke(null);
    plot.setDomainGridlinePaint(null);
    ValueAxis xAxis = chart.getXYPlot().getDomainAxis();
    xAxis.setLabel(null);
    xAxis.setTickLabelsVisible(true);
    xAxis.setTickMarksVisible(true);
    xAxis.setAxisLineVisible(false);
    xAxis.setNegativeArrowVisible(false);
    xAxis.setPositiveArrowVisible(false);
    xAxis.setVisible(false);
    ValueAxis yAxis = chart.getXYPlot().getRangeAxis();
    yAxis.setTickLabelsVisible(false);
    yAxis.setTickMarksVisible(false);
    yAxis.setAxisLineVisible(false);
    yAxis.setNegativeArrowVisible(false);
    yAxis.setPositiveArrowVisible(false);
    yAxis.setVisible(false);
    return chart;
}
Also used : XYPlot(org.jfree.chart.plot.XYPlot) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) JFreeChart(org.jfree.chart.JFreeChart)

Example 13 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project adempiere by adempiere.

the class MChart method getXYDataset.

public IntervalXYDataset getXYDataset() {
    dataset = new TimeSeriesCollection();
    loadData();
    return (IntervalXYDataset) dataset;
}
Also used : TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset)

Example 14 with IntervalXYDataset

use of org.jfree.data.xy.IntervalXYDataset in project processdash by dtuma.

the class TimeLogPhaseWaterfallChart method createChart.

@Override
public JFreeChart createChart() {
    ProcessUtil process = new ProcessUtil(getDataContext());
    List<String> phases = getPhaseList(process);
    List timeLogEntries = getTimeLogEntries();
    GapSkipTracker gaps = createGapTracker();
    IntervalXYDataset dataset = createDataset(process, phases, timeLogEntries, gaps);
    return createChart(dataset, process, phases, gaps);
}
Also used : IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) ProcessUtil(net.sourceforge.processdash.process.ProcessUtil)

Example 15 with IntervalXYDataset

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

the class DatasetUtilities method iterateToFindDomainBounds.

/**
 * Returns the range of x-values in the specified dataset for the
 * data items belonging to the visible series.
 *
 * @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);
    }
}
Also used : IntervalXYDataset(org.jfree.data.xy.IntervalXYDataset) Iterator(java.util.Iterator) 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