Example usage for org.jfree.data.time TimeSeriesCollection getX

List of usage examples for org.jfree.data.time TimeSeriesCollection getX

Introduction

In this page you can find the example usage for org.jfree.data.time TimeSeriesCollection getX.

Prototype

@Override
public Number getX(int series, int item) 

Source Link

Document

Returns the x-value for the specified series and item.

Usage

From source file:org.openfaces.component.chart.impl.helpers.ChartInfoUtil.java

private static GridPointInfo getGridPointInfo(XYItemEntity en, Chart chart) {
    ChartModel model = chart.getModel();
    if (model == null)
        return null;

    GridPointInfo info = new GridPointInfoImpl();
    info.setSeries(new SeriesInfoImpl());
    info.getSeries().setIndex(en.getSeriesIndex());
    info.setIndex(en.getItem());/*from   w  ww .ja  v  a  2 s  .  c  o m*/
    ModelInfo modelInfo = new ModelInfo(model);
    if (!modelInfo.isDataEmpty()) {
        if (modelInfo.getModelType() == ModelType.Date) {
            TimeSeriesCollection ds = ModelConverter.toTimeSeriesCollection(chart, modelInfo);
            Comparable seriesKey = ds.getSeriesKey(en.getSeriesIndex());
            Number tupleKey = ds.getX(en.getSeriesIndex(), en.getItem());
            if (tupleKey instanceof Long) {
                info.setKey(new Date(tupleKey.longValue()));
            } else {
                info.setKey(tupleKey);
            }

            Object tupleValue = ds.getY(en.getSeriesIndex(), en.getItem());

            info.setValue(tupleValue);
            info.getSeries().setKey(seriesKey);
        } else {
            XYDataset ds = ModelConverter.toXYSeriesCollection(modelInfo);
            Comparable seriesKey = ds.getSeriesKey(en.getSeriesIndex());
            Number tupleKey = ds.getX(en.getSeriesIndex(), en.getItem());
            info.setKey(tupleKey);

            Object tupleValue = ds.getY(en.getSeriesIndex(), en.getItem());

            info.setValue(tupleValue);
            info.getSeries().setKey(seriesKey);
        }
    }

    return info;
}

From source file:com.android.ddmuilib.log.event.OccurrenceRenderer.java

@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) {
    TimeSeriesCollection timeDataSet = (TimeSeriesCollection) dataset;

    // get the x value for the series/item.
    double x = timeDataSet.getX(series, item).doubleValue();

    // get the min/max of the range axis
    double yMin = rangeAxis.getLowerBound();
    double yMax = rangeAxis.getUpperBound();

    RectangleEdge domainEdge = plot.getDomainAxisEdge();
    RectangleEdge rangeEdge = plot.getRangeAxisEdge();

    // convert the coordinates to java2d.
    double x2D = domainAxis.valueToJava2D(x, dataArea, domainEdge);
    double yMin2D = rangeAxis.valueToJava2D(yMin, dataArea, rangeEdge);
    double yMax2D = rangeAxis.valueToJava2D(yMax, dataArea, rangeEdge);

    // get the paint information for the series/item
    Paint p = getItemPaint(series, item);
    Stroke s = getItemStroke(series, item);

    Line2D line = null;//from  ww w .  j a  v  a  2s .c o  m
    PlotOrientation orientation = plot.getOrientation();
    if (orientation == PlotOrientation.HORIZONTAL) {
        line = new Line2D.Double(yMin2D, x2D, yMax2D, x2D);
    } else if (orientation == PlotOrientation.VERTICAL) {
        line = new Line2D.Double(x2D, yMin2D, x2D, yMax2D);
    }
    g2.setPaint(p);
    g2.setStroke(s);
    g2.draw(line);
}