Example usage for org.jfree.chart.plot XYPlot getDataset

List of usage examples for org.jfree.chart.plot XYPlot getDataset

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getDataset.

Prototype

public XYDataset getDataset() 

Source Link

Document

Returns the primary dataset for the plot.

Usage

From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java

/**
 *
 *//*  ww w .j  av a2  s .  c  om*/
protected void configurePlot(Plot plot, JRChartPlot jrPlot) {
    super.configurePlot(plot, jrPlot);
    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
        CategoryDataset categoryDataset = categoryPlot.getDataset();
        if (categoryDataset != null) {
            for (int i = 0; i < categoryDataset.getRowCount(); i++) {
                categoryRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
            }
        }
        categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_134);
        categoryPlot.setRangeGridlineStroke(new BasicStroke(1f));
        categoryPlot.setDomainGridlinesVisible(false);

    } else if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        XYDataset xyDataset = xyPlot.getDataset();
        if (xyDataset != null) {
            XYItemRenderer xyItemRenderer = xyPlot.getRenderer();
            for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
                xyItemRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
            }
        }
        xyPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_134);
        xyPlot.setRangeGridlineStroke(new BasicStroke(1f));
        xyPlot.setDomainGridlinesVisible(false);

        xyPlot.setRangeZeroBaselineVisible(true);

    }
}

From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java

@Override
protected void configurePlot(Plot plot, JRChartPlot jrPlot) {
    super.configurePlot(plot, jrPlot);
    if (plot instanceof CategoryPlot) {
        CategoryPlot categoryPlot = (CategoryPlot) plot;
        CategoryItemRenderer categoryRenderer = categoryPlot.getRenderer();
        CategoryDataset categoryDataset = categoryPlot.getDataset();
        if (categoryDataset != null) {
            for (int i = 0; i < categoryDataset.getRowCount(); i++) {
                categoryRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
            }/*  www .  j a v a2  s .c om*/
        }
        categoryPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_134);
        categoryPlot.setRangeGridlineStroke(new BasicStroke(1f));
        categoryPlot.setDomainGridlinesVisible(false);

    } else if (plot instanceof XYPlot) {
        XYPlot xyPlot = (XYPlot) plot;
        XYDataset xyDataset = xyPlot.getDataset();
        if (xyDataset != null) {
            XYItemRenderer xyItemRenderer = xyPlot.getRenderer();
            for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
                xyItemRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
            }
        }
        xyPlot.setRangeGridlinePaint(ChartThemesConstants.GRAY_PAINT_134);
        xyPlot.setRangeGridlineStroke(new BasicStroke(1f));
        xyPlot.setDomainGridlinesVisible(false);

        xyPlot.setRangeZeroBaselineVisible(true);

    }
}

From source file:org.yccheok.jstock.gui.charting.InvestmentFlowLayerUI.java

