Example usage for org.jfree.data.xy XYDataset getItemCount

List of usage examples for org.jfree.data.xy XYDataset getItemCount

Introduction

In this page you can find the example usage for org.jfree.data.xy XYDataset getItemCount.

Prototype

public int getItemCount(int series);

Source Link

Document

Returns the number of items in a series.

Usage

From source file:gov.llnl.lc.infiniband.opensm.plugin.gui.chart.AdvancedXY_PlotPanel.java

@Override
public void chartProgress(ChartProgressEvent event) {
    if (event.getType() != ChartProgressEvent.DRAWING_FINISHED) {
        return;/*from  w w  w.  ja  va  2s  .c  o  m*/
    }

    // update the table model

    if (this.chartPanel != null) {
        JFreeChart c = this.getChart();
        if (c != null) {
            XYPlot plot = (XYPlot) c.getPlot();

            int ndex = this.getCrossHairDomainIndex();

            // update the table from the value at the crosshair

            for (int pnum = 0; pnum < NumDataSets; pnum++) {
                XYDataset dataset = plot.getDataset(pnum);
                String seriesName = "Unknown";
                if ((dataset != null) && (dataset.getSeriesKey(0) != null)) {
                    int ds_size = dataset.getItemCount(0);
                    if (dataset.getSeriesKey(0) instanceof String)
                        seriesName = (String) dataset.getSeriesKey(0);

                    // the name
                    this.model.setValueAt(seriesName, pnum, 0);

                    // the deltas are one smaller than the counters, so make sure the
                    // crosshair index is valid
                    if (ndex < ds_size) {
                        // the time
                        this.model.setValueAt(dataset.getXValue(0, ndex), pnum, 1);

                        // the value
                        this.model.setValueAt(dataset.getYValue(0, ndex), pnum, 2);
                    }

                    // the units (key off the series name)
                    PortCounterAxisLabel label = PortCounterAxisLabel.getByName(seriesName);
                    if (label != null)
                        this.model.setValueAt(label.getUnits(), pnum, 3);
                    else
                        this.model.setValueAt(PortCounterAxisLabel.DELTA.getUnits(), pnum, 3);
                }
            }
        } else
            System.err.println("Its NULL, Jim!");
    }
}

From source file:io.github.mzmine.util.jfreechart.IntelligentItemLabelGenerator.java

/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)/*from w w  w .ja v a2  s  .  c  o m*/
 */
public String generateLabel(XYDataset currentDataset, int currentSeries, int currentItem) {

    XYPlot plot = chartNode.getChart().getXYPlot();

    // X and Y values of the current data point
    final double currentXValue = currentDataset.getXValue(currentSeries, currentItem);
    final double currentYValue = currentDataset.getYValue(currentSeries, currentItem);

    // Calculate X axis span of 1 screen pixel
    final double xLength = plot.getDomainAxis().getRange().getLength();
    final double pixelX = xLength / chartNode.getWidth();

    // Calculate the distance from the current point where labels might
    // overlap
    final double dangerZoneX = (reservedPixels / 2) * pixelX;

    // Range on X axis that we're going to check for higher data points. If
    // a higher data point is found, we don't place a label on this one.
    final Range<Double> dangerZoneRange = Range.closed(currentXValue - dangerZoneX,
            currentXValue + dangerZoneX);

    // Iterate through data sets
    for (int datasetIndex = 0; datasetIndex < plot.getDatasetCount(); datasetIndex++) {

        XYDataset dataset = plot.getDataset(datasetIndex);

        // Some data sets could have been removed
        if (dataset == null)
            continue;

        final int seriesCount = dataset.getSeriesCount();

        // Iterate through series
        for (int seriesIndex = 0; seriesIndex < seriesCount; seriesIndex++) {

            final int itemCount = dataset.getItemCount(seriesIndex);

            // Find the index of a data point that is closest to
            // currentXValue
            int closestValueIndex;
            if (dataset == currentDataset && seriesIndex == currentSeries) {
                closestValueIndex = currentItem;
            } else {
                closestValueIndex = findClosestXIndex(dataset, seriesIndex, currentXValue, 0, itemCount - 1);
            }

            // Search to the left of the closest data point
            for (int i = closestValueIndex; (i >= 0)
                    && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i--) {
                if (dataset.getYValue(seriesIndex, i) > currentYValue)
                    return null;

                // In the case there are equal values, only place the label
                // on the leftmost value
                if (dataset.getYValue(seriesIndex, i) == currentYValue
                        && (dataset.getXValue(seriesIndex, i) < currentXValue))
                    return null;

            }

            // Search to the right of the closest data point
            for (int i = closestValueIndex + 1; (i < itemCount)
                    && (dangerZoneRange.contains(dataset.getX(seriesIndex, i).doubleValue())); i++) {
                if (dataset.getYValue(seriesIndex, i) > currentYValue)
                    return null;
            }

        }

    }

    // If no higher data point was found, create the label
    String label = underlyingGenerator.generateLabel(currentDataset, currentSeries, currentItem);

    return label;

}

