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(int index) 

Source Link

Document

Returns the dataset with the specified index, or null if there is no dataset with that index.

Usage

From source file:edu.jhuapl.graphs.jfreechart.JFreeChartTimeSeriesGraphSourceTestCase.java

private void validateChart(JFreeChart chart) {
    XYPlot plot = chart.getXYPlot();
    assertEquals(1, plot.getDatasetCount());
    assertEquals(3, plot.getDataset(0).getSeriesCount());

    // TODO add more please
}

From source file:gda.plots.SimpleXYItemRenderer.java

/**
 * Creates a LegendItem for a SimpleXYSeries in the dataset - note that here we create a SimpleLegendItem which
 * knows about the data it belongs to./*  www. j a  v  a2 s . c o  m*/
 * 
 * @param datasetIndex
 *            which dataset (left or right effectively)
 * @param series
 *            which data series
 * @return the created legend
 */
@Override
public LegendItem getLegendItem(int datasetIndex, int series) {
    LegendItem result = null;

    XYPlot plot = getPlot();
    if (plot != null) {
        SimpleXYSeriesCollection dataset = (SimpleXYSeriesCollection) plot.getDataset(datasetIndex);
        if (dataset != null) {
            SimpleXYSeries sxys = (SimpleXYSeries) dataset.getSeries(series);

            if (sxys.isVisible() && sxys.isVisibleInLegend()) {
                result = new SimpleLegendItem(sxys);
            }
        }

    }

    return result;

}

From source file:com.fr3ts0n.ecu.gui.application.ObdDataPlotter.java

/**
 * Setter for property graphTime.//from   w  ww .j a v  a  2s .c om
 *
 * @param graphTime New value of property graphTime.
 */
@SuppressWarnings("rawtypes")
public synchronized void setGraphTime(int graphTime) {
    TimeSeries currSer;
    TimeSeriesCollection currDs;
    XYPlot currPlot = (XYPlot) chart.getPlot();
    this.graphTime = graphTime;
    // lop through all datasets
    for (int i = currPlot.getDatasetCount(); i >= 0; --i) {
        currDs = (TimeSeriesCollection) currPlot.getDataset(i);
        // Update all series within dataset
        Iterator it = currDs.getSeries().iterator();
        while (it.hasNext()) {
            currSer = (TimeSeries) it.next();
            currSer.setMaximumItemAge(graphTime);
        }
    }
}

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

/**
 * Returns a default legend item for the specified series. Subclasses should
 * override this method to generate customised items.
 * //from w  w w . j  a v  a 2s.  c om
 * @param datasetIndex
 *          the dataset index (zero-based).
 * @param series
 *          the series index (zero-based).
 * 
 * @return A legend item for the series.
 */
public LegendItem getLegendItem(int datasetIndex, int series) {
    LegendItem result = null;
    XYPlot xyplot = getPlot();
    if (xyplot != null) {
        XYDataset dataset = xyplot.getDataset(datasetIndex);
        if (dataset != null) {
            XYSeriesLabelGenerator lg = getLegendItemLabelGenerator();
            String label = lg.generateLabel(dataset, series);
            String description = label;
            String toolTipText = null;
            if (getLegendItemToolTipGenerator() != null) {
                toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
            }
            String urlText = null;
            if (getLegendItemURLGenerator() != null) {
                urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
            }
            Shape shape = getLegendBar();
            Paint paint = getSeriesPaint(series);
            Paint outlinePaint = getSeriesOutlinePaint(series);
            Stroke outlineStroke = getSeriesOutlineStroke(series);

            // This is the fix for bug #2695
            if (paint instanceof java.awt.GradientPaint) {
                // When the paintstyle is "shade" use the lighter
                // color while with "light" use the darker color
                // NOTE: if we take the lighter color (Color2) and make it darker
                // and it equals the darker color (Color1) then the paintstyle
                // is "shade".
                GradientPaint gp = ((GradientPaint) paint);
                if (cfCHART.getDarkerColor(gp.getColor2()).equals(gp.getColor1()))
                    paint = gp.getColor2(); // the lighter color
                else
                    paint = gp.getColor1(); // the darker color
            }

            result = new LegendItem(label, description, toolTipText, urlText, shape, paint, outlineStroke,
                    outlinePaint);
        }
    }
    return result;
}

From source file:ste.travian.world.TileRenderer.java

/**
 * Returns a legend item for the specified series.
 *
 * @param datasetIndex  the dataset index (zero-based).
 * @param series  the series index (zero-based).
 *
 * @return A legend item for the series (possibly <code>null</code>).
 *///from  w  w w.  jav a2 s.c  o m
public LegendItem getLegendItem(int datasetIndex, int series) {

    // if the renderer isn't assigned to a plot, then we don't have a
    // dataset...
    XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }

    XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }

    LegendItem result = null;
    if (getItemVisible(series, 0)) {
        String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
        String description = label;
        String toolTipText = null;
        if (getLegendItemToolTipGenerator() != null) {
            toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
        }
        String urlText = null;
        if (getLegendItemURLGenerator() != null) {
            urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
        }
        Paint fillPaint = lookupSeriesPaint(series);
        result = new LegendItem(label, description, toolTipText, urlText, getLegendShape(), fillPaint);
        result.setSeriesKey(dataset.getSeriesKey(series));
        result.setSeriesIndex(series);
        result.setDataset(dataset);
        result.setDatasetIndex(datasetIndex);
    }

    return result;

}