private boolean updateInvestPoint(Point2D _investPoint) {
    if (_investPoint == null) {
        return false;
    }/*from   w  w w .ja va  2  s .  co  m*/

    final ChartPanel chartPanel = this.investmentFlowChartJDialog.getChartPanel();
    final JFreeChart chart = chartPanel.getChart();
    final XYPlot plot = (XYPlot) chart.getPlot();
    final TimeSeriesCollection timeSeriesCollection = (TimeSeriesCollection) plot.getDataset();
    final TimeSeries timeSeries = timeSeriesCollection.getSeries(0);

    // I also not sure why. This is what are being done in Mouse Listener Demo 4.
    //
    // Don't use it. It will cause us to lose precision.
    //final Point2D p2 = chartPanel.translateScreenToJava2D((Point)_investPoint);

    /* Try to get correct main chart area. */
    final Rectangle2D _plotArea = chartPanel.getChartRenderingInfo().getPlotInfo().getDataArea();

    /* Believe it? When there is another thread keep updateing time series data,
     * and keep calling setDirty, _plotArea can be 0 size sometimes. Ignore it.
     * Just assume we had processed it.
     */
    if (_plotArea.getWidth() == 0.0 && _plotArea.getHeight() == 0.0) {
        /* Cheat the caller. */
        return true;
    }

    final ValueAxis domainAxis = plot.getDomainAxis();
    final RectangleEdge domainAxisEdge = plot.getDomainAxisEdge();
    final ValueAxis rangeAxis = plot.getRangeAxis();
    final RectangleEdge rangeAxisEdge = plot.getRangeAxisEdge();
    final double coordinateX = domainAxis.java2DToValue(_investPoint.getX(), _plotArea, domainAxisEdge);

    int low = 0;
    int high = timeSeries.getItemCount() - 1;
    Date date = new Date((long) coordinateX);
    final long time = date.getTime();
    long bestDistance = Long.MAX_VALUE;
    int bestMid = 0;

    while (low <= high) {
        int mid = (low + high) >>> 1;

        final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(mid);
        final Day day = (Day) timeSeriesDataItem.getPeriod();
        final long search = day.getFirstMillisecond();
        final long cmp = search - time;

        if (cmp < 0) {
            low = mid + 1;
        } else if (cmp > 0) {
            high = mid - 1;
        } else {
            bestDistance = 0;
            bestMid = mid;
            break;
        }

        final long abs_cmp = Math.abs(cmp);
        if (abs_cmp < bestDistance) {
            bestDistance = abs_cmp;
            bestMid = mid;
        }
    }

    final TimeSeriesDataItem timeSeriesDataItem = timeSeries.getDataItem(bestMid);
    final double xValue = timeSeriesDataItem.getPeriod().getFirstMillisecond();
    final double yValue = timeSeriesDataItem.getValue().doubleValue();
    final double xJava2D = domainAxis.valueToJava2D(xValue, _plotArea, domainAxisEdge);
    final double yJava2D = rangeAxis.valueToJava2D(yValue, _plotArea, rangeAxisEdge);

    final int tmpIndex = bestMid;
    // Do not perform translation as this will cause precision losing.
    // We might experience unstable point. For example,
    //
    // this.investPoint is 700.9, there are 2 data points which are 700 and
    // 701.
    // During first updateInvestPoint(this.investPoint) call, data point 701
    // will be chosen, and this.investPoint has been truncated to 700.
    // During second updateInvestPoint(this.investPoint) call, data point 700
    // will be chosen. We may observe an unstable point swings between 700
    // and 701.
    //
    // translateJava2DToScreen will internally convert Point2D.Double to Point.
    //final Point2D tmpPoint = chartPanel.translateJava2DToScreen(new Point2D.Double(xJava2D, yJava2D));
    final Point2D tmpPoint = new Point2D.Double(xJava2D, yJava2D);
    this.drawArea.setRect(_plotArea);

    if (this.drawArea.contains(tmpPoint)) {
        this.investPointIndex = tmpIndex;
        this.investPoint = tmpPoint;
        return true;
    }
    return false;
}

From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java

/**
 *
 *//*from  w  w  w . j ava  2  s .  co  m*/
protected JFreeChart createCandlestickChart() throws JRException {
    JFreeChart jfreeChart = super.createCandlestickChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    CandlestickRenderer renderer = (CandlestickRenderer) xyPlot.getRenderer();
    DefaultHighLowDataset dataset = (DefaultHighLowDataset) xyPlot.getDataset();
    if (dataset != null) {
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesFillPaint(i, (Paint) ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(i));
            renderer.setSeriesPaint(i, Color.DARK_GRAY);
        }
    }
    return jfreeChart;
}

From source file:net.sf.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java