From source file:net.sf.mzmine.modules.visualization.spectra.renderers.SpectraItemLabelGenerator.java

/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)// w w w.  j  a  va  2 s  . c o  m
 */
public String generateLabel(XYDataset dataset, int series, int item) {

    // X and Y values of current data point
    double originalX = dataset.getX(series, item).doubleValue();
    double originalY = dataset.getY(series, item).doubleValue();

    // Calculate data size of 1 screen pixel
    double xLength = (double) plot.getXYPlot().getDomainAxis().getRange().getLength();
    double pixelX = xLength / plot.getWidth();

    // Size of data set
    int itemCount = dataset.getItemCount(series);

    // Search for data points higher than this one in the interval
    // from limitLeft to limitRight
    double limitLeft = originalX - ((POINTS_RESERVE_X / 2) * pixelX);
    double limitRight = originalX + ((POINTS_RESERVE_X / 2) * pixelX);

    // Iterate data points to the left and right
    for (int i = 1; (item - i > 0) || (item + i < itemCount); i++) {

        // If we get out of the limit we can stop searching
        if ((item - i > 0) && (dataset.getXValue(series, item - i) < limitLeft)
                && ((item + i >= itemCount) || (dataset.getXValue(series, item + i) > limitRight)))
            break;

        if ((item + i < itemCount) && (dataset.getXValue(series, item + i) > limitRight)
                && ((item - i <= 0) || (dataset.getXValue(series, item - i) < limitLeft)))
            break;

        // If we find higher data point, bail out
        if ((item - i > 0) && (originalY <= dataset.getYValue(series, item - i)))
            return null;

        if ((item + i < itemCount) && (originalY <= dataset.getYValue(series, item + i)))
            return null;

    }

    // Create label
    String label = null;
    if (dataset instanceof ScanDataSet) {
        label = ((ScanDataSet) dataset).getAnnotation(item);
    }
    if (label == null) {
        double mzValue = dataset.getXValue(series, item);
        label = mzFormat.format(mzValue);
    }

    return label;

}

From source file:net.sf.mzmine.modules.visualization.metamsecorrelate.visual.pseudospectra.PseudoSpectraItemLabelGenerator.java

/**
 * @see org.jfree.chart.labels.XYItemLabelGenerator#generateLabel(org.jfree.data.xy.XYDataset,
 *      int, int)/*w  w w  . java  2 s. co  m*/
 */
public String generateLabel(XYDataset dataset, int series, int item) {

    // X and Y values of current data point
    double originalX = dataset.getX(series, item).doubleValue();
    double originalY = dataset.getY(series, item).doubleValue();

    // Calculate data size of 1 screen pixel
    double xLength = (double) plot.getChart().getXYPlot().getDomainAxis().getRange().getLength();
    double pixelX = xLength / plot.getWidth();

    // Size of data set
    int itemCount = dataset.getItemCount(series);

    // Search for data points higher than this one in the interval
    // from limitLeft to limitRight
    double limitLeft = originalX - ((POINTS_RESERVE_X / 2) * pixelX);
    double limitRight = originalX + ((POINTS_RESERVE_X / 2) * pixelX);

    // Iterate data points to the left and right
    for (int i = 1; (item - i > 0) || (item + i < itemCount); i++) {

        // If we get out of the limit we can stop searching
        if ((item - i > 0) && (dataset.getXValue(series, item - i) < limitLeft)
                && ((item + i >= itemCount) || (dataset.getXValue(series, item + i) > limitRight)))
            break;

        if ((item + i < itemCount) && (dataset.getXValue(series, item + i) > limitRight)
                && ((item - i <= 0) || (dataset.getXValue(series, item - i) < limitLeft)))
            break;

        // If we find higher data point, bail out
        if ((item - i > 0) && (originalY <= dataset.getYValue(series, item - i)))
            return null;

        if ((item + i < itemCount) && (originalY <= dataset.getYValue(series, item + i)))
            return null;

    }

    // Create label
    String label = null;
    if (dataset instanceof PseudoSpectrumDataSet) {
        double mzValue = dataset.getXValue(series, item);
        label = mzFormat.format(mzValue);
        String ann = ((PseudoSpectrumDataSet) dataset).getAnnotation(item);
        if (ann != null)
            label = label + "\n" + ann;
        return label;
    }
    if (label == null) {
        double mzValue = dataset.getXValue(series, item);
        label = mzFormat.format(mzValue);
    }

    return label;

}

From source file:org.pentaho.plugin.jfreereport.reportcharts.FormulaXYZURLGenerator.java

