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.jasperreports.chartthemes.spring.EyeCandySixtiesChartTheme.java

@Override
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);/*from  w  ww.java 2 s . co m*/
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            bubbleRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
            bubbleRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
        }
    }
    return jfreeChart;
}

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

/**
 *
 *//*from   w w w.j ava 2s  .c  o m*/
protected JFreeChart createXYBarChart() throws JRException {
    JFreeChart jfreeChart = super.createXYBarChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer();
    renderer.setMargin(0.1);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            renderer.setSeriesPaint(i, (Paint) ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
        }
    }
    return jfreeChart;
}

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

@Override
protected JFreeChart createXYBarChart() throws JRException {
    JFreeChart jfreeChart = super.createXYBarChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
    XYBarRenderer renderer = (XYBarRenderer) xyPlot.getRenderer();
    renderer.setMargin(0.1);/*from   w  w w. ja v a2 s  . co  m*/
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            renderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
        }
    }
    return jfreeChart;
}

From source file:net.sf.jasperreports.engine.fill.JRFillChart.java

/**
 * Build and configure a multiple axis chart.  A multiple axis chart support more than
 * one range axis.  Multiple datasets using different ranges can be displayed as long as
 * they share a common domain axis.  Each dataset can be rendered differently, so one chart
 * can contain (for example) two line charts, a bar chart and an area chart.
 * <br><br>/*from   www.j av  a  2  s  .  c  om*/
 * Multiple axis charts are handled differently than the other chart types.  They do not
 * have a dataset, as each chart that is added to the multiple axis chart has its own
 * dataset.  For simplicity, each dataset is treated as its own chart, and in fact we
 * reuse the design of all the chart types and let JFreeChart actually run them.  Then
 * we pull out the bits we need and add it to the common chart.  All the plot and chart
 * options on the nested charts is ignored, and all formatting is controlled by the plot
 * attached to the multiAxisChart.  The one exception is seriesColor, which can be used in
 * a nested report to specify a color for a specific series in that report.
 *
 * @param evaluation current expression evaluation phase
 * @throws JRException
 */