@Override
protected JFreeChart createCandlestickChart() throws JRException {
    JFreeChart jfreeChart = super.createCandlestickChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    CandlestickRenderer renderer = (CandlestickRenderer) xyPlot.getRenderer();
    DefaultHighLowDataset dataset = (DefaultHighLowDataset) xyPlot.getDataset();
    if (dataset != null) {
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesFillPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(i));
            renderer.setSeriesPaint(i, Color.DARK_GRAY);
        }//from ww  w  . j  a v  a 2  s .c  om
    }
    return jfreeChart;
}

From source file:net.bioclipse.model.ScatterPlotMouseHandler.java

@Override
public void mouseDragged(MouseEvent e) {
    super.mouseDragged(e);

    ChartPanel chartPanel = getChartPanel(e);
    JFreeChart selectedChart = chartPanel.getChart();
    ChartDescriptor cd = ChartUtils.getChartDescriptor(selectedChart);
    int[] indices = cd.getSourceIndices();

    XYPlot plot = (XYPlot) chartPanel.getChart().getPlot();

    //Create double buffer
    Image buffer = chartPanel.createImage(chartPanel.getWidth(), chartPanel.getHeight());
    Graphics bufferGraphics = buffer.getGraphics();
    chartPanel.paint(bufferGraphics);//from   w w w.j  a v  a  2 s. c  om

    if (lastX == 0 && lastY == 0) {
        lastX = e.getX();
        lastY = e.getY();
    }

    drawRect = new Rectangle();
    int x1 = Math.min(Math.min(e.getX(), lastX), startX);
    int y1 = Math.min(Math.min(e.getY(), lastY), startY);
    int x2 = Math.max(Math.max(e.getX(), lastX), startX);
    int y2 = Math.max(Math.max(e.getY(), lastY), startY);

    drawRect.x = x1;
    drawRect.y = y1;
    drawRect.width = x2 - drawRect.x;
    drawRect.height = y2 - drawRect.y;

    //Create a clipping rectangle
    Rectangle clipRect = new Rectangle(drawRect.x - 100, drawRect.y - 100, drawRect.width + 200,
            drawRect.height + 200);

    //Check for selected points
    for (int j = 0; j < plot.getDataset().getItemCount(plot.getDataset().getSeriesCount() - 1); j++) {
        for (int i = 0; i < plot.getDataset().getSeriesCount(); i++) {
            Number xK = plot.getDataset().getX(i, j);
            Number yK = plot.getDataset().getY(i, j);
            Point2D datasetPoint2D = new Point2D.Double(domainValueTo2D(chartPanel, plot, xK.doubleValue()),
                    rangeValueTo2D(chartPanel, plot, yK.doubleValue()));

            if (drawRect.contains(datasetPoint2D)) {
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                boolean pointAdded = mouseDragSelection.addPoint(cp);
                if (pointAdded) {
                    ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(j, i);
                    selectedChart.plotChanged(new PlotChangeEvent(plot));
                }
            } else if (!mouseDragSelection.isEmpty()) {
                PlotPointData cp = new PlotPointData(indices[j], cd.getXLabel(), cd.getYLabel());
                boolean pointRemoved = mouseDragSelection.removePoint(cp);
                if (pointRemoved) {
                    ((ScatterPlotRenderer) plot.getRenderer()).removeMarkedPoint(new Point(j, i));
                    selectedChart.plotChanged(new PlotChangeEvent(plot));
                }
            }
        }
    }

    Iterator<PlotPointData> iterator = currentSelection.iterator();
    while (iterator.hasNext()) {
        PlotPointData next = iterator.next();
        Point dataPoint = next.getDataPoint();
        ((ScatterPlotRenderer) plot.getRenderer()).addMarkedPoint(dataPoint);
    }

    lastX = e.getX();
    lastY = e.getY();

    Graphics graphics = chartPanel.getGraphics();
    graphics.setClip(clipRect);

    //Draw selection rectangle
    bufferGraphics.drawRect(drawRect.x, drawRect.y, drawRect.width, drawRect.height);

    graphics.drawImage(buffer, 0, 0, chartPanel.getWidth(), chartPanel.getHeight(), null);
}