/**
 * Generates a URL for a particular item within a series.
 *
 * @param dataset the dataset./* w  ww . j a va 2  s.  com*/
 * @param series  the series number (zero-based index).
 * @param item    the item number (zero-based index).
 * @return The generated URL.
 */
public String generateURL(final XYDataset dataset, final int series, final int item) {
    if (dataset instanceof XYZDataset) {
        return generateURL((XYZDataset) dataset, series, item);
    }
    try {
        final Object[] values = new Object[] { dataset.getX(series, item), dataset.getY(series, item), null,
                IntegerCache.getInteger(series), dataset.getSeriesKey(series),
                IntegerCache.getInteger(dataset.getSeriesCount()), IntegerCache.getInteger(item),
                IntegerCache.getInteger(dataset.getItemCount(series)) };
        formulaExpression.setRuntime(
                new WrapperExpressionRuntime(new StaticDataRow(ADDITIONAL_COLUMN_KEYS, values), runtime));
        final Object o = formulaExpression.getValue();
        if (o == null) {
            return null;
        }
        return String.valueOf(o);
    } finally {
        formulaExpression.setRuntime(null);
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.FormulaXYZTooltipGenerator.java

/**
 * Generates the tooltip text for the specified item.
 *
 * @param dataset the dataset (<code>null</code> not permitted).
 * @param series  the series index (zero-based).
 * @param item    the item index (zero-based).
 * @return The tooltip text (possibly <code>null</code>).
 *//*from w  w  w  . ja va 2  s.co m*/
public String generateToolTip(final XYDataset dataset, final int series, final int item) {
    if (dataset instanceof XYZDataset) {
        return generateToolTip((XYZDataset) dataset, series, item);
    }
    try {
        final Object[] values = new Object[] { dataset.getX(series, item), dataset.getY(series, item), null,
                IntegerCache.getInteger(series), dataset.getSeriesKey(series),
                IntegerCache.getInteger(dataset.getSeriesCount()), IntegerCache.getInteger(item),
                IntegerCache.getInteger(dataset.getItemCount(series)) };
        formulaExpression.setRuntime(
                new WrapperExpressionRuntime(new StaticDataRow(ADDITIONAL_COLUMN_KEYS, values), runtime));
        final Object o = formulaExpression.getValue();
        if (o == null) {
            return null;
        }
        return String.valueOf(o);
    } finally {
        formulaExpression.setRuntime(null);
    }
}

From source file:com.newatlanta.bluedragon.CustomXYAreaRenderer.java

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) {
    super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
            crosshairState, pass);//from   ww  w . j av a2 s  .c  o m

    // The complete area chart is drawn when drawItem() is called for the last
    // item
    // so we need to draw all of the item labels after the last item so they'll
    // be
    // visible if they overlap the area chart.
    int itemCount = dataset.getItemCount(series);
    if (getPlotArea() && item > 0 && item == (itemCount - 1)) {
        // this is the last item so draw the item labels
        PlotOrientation orientation = plot.getOrientation();

        for (int i = 0; i < itemCount; i++) {
            if (isItemLabelVisible(series, i)) {
                double xValue = dataset.getXValue(series, i);
                double yValue = dataset.getYValue(series, i);
                if (Double.isNaN(yValue)) {
                    yValue = 0.0;
                }
                double transXValue = domainAxis.valueToJava2D(xValue, dataArea, plot.getDomainAxisEdge());
                double transYValue = rangeAxis.valueToJava2D(yValue, dataArea, plot.getRangeAxisEdge());

                double xx = transXValue;
                double yy = transYValue;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    xx = transYValue;
                    yy = transXValue;
                }
                drawItemLabel(g2, orientation, dataset, series, i, xx, yy, (yValue < 0.0));
            }
        }
    }
}

From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java

private double binSearch(XYDataset dataset, int si, double x) {
    return binSearch(dataset, si, x, 0, dataset.getItemCount(si) - 1);
}

From source file:org.operamasks.faces.render.graph.XYCurveAndShapeRenderer.java

/**
 * Draws the item (first pass). This method draws the lines
 * connecting the items. Instead of drawing separate lines,
 * a GeneralPath is constructed and drawn at the end of
 * the series painting./*from  w w  w . j  a v  a  2  s. c  o  m*/
 *
 * @param g2  the graphics device.
 * @param state  the renderer state.
 * @param plot  the plot (can be used to obtain standard color information
 *              etc).
 * @param dataset  the dataset.
 * @param pass  the pass.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataArea  the area within which the data is being drawn.
 */