protected void createMultiAxisChart(byte evaluation) throws JRException {
    // A multi axis chart has to have at least one axis and chart specified.
    // Create the first axis as the base plot, and then go ahead and create the
    // charts for any additional axes.  Just take the renderer and data series
    // from those charts and add them to the first one.
    Plot mainPlot = null;

    JRFillMultiAxisPlot jrPlot = (JRFillMultiAxisPlot) getPlot();

    // create a multi axis hyperlink provider
    MultiAxisChartHyperlinkProvider multiHyperlinkProvider = new MultiAxisChartHyperlinkProvider();

    // Generate the main plot from the first axes specified.
    Iterator<JRChartAxis> iter = jrPlot.getAxes().iterator();
    if (iter.hasNext()) {
        JRFillChartAxis axis = (JRFillChartAxis) iter.next();
        JRFillChart fillChart = axis.getFillChart();

        //a JFreeChart object should be obtained first; the rendering type should be always "vector"

        jfreeChart = fillChart.evaluateChart(evaluation);
        //FIXME honor printWhenExpression
        // Override the plot from the first axis with the plot for the multi-axis
        // chart.
        //FIXME is the above comment true? 
        //configureChart(jfreeChart, getPlot(), evaluation);
        mainPlot = jfreeChart.getPlot();
        ChartHyperlinkProvider axisHyperlinkProvider = fillChart.getHyperlinkProvider();

        if (mainPlot instanceof CategoryPlot) {
            CategoryPlot categoryPlot = (CategoryPlot) mainPlot;
            categoryPlot.setRangeAxisLocation(0, getChartAxisLocation(axis));
            if (axisHyperlinkProvider != null) {
                multiHyperlinkProvider.addHyperlinkProvider(categoryPlot.getDataset(), axisHyperlinkProvider);
            }
        } else if (mainPlot instanceof XYPlot) {
            XYPlot xyPlot = (XYPlot) mainPlot;
            xyPlot.setRangeAxisLocation(0, getChartAxisLocation(axis));
            if (axisHyperlinkProvider != null) {
                multiHyperlinkProvider.addHyperlinkProvider(xyPlot.getDataset(), axisHyperlinkProvider);
            }
        }
    }

    // Now handle all the extra axes, if any.
    int axisNumber = 0;
    while (iter.hasNext()) {
        JRFillChartAxis chartAxis = (JRFillChartAxis) iter.next();
        JRFillChart fillChart = chartAxis.getFillChart();

        fillChart.evaluatePrintWhenExpression(evaluation);
        if (!(fillChart.isPrintWhenExpressionNull() || fillChart.isPrintWhenTrue())) {
            continue;
        }

        axisNumber++;
        JFreeChart axisChart = fillChart.evaluateChart(evaluation);
        ChartHyperlinkProvider axisHyperlinkProvider = fillChart.getHyperlinkProvider();

        // In JFreeChart to add a second chart type to an existing chart
        // you need to add an axis, a data series and a renderer.  To
        // leverage existing code we simply create a new chart for the
        // axis and then pull out the bits we need and add them to the multi
        // chart.  Currently JFree only supports category plots and xy plots
        // in a multi-axis chart, and you can not mix the two.
        if (mainPlot instanceof CategoryPlot) {
            CategoryPlot mainCatPlot = (CategoryPlot) mainPlot;
            if (!(axisChart.getPlot() instanceof CategoryPlot)) {
                throw new JRException(EXCEPTION_MESSAGE_KEY_MULTIAXIS_PLOT_TYPES_MIX_NOT_ALLOWED,
                        (Object[]) null);
            }

            // Get the axis and add it to the multi axis chart plot
            CategoryPlot axisPlot = (CategoryPlot) axisChart.getPlot();
            mainCatPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis());
            mainCatPlot.setRangeAxisLocation(axisNumber, getChartAxisLocation(chartAxis));

            // Add the data set and map it to the recently added axis
            mainCatPlot.setDataset(axisNumber, axisPlot.getDataset());
            mainCatPlot.mapDatasetToRangeAxis(axisNumber, axisNumber);

            // Set the renderer to use to draw the dataset.
            mainCatPlot.setRenderer(axisNumber, axisPlot.getRenderer());

            // Handle any color series for this chart
            configureAxisSeriesColors(axisPlot.getRenderer(), fillChart.getPlot());

            if (axisHyperlinkProvider != null) {
                multiHyperlinkProvider.addHyperlinkProvider(axisPlot.getDataset(), axisHyperlinkProvider);
            }
        } else if (mainPlot instanceof XYPlot) {
            XYPlot mainXyPlot = (XYPlot) mainPlot;
            if (!(axisChart.getPlot() instanceof XYPlot)) {
                throw new JRException(EXCEPTION_MESSAGE_KEY_MULTIAXIS_PLOT_TYPES_MIX_NOT_ALLOWED,
                        (Object[]) null);
            }

            // Get the axis and add it to the multi axis chart plot
            XYPlot axisPlot = (XYPlot) axisChart.getPlot();
            mainXyPlot.setRangeAxis(axisNumber, axisPlot.getRangeAxis());
            mainXyPlot.setRangeAxisLocation(axisNumber, getChartAxisLocation(chartAxis));

            // Add the data set and map it to the recently added axis
            mainXyPlot.setDataset(axisNumber, axisPlot.getDataset());
            mainXyPlot.mapDatasetToRangeAxis(axisNumber, axisNumber);

            // Set the renderer to use to draw the dataset.
            mainXyPlot.setRenderer(axisNumber, axisPlot.getRenderer());

            // Handle any color series for this chart
            configureAxisSeriesColors(axisPlot.getRenderer(), fillChart.getPlot());

            if (axisHyperlinkProvider != null) {
                multiHyperlinkProvider.addHyperlinkProvider(axisPlot.getDataset(), axisHyperlinkProvider);
            }
        } else {
            throw new JRException(EXCEPTION_MESSAGE_KEY_MULTIAXIS_PLOT_NOT_SUPPORTED, (Object[]) null);
        }
    }

    //set the multi hyperlink provider
    chartHyperlinkProvider = multiHyperlinkProvider;
}

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

