Example usage for org.jfree.data.xy XYSeriesCollection getXValue

List of usage examples for org.jfree.data.xy XYSeriesCollection getXValue

Introduction

In this page you can find the example usage for org.jfree.data.xy XYSeriesCollection getXValue.

Prototype

@Override
public double getXValue(int series, int item) 

Source Link

Document

Returns the x-value (as a double primitive) for an item within a series.

Usage

From source file:umontreal.iro.lecuyer.charts.EmpiricalChart.java

/**
 * Synchronizes <SPAN CLASS="MATH"><I>x</I></SPAN>-axis ticks to the <SPAN CLASS="MATH"><I>s</I></SPAN>-th series <SPAN CLASS="MATH"><I>x</I></SPAN>-values.
 * /*from   ww w .j av a 2  s  . c  o  m*/
 * @param s series used to define ticks.
 * 
 * 
 */
public void setTicksSynchro(int s) {
    XYSeriesCollection seriesCollection = (XYSeriesCollection) this.dataset.getSeriesCollection();
    double[] values = new double[seriesCollection.getItemCount(s)];

    for (int i = 0; i < seriesCollection.getItemCount(s); i++)
        values[i] = seriesCollection.getXValue(s, i);

    XAxis.setLabels(values);
}

From source file:userinterface.graph.PrismErrorRenderer.java

/**
 * Draws the visual representation for one data item.
 *
 * @param g2  the graphics output target.
 * @param state  the renderer state./*from   ww w.ja  va  2s.c o m*/
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index
 * @author Muhammad Omer Saeed.
 */

@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) {

    if (!drawError) {
        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);
        return;
    }

    switch (currentMethod) {

    case PrismErrorRenderer.ERRORBARS:

        if (pass == 0 && dataset instanceof XYSeriesCollection && getItemVisible(series, item)) {

            synchronized (dataset) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;

                PlotOrientation orientation = plot.getOrientation();
                // draw the error bar for the y-interval
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                double y0 = it.getYValue() + it.getError();
                double y1 = it.getYValue() - it.getError();
                double x = collection.getXValue(series, item);

                RectangleEdge edge = plot.getRangeAxisEdge();
                double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge);
                double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge);
                double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
                Line2D line;
                Line2D cap1;
                Line2D cap2;
                double adj = this.capLength / 2.0;
                if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(xx, yy0, xx, yy1);
                    cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0);
                    cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1);
                } else { // PlotOrientation.HORIZONTAL
                    line = new Line2D.Double(yy0, xx, yy1, xx);
                    cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj);
                    cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj);
                }

                g2.setPaint(getItemPaint(series, item));

                if (this.errorStroke != null) {
                    g2.setStroke(this.errorStroke);
                } else {
                    g2.setStroke(getItemStroke(series, item));
                }
                g2.draw(line);
                g2.draw(cap1);
                g2.draw(cap2);
            }

        }

        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);

        break;

    case PrismErrorRenderer.ERRORDEVIATION:

        synchronized (dataset) {
            // do nothing if item is not visible
            if (!getItemVisible(series, item)) {
                return;
            }

            // first pass draws the shading
            if (pass == 0) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                State drState = (State) state;

                double x = collection.getXValue(series, item);
                double yLow = it.getYValue() - it.getError();
                double yHigh = it.getYValue() + it.getError();

                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);

                PlotOrientation orientation = plot.getOrientation();
                if (orientation == PlotOrientation.HORIZONTAL) {
                    drState.lowerCoordinates.add(new double[] { yyLow, xx });
                    drState.upperCoordinates.add(new double[] { yyHigh, xx });
                } else if (orientation == PlotOrientation.VERTICAL) {
                    drState.lowerCoordinates.add(new double[] { xx, yyLow });
                    drState.upperCoordinates.add(new double[] { xx, yyHigh });
                }

                if (item == (dataset.getItemCount(series) - 1)) {
                    // last item in series, draw the lot...
                    // set up the alpha-transparency...
                    Composite originalComposite = g2.getComposite();
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) this.alpha));
                    g2.setPaint(getItemPaint(series, item));
                    GeneralPath area = new GeneralPath();
                    double[] coords = (double[]) drState.lowerCoordinates.get(0);
                    area.moveTo((float) coords[0], (float) coords[1]);
                    for (int i = 1; i < drState.lowerCoordinates.size(); i++) {
                        coords = (double[]) drState.lowerCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    int count = drState.upperCoordinates.size();
                    coords = (double[]) drState.upperCoordinates.get(count - 1);
                    area.lineTo((float) coords[0], (float) coords[1]);
                    for (int i = count - 2; i >= 0; i--) {
                        coords = (double[]) drState.upperCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    area.closePath();
                    g2.fill(area);
                    g2.setComposite(originalComposite);

                    drState.lowerCoordinates.clear();
                    drState.upperCoordinates.clear();
                }
            }
            if (isLinePass(pass)) {

                // the following code handles the line for the y-values...it's
                // all done by code in the super class
                if (item == 0) {
                    State s = (State) state;
                    s.seriesPath.reset();
                    s.setLastPointGood(false);
                }

                if (getItemLineVisible(series, item)) {
                    drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis,
                            dataArea);
                }
            }

            // second pass adds shapes where the items are ..
            else if (isItemPass(pass)) {

                // setup for collecting optional entity info...
                EntityCollection entities = null;
                if (info != null) {
                    entities = info.getOwner().getEntityCollection();
                }

                drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis,
                        crosshairState, entities);
            }

        }

        break;
    default:
        return;
    }
}