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:scheduler.benchmarker.manager.CreateCombinedSplineChart.java

public ChartPanel createChartPanel() {
    XYDataset dataset = createDataset();
    NumberAxis numberaxis = new NumberAxis("EMAILS");
    numberaxis.setAutoRangeIncludesZero(true);
    numberaxis.setRange(0, dataset.getItemCount(1));
    numberaxis.setVisible(false);//from   w  w w.  j  a  va 2 s. c  o m
    NumberAxis numberaxis1 = new NumberAxis("TIME CONSUMED");
    numberaxis.setAutoRangeIncludesZero(false);
    XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
    XYPlot xyplot = new XYPlot(dataset, numberaxis, numberaxis1, xysplinerenderer);
    xyplot.setBackgroundPaint(Color.lightGray);
    xyplot.setDomainGridlinePaint(Color.white);
    xyplot.setRangeGridlinePaint(Color.white);
    xyplot.setFixedLegendItems(null);
    JFreeChart jfreechart = new JFreeChart(
            "PLAN VALUES FOR '" + sName[0] + "' AND '" + sName[1] + "' SCHEDULERS",
            new Font(Font.SANS_SERIF, Font.PLAIN, 11), xyplot, true);
    chartPanel = new ChartPanel(jfreechart, true);

    //Creating listener
    chartPanel.addChartMouseListener(new ChartMouseListener() {
        @Override
        public void chartMouseClicked(ChartMouseEvent e) {
            ChartEntity entity = e.getEntity();
            if (entity != null && (entity instanceof XYItemEntity)) {
                XYItemEntity item = (XYItemEntity) entity;

                String chartTitle = "COMPARISON OF '" + sName[0] + "' AND '" + sName[1]
                        + "' BEHAVIOUR FOR EMAIL '"
                        + dataSource.get(0).getPlanningResult().get(item.getItem()).getEmailName() + "'";
                createSubChart(new CreateCombinedCategoryPlot(
                        new PlanningResult[] { dataSource.get(0).getPlanningResult().get(item.getItem()),
                                dataSource.get(1).getPlanningResult().get(item.getItem()) },
                        pluginColor, chartTitle, new String[] { dataSource.get(0).getSchedulerUsed(),
                                dataSource.get(1).getSchedulerUsed() }).createChartPanel());
            }
        }

        @Override
        public void chartMouseMoved(ChartMouseEvent e) {
            //DO NOTHING
        }

    });
    return chartPanel;
}

From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.CompassRenderer.java

@Override
public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot,
        XYDataset dataset, int seriesIndex) {

    // compute the right color for the paint
    int length = GuiUtils.getAvailableColors().length;
    Color color = GuiUtils.getAvailableColors()[index % length];
    // get all the data points
    int numPoints = dataset.getItemCount(seriesIndex);
    // set STroke and Paint of the graphics
    g2.setStroke(new BasicStroke(1.5f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175));

    // iterate through the points of the dataset
    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i); // the angle at the center         
        double radius = dataset.getYValue(seriesIndex, i); // the frequency

        Point p0 = plot.translateToJava2D(0, 0, plot.getAxis(), dataArea);
        Point p1 = plot.translateToJava2D(theta, radius, plot.getAxis(), dataArea);

        Line2D line = new Line2D.Double(p0, p1);
        g2.draw(line);//from   w ww . j  a  v a 2 s. c o m
    }
}

From source file:be.ugent.maf.cellmissy.gui.view.renderer.jfreechart.AngularHistogramRenderer.java

@Override
public void drawSeries(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info, PolarPlot plot,
        XYDataset dataset, int seriesIndex) {

    // compute the right color for the paint
    int length = GuiUtils.getAvailableColors().length;
    Color color = GuiUtils.getAvailableColors()[index % length];
    // get all the data points
    int numPoints = dataset.getItemCount(seriesIndex);

    for (int i = 0; i < numPoints; i++) {
        double theta = dataset.getXValue(seriesIndex, i); // the angle at the center         
        double radius = dataset.getYValue(seriesIndex, i); // the frequency

        Point p0 = plot.translateToJava2D(0, 0, plot.getAxis(), dataArea);
        Point p1 = plot.translateToJava2D(theta - binSize, radius, plot.getAxis(), dataArea);
        Point p2 = plot.translateToJava2D(theta + binSize, radius, plot.getAxis(), dataArea);

        Polygon poly = new Polygon(new int[] { p0.x, p1.x, p2.x }, new int[] { p0.y, p1.y, p2.y }, 3);

        g2.setPaint(new Color(color.getRed(), color.getGreen(), color.getBlue(), 175));
        g2.fill(poly);//w w w  .j  av a2 s.c  om
    }
}