protected JFreeChart createXyLineChart() throws JRException {
    JFreeChart jfreeChart = super.createXyLineChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();

    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) jfreeChart.getXYPlot().getRenderer();
    XYLine3DRenderer line3DRenderer = new XYLine3DRenderer();

    line3DRenderer.setBaseToolTipGenerator(lineRenderer.getBaseToolTipGenerator());
    line3DRenderer.setURLGenerator(lineRenderer.getURLGenerator());
    line3DRenderer.setBaseStroke(new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    line3DRenderer.setBaseLinesVisible(lineRenderer.getBaseLinesVisible());
    line3DRenderer.setBaseShapesVisible(lineRenderer.getBaseShapesVisible());
    Stroke stroke = new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            line3DRenderer.setSeriesStroke(i, stroke);
            line3DRenderer.setSeriesLinesVisible(i, lineRenderer.getBaseLinesVisible());
            line3DRenderer.setSeriesShapesVisible(i, lineRenderer.getBaseShapesVisible());
        }//from  w w w. j a v a2 s  . com
    }
    line3DRenderer.setXOffset(2);
    line3DRenderer.setYOffset(2);
    line3DRenderer.setWallPaint(ChartThemesConstants.GRAY_PAINT_134);

    xyPlot.setRenderer(line3DRenderer);
    return jfreeChart;
}

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

@Override
protected JFreeChart createXyLineChart() throws JRException {
    JFreeChart jfreeChart = super.createXyLineChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();

    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) jfreeChart.getXYPlot().getRenderer();
    XYLine3DRenderer line3DRenderer = new XYLine3DRenderer();

    line3DRenderer.setBaseToolTipGenerator(lineRenderer.getBaseToolTipGenerator());
    line3DRenderer.setURLGenerator(lineRenderer.getURLGenerator());
    line3DRenderer.setBaseStroke(new BasicStroke(2, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    line3DRenderer.setBaseLinesVisible(lineRenderer.getBaseLinesVisible());
    line3DRenderer.setBaseShapesVisible(lineRenderer.getBaseShapesVisible());
    Stroke stroke = new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            line3DRenderer.setSeriesStroke(i, stroke);
            line3DRenderer.setSeriesLinesVisible(i, lineRenderer.getBaseLinesVisible());
            line3DRenderer.setSeriesShapesVisible(i, lineRenderer.getBaseShapesVisible());
        }/* www  .  ja  v  a  2s  .  c om*/
    }
    line3DRenderer.setXOffset(2);
    line3DRenderer.setYOffset(2);
    line3DRenderer.setWallPaint(ChartThemesConstants.GRAY_PAINT_134);

    xyPlot.setRenderer(line3DRenderer);
    return jfreeChart;
}

From source file:CGgui.java

public void FindMin() {

    try {/*ww  w  . j  ava  2s.c  o m*/
        //get the data
        XYPlot xyplot = (XYPlot) chart.getPlot();
        XYDataset xydataset = xyplot.getDataset();

        //search through and find lowest minimum
        double MinXVal = -1;
        double MinYVal = -1;
        double lowbound = Double.parseDouble(minText.getText());
        double highbound = Double.parseDouble(maxText.getText());
        if (DEBUG)
            PrintText("Minimum of " + xydataset.getItemCount(0) + " datapoints\n");
        for (int i = 0; i < xydataset.getItemCount(0); i++) {
            double XVal = xydataset.getXValue(0, i);
            if ((XVal > lowbound) && (XVal < highbound)) {
                double YValCurr = xydataset.getYValue(0, i);
                if ((YValCurr < MinYVal) || (MinYVal == -1)) {
                    MinYVal = YValCurr;
                    MinXVal = xydataset.getXValue(0, i);
                }
            }
        }

        //print out, save, and mark off min
        if (DEBUG)
            PrintText("Minimum located at (" + MinXVal + "," + MinYVal + ")\n");

        addMinima(MinXVal);
        CurrMin = MinXVal;
        xyplot.setDomainCrosshairValue(MinXVal);

        cluster = new Cluster(fragmentMap, CurrCG, MinXVal);

        double AveLength = cluster.getAvgClusterLength();
        if (DEBUG)
            PrintText("Average Number of " + regex + "s in Cluster: " + AveLength + "\n");
        addClusterSize(AveLength);
    } catch (NumberFormatException err) {
        if (DEBUG)
            PrintText("Error: " + err + "\n");
    } catch (IndexOutOfBoundsException err) {
        if (DEBUG)
            PrintText("Error: " + err + "\n");
    }

}

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