protected void drawPrimaryLineAsPath(XYItemRendererState state, Graphics2D g2, XYPlot plot, XYDataset dataset,
        int pass, int series, int item, ValueAxis domainAxis, ValueAxis rangeAxis, Rectangle2D dataArea) {

    if (item != 0) {
        return;
    }

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    PlotOrientation orientation = plot.getOrientation();

    int itemCount = dataset.getItemCount(series);
    double[][] points = new double[itemCount][2];
    int count = 0;

    for (int i = 0; i < itemCount; i++) {
        double x = dataset.getXValue(series, i);
        double y = dataset.getYValue(series, i);
        double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
        double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation);
        if (!Double.isNaN(transX) && !Double.isNaN(transY)) {
            points[count][0] = transX;
            points[count][1] = transY;
            count++;
        }
    }

    if (count < 2) {
        return;
    }

    // sort points according to x axis
    Arrays.sort(points, new Comparator<double[]>() {
        public int compare(double[] a, double[] b) {
            return a[0] > b[0] ? 1 : a[0] < b[0] ? -1 : 0;
        }
    });

    // draw curve
    CubicSplineFunction2D f = new CubicSplineFunction2D(points, count);
    GeneralPath path = new GeneralPath();

    double startX = points[0][0];
    double startY = points[0][1];
    double endX = points[count - 1][0];
    double endY = points[count - 1][1];
    double yz = rangeAxis.valueToJava2D(0.0, dataArea, yAxisLocation);

    if (orientation == PlotOrientation.HORIZONTAL) {
        if (drawArea) {
            path.moveTo((float) yz, (float) startX);
            path.lineTo((float) startY, (float) startX);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) f.getValue(x), (float) x);
            }
            path.lineTo((float) endY, (float) endX);
            path.lineTo((float) yz, (float) endX);
            path.closePath();
        } else {
            path.moveTo((float) startY, (float) startX);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) f.getValue(x), (float) x);
            }
            path.lineTo((float) endY, (float) endX);
        }
    } else {
        if (drawArea) {
            path.moveTo((float) startX, (float) yz);
            path.lineTo((float) startX, (float) startY);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) x, (float) f.getValue(x));
            }
            path.lineTo((float) endX, (float) endY);
            path.lineTo((float) endX, (float) yz);
            path.closePath();
        } else {
            path.moveTo((float) startX, (float) startY);
            for (double x = Math.floor(startX) + 1.0; x < endX; x += 1.0) {
                path.lineTo((float) x, (float) f.getValue(x));
            }
            path.lineTo((float) endX, (float) endY);
        }
    }

    Paint paint = getItemPaint(series, item);
    Stroke stroke = getItemStroke(series, item);

    if (drawArea) {
        g2.setPaint(paint);
        g2.fill(path);

        // create paint for outline
        if (paint instanceof Color) {
            paint = ((Color) paint).darker();
        } else if (paint instanceof GradientPaint) {
            paint = ((GradientPaint) paint).getColor1().darker();
        }
    }

    g2.setPaint(paint);
    g2.setStroke(stroke);
    g2.draw(path);
}

From source file:org.sunzoft.sunstock.StockMain.java

protected JFreeChart createChart() {
    // 2Chart[??]
    XYDataset dataset = initChartData();
    JFreeChart chart = ChartFactory.createTimeSeriesChart("", "", "", dataset);

    XYPlot xyplot = (XYPlot) chart.getPlot();

    //addIndexChart(xyplot);        

    ChartUtils.setAntiAlias(chart);// 
    ChartUtils.setTimeSeriesStyle(xyplot, false, true);
    ChartUtils.setLegendEmptyBorder(chart);

    // X??//w  w  w. j  a v a  2s .  c o m
    DateAxis domainAxis = (DateAxis) xyplot.getDomainAxis();
    domainAxis.setAutoTickUnitSelection(false);
    domainAxis.setTimeline(SegmentedTimeline.newMondayThroughFridayTimeline());

    DateTickUnit dateTickUnit;
    if (dataset.getItemCount(0) < 30)
        dateTickUnit = new DateTickUnit(DateTickUnitType.DAY, 5, new SimpleDateFormat("yyyy-MM-dd")); // ??
    else if (dataset.getItemCount(0) < 100)
        dateTickUnit = new DateTickUnit(DateTickUnitType.DAY, 10, new SimpleDateFormat("yyyy-MM-dd")); // ??
    else if (dataset.getItemCount(0) < 200)
        dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 1, new SimpleDateFormat("yyyy/MM")); // ??
    else if (dataset.getItemCount(0) < 500)
        dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 3, new SimpleDateFormat("yyyy/MM")); // ??
    else if (dataset.getItemCount(0) < 1000)
        dateTickUnit = new DateTickUnit(DateTickUnitType.MONTH, 6, new SimpleDateFormat("yyyy/MM")); // ??
    else
        dateTickUnit = new DateTickUnit(DateTickUnitType.YEAR, 1, new SimpleDateFormat("yyyy")); // ??
    // ??
    domainAxis.setTickUnit(dateTickUnit);
    return chart;
}