From source file:arduinouno.TimeChartGenerator.java

public Double[][] getPlotInfo() {

    //Get the length to plot from dummy signal "offset"
    XYDataset theDataset;
    theDataset = plot.getDataset(0);/*from w  w  w .  j a  va2s .  c om*/

    int dataLenght = theDataset.getItemCount(0);
    int datasets = plot.getDatasetCount();

    Double[][] dataVector = new Double[dataLenght][datasets - 1];

    for (int j = 1; j < datasets; j++) {
        theDataset = plot.getDataset(j);
        int i = 0;
        while (i < dataLenght) {
            Double value = theDataset.getYValue(0, i);
            dataVector[i][j - 1] = value;
            i++;
        }
    }

    return dataVector;
}

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

/**
 * Sets the value of crossHairDomainIndex
 *
 * @param crossHairDomainIndex the crossHairDomainIndex to set
 *
 ***********************************************************/
protected void setCrossHairDomainIndex() {
    int value = this.slider.getValue();

    if (this.chartPanel != null) {
        JFreeChart c = this.getChart();
        this.getChart();
        if (c != null) {
            XYPlot plot = (XYPlot) c.getPlot();
            XYDataset dataset = plot.getDataset();
            int itemCount = dataset.getItemCount(0);
            double ndexD = (double) itemCount * ((double) value / 100);
            int ndex = (int) ndexD;

            // the index goes from 0 to (itemCount -1)
            this.CrossHairDomainIndex = ndex >= itemCount ? itemCount - 1 : ndex;
        }/*from  ww  w.  j av a2s  . c  o m*/
    }
}

From source file:org.esa.beam.pixex.output.ScatterPlotDecoratingStrategyTest.java

@Test
public void testCreateScatterPlotsForSingleProduct() throws Exception {
    Measurement[] productMeasurements = new Measurement[] {
            new Measurement(0, "someName", PRODUCT_ID_0, -1, -1, null, null, new Object[] { 7, 4.0 }, true),
            new Measurement(1, "someOtherName", PRODUCT_ID_0, -1, -1, null, null, new Object[] { 9, 3.0 },
                    true) };/*from w ww .j  ava2s  .c o  m*/

    assertTrue(strategy.plotMaps.isEmpty());

    final Product product = createProduct("newProduct");
    strategy.writeHeader(null, product);
    strategy.writeMeasurements(product, null, productMeasurements);

    assertEquals(1, strategy.plotMaps.size());
    final int scatterPlotCountForProduct = strategy.plotMaps.get(PRODUCT_ID_0).size();
    assertEquals(2, scatterPlotCountForProduct);

    JFreeChart sstPlot = strategy.plotMaps.get(PRODUCT_ID_0).get(variableCombinations[0]);
    assertEquals("original_sst", sstPlot.getXYPlot().getDomainAxis().getLabel());
    assertEquals("product_sst", sstPlot.getXYPlot().getRangeAxis().getLabel());
    assertEquals("Scatter plot of 'original_sst' and 'product_sst' for product 'newProduct'",
            sstPlot.getTitle().getText());

    XYDataset sstDataset = sstPlot.getXYPlot().getDataset();
    assertNotNull(sstDataset);
    assertEquals(1, sstDataset.getSeriesCount());

    int seriesIndex = 0;

    assertEquals(2, sstDataset.getItemCount(0));

    assertEquals(6, sstDataset.getX(seriesIndex, 0));
    assertEquals(7, sstDataset.getY(seriesIndex, 0));

    assertEquals(8, sstDataset.getX(seriesIndex, 1));
    assertEquals(9, sstDataset.getY(seriesIndex, 1));

    JFreeChart tsmPlot = strategy.plotMaps.get(PRODUCT_ID_0).get(variableCombinations[1]);
    assertEquals("original_tsm", tsmPlot.getXYPlot().getDomainAxis().getLabel());
    assertEquals("product_tsm", tsmPlot.getXYPlot().getRangeAxis().getLabel());
    assertEquals("Scatter plot of 'original_tsm' and 'product_tsm' for product 'newProduct'",
            tsmPlot.getTitle().getText());

    XYDataset tsmDataset = tsmPlot.getXYPlot().getDataset();
    assertNotNull(tsmDataset);
    assertEquals(1, tsmDataset.getSeriesCount());

    assertEquals(2, tsmDataset.getItemCount(0));

    assertEquals(2.0, tsmDataset.getX(seriesIndex, 0));
    assertEquals(3.0, tsmDataset.getY(seriesIndex, 0));

    assertEquals(3.0, tsmDataset.getX(seriesIndex, 1));
    assertEquals(4.0, tsmDataset.getY(seriesIndex, 1));
}