From source file:OAT.ui.BarChartFrame.java

public void addDataset(ChartDataset dataset) {
    if (dataset == null || dataset.getSeriesCount() == 0) {
        return;/*ww w .j a va 2  s .c o m*/
    }

    XYPlot plot = getChart().getXYPlot();
    int i = plot.getDatasetCount();

    for (int j = 0; j < i; j++) {
        if (plot.getDataset(j).equals(dataset)) {
            //                System.out.println("eq " + i
            //                        + " " + ((ChartDataset) plot.getDataset(j)).getTitle()
            //                        + " " + dataset.getTitle());
            return;
        }
    }

    plot.setDataset(i, dataset);
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.REVERSE);
    Double[] range = dataset.getAxisRange();

    //axis
    int axisId = 0;

    if (range != null) {
        //        if (range == null || range.length < 2) {
        //            plot.mapDatasetToRangeAxis(i, 0);
        //        } else {

        //scan for equal axis range, reuse if found
        boolean hasSameRange = false;

        if (range.length > 1) {
            for (int j = 1; j < plot.getRangeAxisCount(); j++) {
                Range otherRange = plot.getRangeAxis(j).getRange();

                if (otherRange != null && otherRange.getLowerBound() == range[0]
                        && otherRange.getUpperBound() == range[1]) {
                    axisId = j;
                    hasSameRange = true;
                    break;
                }
            }
        }

        if (!hasSameRange) {
            NumberAxis newAxis = new NumberAxis();

            if (range.length > 1) {
                newAxis.setAutoRange(false);
                newAxis.setRange(range[0], range[1]);
            }

            if (range.length > 2) {
                newAxis.setAutoTickUnitSelection(false, false);
                newAxis.setTickUnit(new NumberTickUnit(range[2]));
            }

            newAxis.setNumberFormatOverride(TextUtil.SIMPLE_FORMATTER);
            //                    newAxis.setAxisLinePaint(new Color(100, 0, 0));
            //                    newAxis.setLabelPaint(paints[i][0]);
            //                    newAxis.setTickLabelPaint(paints[i][0]);
            //                    newAxis.setTickMarkPaint(paints[i][0]);
            //                    newAxis.setTickLabelsVisible(true);

            axisId = plot.getRangeAxisCount();
            plot.setRangeAxis(axisId, newAxis, false);
            plot.setRangeAxisLocation(axisId, AxisLocation.BOTTOM_OR_LEFT, false);
        }
        //            plot.mapDatasetToRangeAxis(i, newAxisId);
    }
    plot.mapDatasetToRangeAxis(i, axisId);
    //

    //renderer
    XYLineAndShapeRenderer renderer;

    if (dataset instanceof TradeDataset) {
        renderer = new TradeRenderer();

        for (int j = 0; j < dataset.getSeriesCount(); j++) {
            renderer.setSeriesLinesVisible(j, false);
        }
    } else {

        Shape shape = Main.defaultShape;
        Paint[][] seriesPaints;
        Stroke stroke;

        if (dataset.getSource() instanceof Stopper && !(dataset.getSource() instanceof Calculator)) {
            seriesPaints = Main.greyPaints;
            stroke = Main.dottedStoke;
        } else {
            seriesPaints = Main.defaultPaints;
            stroke = Main.defaultStoke;
        }

        renderer = new IndicatorRenderer(seriesPaints[(i - 1) % seriesPaints.length], shape, stroke);
    }

    plot.setRenderer(i, renderer, false);
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.backport.XYDotRenderer.java

/**
 * Returns a legend item for the specified series.
 *
 * @param datasetIndex the dataset index (zero-based).
 * @param series       the series index (zero-based).
 * @return A legend item for the series (possibly <code>null</code>).
 *///from  w  ww.ja v a 2  s  .c o  m
public LegendItem getLegendItem(final int datasetIndex, final int series) {

    // if the renderer isn't assigned to a plot, then we don't have a
    // dataset...
    final XYPlot plot = getPlot();
    if (plot == null) {
        return null;
    }

    final XYDataset dataset = plot.getDataset(datasetIndex);
    if (dataset == null) {
        return null;
    }

    LegendItem result = null;
    if (getItemVisible(series, 0)) {
        final String label = getLegendItemLabelGenerator().generateLabel(dataset, series);
        String toolTipText = null;
        if (getLegendItemToolTipGenerator() != null) {
            toolTipText = getLegendItemToolTipGenerator().generateLabel(dataset, series);
        }
        String urlText = null;
        if (getLegendItemURLGenerator() != null) {
            urlText = getLegendItemURLGenerator().generateLabel(dataset, series);
        }
        final Paint fillPaint = lookupSeriesPaint(series);
        result = new LegendItem(label, label, toolTipText, urlText, getLegendShape(), fillPaint);
        result.setSeriesKey(dataset.getSeriesKey(series));
        result.setSeriesIndex(series);
        result.setDataset(dataset);
        result.setDatasetIndex(datasetIndex);
    }

    return result;

}