@Override
protected JFreeChart createScatterChart() throws JRException {
    JFreeChart jfreeChart = super.createScatterChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();

    xyPlot.setRangeGridlinePaint(SCATTER_GRIDLINE_COLOR);
    xyPlot.setRangeGridlineStroke(new BasicStroke(0.75f));
    xyPlot.setDomainGridlinesVisible(true);
    xyPlot.setDomainGridlinePaint(SCATTER_GRIDLINE_COLOR);
    xyPlot.setDomainGridlineStroke(new BasicStroke(0.75f));
    xyPlot.setRangeZeroBaselinePaint(ChartThemesConstants.GRAY_PAINT_134);

    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
    lineRenderer.setUseFillPaint(true);// w  ww .ja v a2s . c  o  m
    JRScatterPlot scatterPlot = (JRScatterPlot) getPlot();
    boolean isShowLines = scatterPlot.getShowLines() == null ? false : scatterPlot.getShowLines();
    lineRenderer.setBaseLinesVisible(isShowLines);
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            lineRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
            lineRenderer.setSeriesFillPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
            lineRenderer.setSeriesPaint(i, ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(i));
            //lineRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6));
        }
    }
    return jfreeChart;
}

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

protected JFreeChart createScatterChart() throws JRException {
    JFreeChart jfreeChart = super.createScatterChart();
    XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();

    xyPlot.setRangeGridlinePaint(SCATTER_GRIDLINE_COLOR);
    xyPlot.setRangeGridlineStroke(new BasicStroke(0.75f));
    xyPlot.setDomainGridlinesVisible(true);
    xyPlot.setDomainGridlinePaint(SCATTER_GRIDLINE_COLOR);
    xyPlot.setDomainGridlineStroke(new BasicStroke(0.75f));
    xyPlot.setRangeZeroBaselinePaint(ChartThemesConstants.GRAY_PAINT_134);

    XYLineAndShapeRenderer lineRenderer = (XYLineAndShapeRenderer) xyPlot.getRenderer();
    lineRenderer.setUseFillPaint(true);/*w w w.  j  a v a 2s . c  om*/
    JRScatterPlot scatterPlot = (JRScatterPlot) getPlot();
    boolean isShowLines = scatterPlot.getShowLines() == null ? false
            : scatterPlot.getShowLines().booleanValue();
    lineRenderer.setBaseLinesVisible(isShowLines);
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset != null) {
        for (int i = 0; i < xyDataset.getSeriesCount(); i++) {
            lineRenderer.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
            lineRenderer.setSeriesFillPaint(i,
                    (Paint) ChartThemesConstants.EYE_CANDY_SIXTIES_GRADIENT_PAINTS.get(i));
            lineRenderer.setSeriesPaint(i, (Paint) ChartThemesConstants.EYE_CANDY_SIXTIES_COLORS.get(i));
            //lineRenderer.setSeriesShape(i, new Ellipse2D.Double(-3, -3, 6, 6));
        }
    }
    return jfreeChart;
}

From source file:org.gumtree.vis.awt.JChartPanel.java

@Override
public void updateLabels() {
    XYPlot xyPlot = getChart().getXYPlot();
    XYDataset xyDataset = xyPlot.getDataset();
    if (xyDataset instanceof IDataset) {
        IDataset dataset = (IDataset) xyDataset;
        try {/*  www. ja va  2s  . co  m*/
            String title = "";
            if (dataset.getXTitle() != null) {
                title += dataset.getXTitle();
            }
            if (dataset.getXUnits() != null) {
                title += " (" + dataset.getXUnits() + ")";
            }
            xyPlot.getDomainAxis().setLabel(title);
            title = "";
            if (dataset.getYTitle() != null) {
                title += dataset.getYTitle();
            }
            if (dataset.getYUnits() != null) {
                title += " (" + dataset.getYUnits() + ")";
            }
            xyPlot.getRangeAxis().setLabel(title);
            title = "";
            if (dataset.getTitle() != null) {
                title = dataset.getTitle();
            }
            getChart().getTitle().setText(title);
        } catch (Exception e) {
        }
    }
}