From source file:com.googlecode.logVisualizer.chart.LineChartBuilder.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.VERTICAL, isIncludeLegend(), true, false);
    final XYPlot plot = (XYPlot) chart.getPlot();

    double lastXValue = 0;
    if (dataset.getSeriesCount() > 0)
        lastXValue = dataset.getXValue(0, dataset.getItemCount(0) - 1);

    plot.setDomainAxis(new FixedZoomNumberAxis(lastXValue));
    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setNoDataMessage("No data available");
    if (dataset.getSeriesCount() > 0)
        ((NumberAxis) plot.getDomainAxis()).setUpperBound(lastXValue);
    ((NumberAxis) plot.getRangeAxis()).setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        renderer.setSeriesShapesVisible(i, false);
        renderer.setSeriesStroke(i, new BasicStroke(2));
    }/*from ww  w. j a  v a 2  s .  c  o m*/
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    plot.setRenderer(renderer);

    return chart;
}

From source file:org.talend.dataprofiler.chart.util.ToolTipChartComposite.java

/**
 * This method attempts to get a tooltip by converting the screen X,Y into Chart Area X,Y and then looking for a
 * data point in a data set that lies inside a hotspot around that value.
 * /*from  w w w  .  ja v a 2s. c  o m*/
 * @param point The Java 2D point
 * @return A string for the data at the point or null if no data is found.
 */