From source file:net.sf.maltcms.chromaui.charts.format.ScaledNumberFormatter.java

/**
 *
 * @param cce/*from  w w w. j  a  va 2 s .  c o  m*/
 */
@Override
public void chartChanged(ChartChangeEvent cce) {
    ChartChangeEventType ccet = cce.getType();
    if (ccet == ChartChangeEventType.DATASET_UPDATED || ccet == ChartChangeEventType.NEW_DATASET) {
        if (cce.getSource() != (this)) {
            Plot p = cce.getChart().getPlot();
            if (p instanceof XYPlot) {
                XYPlot xyp = (XYPlot) p;
                Range axisRange = xyp.getRangeAxis().getRange();
                ;
                if (relativeMode) {
                    int cnt = xyp.getDatasetCount();
                    Range r = new Range(0, 1);
                    for (int i = 0; i < cnt; i++) {
                        Dataset d = xyp.getDataset(i);
                        if (d != null && d instanceof XYDataset) {
                            XYDataset xyd = (XYDataset) d;
                            Range dr = DatasetUtilities.findRangeBounds(xyd);
                            if (dr != null) {
                                r = new Range(Math.min(r.getLowerBound(), dr.getLowerBound()),
                                        Math.max(r.getUpperBound(), dr.getUpperBound()));

                            }
                        } else {
                            throw new NotImplementedException(
                                    "No support yet for dataset of type: " + d.getClass());
                        }
                    }
                    this.dataMin = Math.min(0, r.getLowerBound());
                    this.dataMax = r.getUpperBound();
                    cce.getChart().fireChartChanged();
                } else {
                    this.min = axisRange.getLowerBound();
                    this.max = axisRange.getUpperBound();
                    cce.getChart().fireChartChanged();
                }
            }
        }
    }
}

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

private void setAxisRenderer(XYPlot plot, int axisIndex, boolean isBarChart, boolean hasDataPoints,
        int lineWeight) {
    XYItemRenderer renderer;/*from  ww  w.  j ava2s .  c  om*/
    if (isBarChart) {
        renderer = new ClusteredXYBarRenderer();
        XYDataset axisDataset = plot.getDataset(axisIndex);
        plot.setDataset(axisIndex, new XYBarDataset(axisDataset, calculateBarWidth(axisDataset, lineWeight)));

    } else {
        renderer = new XYLineAndShapeRenderer(true, hasDataPoints);

        if (lineWeight >= 0 && lineWeight <= 5) {
            for (int seriesIndex = 0; seriesIndex < plot.getDataset(axisIndex)
                    .getSeriesCount(); seriesIndex++) {
                renderer.setSeriesStroke(seriesIndex, new BasicStroke((float) lineWeight));
            }
        }
    }
    renderer.setBaseToolTipGenerator(getToolTipGenerator());
    plot.setRenderer(axisIndex, renderer);
}

From source file:org.jfree.eastwood.ChartEngine.java

/**
 * The 'ewtr' tag is an Eastwood extension that draws a trend line over a
 * chart, using data that has been added to a secondary dataset using the
 * 'ewd2' tag./*from w ww  .ja v  a  2 s  .c o  m*/
 *
 * @param params  the chart parameters;
 * @param chart  the chart under construction (will be updated by this
 *         method if necessary).
 */
public static void processEWTR(Map params, JFreeChart chart) {
    // the 'ewtr' arguments are:
    // - <seriesIndex> : the index of the series in the secondary dataset;
    // - <colour> : the colour;
    // - <lineThickness> : the line thickness;
    String[] ewtrStr = (String[]) params.get("ewtr");
    if (ewtrStr != null) {
        String[] atts = ewtrStr[0].split(",");
        int series = Integer.parseInt(atts[0]);
        Color color = parseColor(atts[1]);
        float lineWidth = Float.parseFloat(atts[2]);
        Plot plot = chart.getPlot();
        if (plot instanceof CategoryPlot) {
            CategoryPlot cp = (CategoryPlot) plot;
            if (cp.getDataset(1) != null) {
                LineAndShapeRenderer r = new LineAndShapeRenderer(true, false);
                r.setBaseSeriesVisible(false);
                r.setSeriesVisible(series, Boolean.TRUE);
                r.setSeriesPaint(series, color);
                r.setSeriesStroke(series, new BasicStroke(lineWidth));
                cp.setRenderer(1, r);

                cp.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
            }
        } else if (plot instanceof XYPlot) {
            XYPlot xp = (XYPlot) plot;
            if (xp.getDataset(1) != null) {
                XYLineAndShapeRenderer r = new XYLineAndShapeRenderer(true, false);
                r.setBaseSeriesVisible(false);
                r.setSeriesVisible(series, Boolean.TRUE);
                r.setSeriesPaint(series, color);
                r.setSeriesStroke(series, new BasicStroke(lineWidth));
                xp.setRenderer(1, r);
                xp.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
            }
        }
    }

}