From source file:cs.cirg.cida.CIDAView.java

@Action
public void changeSeriesName() {
    SeriesPair series = (SeriesPair) lineSeriesComboBox.getSelectedItem();
    JFreeChart chart = ((ChartPanel) chartPanel).getChart();
    XYPlot plot = (XYPlot) chart.getPlot();
    XYSeriesCollection xYSeriesCollection = (XYSeriesCollection) plot.getDataset();
    CIDAInputDialog dialog = new CIDAInputDialog(this.getFrame(), CIDAConstants.DIALOG_NEW_NAME_MSG,
            (String) xYSeriesCollection.getSeries(series.getValue()).getKey());
    dialog.displayPrompt();/*from  w ww. j ava 2  s.co m*/
    xYSeriesCollection.getSeries(series.getValue()).setKey(dialog.getInput());
    plot.notifyListeners(new PlotChangeEvent(plot));
    lineSeriesComboBox.removeItem(series);
    lineSeriesComboBox.addItem(new SeriesPair(series.getKey(), dialog.getInput()));
}

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

protected void createCurveSeries(JFreeChart chart, UIChart comp) {
    UIDataSeries data = comp.getDataSeries();
    if (data == null) {
        return;//from   ww w.  j  a  va2 s.  co  m
    }

    if (!(chart.getPlot() instanceof XYPlot)) {
        return;
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    XYDataset dataset = plot.getDataset();
    if (dataset.getSeriesCount() == 0) {
        return;
    }

    UIDataItem[] items = data.getItems();
    XYSeriesCollection collection = null;
    XYLineAndShapeRenderer renderer = null;

    int curSeries = 0;
    for (int i = 0; i < items.length; i++) {
        if (dataset.getItemCount(i) < 2) {
            continue;
        }

        for (UIComponent kid : items[i].getChildren()) {
            if (kid.isRendered() && (kid instanceof UICurve)) {
                UICurve curve = (UICurve) kid;
                XYSeries series = createCurveSeries(curve, dataset, i);

                if (collection == null) {
                    collection = new XYSeriesCollection();
                    renderer = new XYLineAndShapeRenderer(true, false);
                }
                collection.addSeries(series);

                String legend = curve.getLegend();
                if (legend == null || legend.length() == 0) {
                    renderer.setSeriesVisibleInLegend(curSeries, false);
                }

                Paint color = curve.getColor();
                if (color != null) {
                    renderer.setSeriesPaint(curSeries, color);
                }

                curSeries++;
            }
        }
    }

    if (collection != null) {
        plot.setDataset(1, collection);
        plot.setRenderer(1, renderer);
    }
}

From source file:com.zimbra.perf.chart.ChartUtil.java

private boolean hasData(JFreeChart chart) {
    if (chart == null) {
        return false;
    }/*from w ww . j a va 2s  .co  m*/
    XYPlot plot = chart.getXYPlot();
    XYDataset data = plot.getDataset();

    int numPoints = 0;
    for (int i = 0; i < data.getSeriesCount(); i++) {
        numPoints += data.getItemCount(i);
    }
    if (numPoints == 0) {
        return false;
    }
    return true;
}

From source file:net.sf.fspdfs.chartthemes.spring.EyeCandySixtiesChartTheme.java

/**
 *
 *///from w  w  w .  j  ava 2s.c  o  m
protected JFreeChart createBubbleChart() throws JRException {
    JFreeChart jfreeChart = super.createBubbleChart();

    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    XYBubbleRenderer bubbleRenderer = (XYBubbleRenderer) xyPlot.getRenderer();
    bubbleRenderer = new GradientXYBubbleRenderer(bubbleRenderer.getScaleType());
    xyPlot.setRenderer(bubbleRenderer);
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            bubbleRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
            bubbleRenderer.setSeriesPaint(i,
                    (Paint) ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
        }
    }
    return jfreeChart;
}