protected String getTooltipAtPoint(Point point) {
    String result = null;

    Point2D translatedPoint = this.translateScreenToJava2D(point);
    Plot plot = this.getChart().getPlot();
    PlotRenderingInfo info = this.getChartRenderingInfo().getPlotInfo();
    if (plot instanceof CombinedDomainXYPlot) {
        int index = info.getSubplotIndex(translatedPoint);
        if (index < 0) {
            index = 0;
        }
        plot = (Plot) ((CombinedDomainXYPlot) plot).getSubplots().get(index);
        info = this.getChartRenderingInfo().getPlotInfo().getSubplotInfo(index);
    }
    if (plot != null && plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        ValueAxis domainAxis = xyPlot.getDomainAxis();
        ValueAxis rangeAxis = xyPlot.getRangeAxis();
        // had to switch to SWT's rectangle here.
        Rectangle screenArea = this.scale(info.getDataArea());

        double hotspotSizeX = hotspontsize * this.getScaleX();
        double hotspotSizeY = hotspontsize * this.getScaleY();
        double x0 = point.getX();
        double y0 = point.getY();
        double x1 = x0 - hotspotSizeX;
        double y1 = y0 + hotspotSizeY;
        double x2 = x0 + hotspotSizeX;
        double y2 = y0 - hotspotSizeY;
        RectangleEdge xEdge = RectangleEdge.BOTTOM;
        RectangleEdge yEdge = RectangleEdge.LEFT;
        // Switch everything for horizontal charts
        if (xyPlot.getOrientation() == PlotOrientation.HORIZONTAL) {
            hotspotSizeX = hotspontsize * this.getScaleY();
            hotspotSizeY = hotspontsize * this.getScaleX();
            x0 = point.getY();
            y0 = point.getX();
            x1 = x0 + hotspotSizeX;
            y1 = y0 - hotspotSizeY;
            x2 = x0 - hotspotSizeX;
            y2 = y0 + hotspotSizeY;
            xEdge = RectangleEdge.LEFT;
            yEdge = RectangleEdge.BOTTOM;
        }

        // OK, here we have to get ourselves back into AWT land...
        Rectangle2D r2d = new Rectangle2D.Double();
        r2d.setRect(screenArea.x, screenArea.y, screenArea.width, screenArea.height);

        double ty0 = rangeAxis.java2DToValue(y0, r2d, yEdge);
        double tx1 = domainAxis.java2DToValue(x1, r2d, xEdge);
        double ty1 = rangeAxis.java2DToValue(y1, r2d, yEdge);
        double tx2 = domainAxis.java2DToValue(x2, r2d, xEdge);
        double ty2 = rangeAxis.java2DToValue(y2, r2d, yEdge);

        int datasetCount = xyPlot.getDatasetCount();
        for (int datasetIndex = 0; datasetIndex < datasetCount; datasetIndex++) {
            XYDataset dataset = xyPlot.getDataset(datasetIndex);
            int seriesCount = dataset.getSeriesCount();
            for (int series = 0; series < seriesCount; series++) {
                int itemCount = dataset.getItemCount(series);
                if (dataset instanceof OHLCDataset) {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValueHi = ((OHLCDataset) dataset).getHighValue(series, item);
                        double yValueLo = ((OHLCDataset) dataset).getLowValue(series, item);
                        // Check hi lo and swap if needed
                        if (yValueHi < yValueLo) {
                            double temp = yValueHi;
                            yValueHi = yValueLo;
                            yValueLo = temp;
                        }
                        // Check if the dataset 'X' value lies between the hotspot (tx1 < xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the cursor 'y' value lies between the high and low (low < ty0 < high)
                            if (yValueLo < ty0 && ty0 < yValueHi) {
                                return hiLoTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                } else {
                    // This could be optimized to use a binary search for x first
                    for (int item = 0; item < itemCount; item++) {
                        double xValue = dataset.getXValue(series, item);
                        double yValue = dataset.getYValue(series, item);
                        // Check if the dataset 'X' value lies between the hotspot (tx1< xValue < tx2)
                        if (tx1 < xValue && xValue < tx2) {
                            // Check if the dataset 'Y' value lies between the hotspot (ty1 < yValue < ty2)
                            if (ty1 < yValue && yValue < ty2) {
                                return xyTips.generateToolTip(dataset, series, item);
                            }
                        }
                    }
                }
            }
        }
    }

    return result;
}

From source file:net.sf.clichart.chart.AbstractChartBuilder.java

private double calculateBarWidth(XYDataset axisDataset, int lineWeight) {
    double minimumInterval = -1;
    for (int seriesIndex = 0; seriesIndex < axisDataset.getSeriesCount(); seriesIndex++) {
        for (int itemIndex = 1; itemIndex < axisDataset.getItemCount(seriesIndex); itemIndex++) {
            double interval = axisDataset.getXValue(seriesIndex, itemIndex)
                    - axisDataset.getXValue(seriesIndex, itemIndex - 1);
            if (itemIndex == 1) {
                minimumInterval = interval;
            } else {
                minimumInterval = Math.min(minimumInterval, interval);
            }/*ww  w .j  a va 2s. c  om*/
        }
    }

    double barWeight = 0.5;
    if (lineWeight >= 0 && lineWeight <= 5) {
        barWeight = 0.2 * lineWeight;
    }

    return minimumInterval * barWeight;
}

From source file:org.openfaces.component.chart.impl.plots.XYPlotAdapter.java

private void renderItems(Graphics2D g2, Rectangle2D dataArea, PlotRenderingInfo info,
        CrosshairState crosshairState, XYDataset xyDataset, ValueAxis xValueAxis, ValueAxis yValueAxis,
        XYItemRenderer xyItemRenderer, XYItemRendererState state, int totalRendererPasses, int seriesIndex) {
    for (int currentPassIndex = 0; currentPassIndex < totalRendererPasses; currentPassIndex++) {
        if (xyDataset.getItemCount(seriesIndex) == 0) {
            return;
        }//from ww w  .j  av  a  2s.c om

        int firstItemIndex = 0;
        int lastItemIndex = xyDataset.getItemCount(seriesIndex) - 1;

        if (state.getProcessVisibleItemsOnly()) {
            final double xLowerBound = xValueAxis.getLowerBound();
            final double xUpperBound = xValueAxis.getUpperBound();
            int[] itemBounds = RendererUtilities.findLiveItems(xyDataset, seriesIndex, xLowerBound,
                    xUpperBound);
            firstItemIndex = itemBounds[0] - 1;
            if (firstItemIndex < 0) {
                firstItemIndex = 0;
            }
            final int lastBoundaryIndex = itemBounds[1] + 1;
            if (lastBoundaryIndex < lastItemIndex) {
                lastItemIndex = lastBoundaryIndex;
            }
        }

        state.startSeriesPass(xyDataset, seriesIndex, firstItemIndex, lastItemIndex, currentPassIndex,
                totalRendererPasses);

        for (int item = firstItemIndex; item <= lastItemIndex; item++) {
            xyItemRenderer.drawItem(g2, state, dataArea, info, this, xValueAxis, yValueAxis, xyDataset,
                    seriesIndex, item, crosshairState, currentPassIndex);
        }

        state.endSeriesPass(xyDataset, seriesIndex, firstItemIndex, lastItemIndex, currentPassIndex,
                totalRendererPasses);
    }
}