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

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

Introduction

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

Prototype

public int getDatasetCount() 

Source Link

Document

Returns the number of datasets.

Usage

From source file:de.bund.bfr.knime.chart.ChartUtils.java

public static void addDataSetToPlot(XYPlot plot, XYDataset dataSet, XYItemRenderer renderer) {
    int i = plot.getDataset(0) == null ? 0 : plot.getDatasetCount();

    plot.setDataset(i, dataSet);//w  w w.  ja va2  s  . c o m
    plot.setRenderer(i, renderer);
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.dec.TwoCoefsDecorator.java

/**
 * Creates a new dataset for visualizing the fitted function.
 * <p>// w  w w.j a v a 2s  .c  om
 * The new dataset is added to the end of the dataset list of the given plot.
 * </p>
 * 
 * @param aPlot Plot to which the new dataset must be added.
 * @return Index of the newly created dataset in the dataset list of <code>aPlot</code>.
 */
protected static int createDataset(XYPlot aPlot) {
    int i = aPlot.getDatasetCount();
    aPlot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);
    XYLineAndShapeRenderer rend = new XYLineAndShapeRenderer();
    rend.setSeriesLinesVisible(0, true);
    rend.setSeriesShapesVisible(0, false);
    aPlot.setRenderer(i, rend);
    return i;
}

From source file:de.mpg.mpi_inf.bioinf.netanalyzer.dec.TwoCoefsDecorator.java

/**
 * Gets the index of the first dataset containing the specified series.
 * /* ww  w . j a v a  2s  .  c  o m*/
 * @param aPlot Plot to be searched for the dataset of the fitted function.
 * @param aSeriesName Name of series the dataset should contain.
 * @return Index of the dataset which contains series named <code>aSeriesName</code>,
 *         <code>-1</code> if such dataset does not exist.
 */
protected static int getDatasetIndex(XYPlot aPlot, String aSeriesName) {
    final int datasetCount = aPlot.getDatasetCount();
    for (int i = 0; i < datasetCount; ++i) {
        if (aSeriesName.equals(aPlot.getDataset(i).getSeriesKey(0))) {
            return i;
        }
    }
    return -1;
}

From source file:ucar.unidata.idv.control.chart.HistogramWrapper.java

/**
 * Plot the displayed {@link DataChoice}.
 * //from ww  w.j  a  va  2s . c  o m
 * @param histoWrapper Cannot be {@code null}.
 */
public static void plotHistogram(HistogramWrapper histoWrapper) {
    XYPlot p = histoWrapper.plot;
    List<DataChoiceWrapper> dcWrappers = histoWrapper.getDataChoiceWrappers();

    try {
        for (int dataSetIdx = 0; dataSetIdx < p.getDatasetCount(); dataSetIdx++) {
            MyHistogramDataset dataset = (MyHistogramDataset) p.getDataset(dataSetIdx);
            dataset.removeAllSeries();
        }

        Hashtable props = new Hashtable();
        props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE);

        for (int paramIdx = 0; paramIdx < dcWrappers.size(); paramIdx++) {
            DataChoiceWrapper wrapper = dcWrappers.get(paramIdx);

            DataChoice dataChoice = wrapper.getDataChoice();
            FlatField data = histoWrapper.getFlatField((FieldImpl) dataChoice.getData(null, props));
            Unit unit = ucar.visad.Util.getDefaultRangeUnits((FlatField) data)[0];
            double[][] samples = data.getValues(false);
            double[] actualValues = histoWrapper.filterData(samples[0],
                    histoWrapper.getTimeValues(samples, data))[0];
            NumberAxis domainAxis = new NumberAxis(wrapper.getLabel(unit));

            XYItemRenderer renderer;
            if (histoWrapper.stacked) {
                renderer = new StackedXYBarRenderer();
            } else {
                renderer = new XYBarRenderer();
            }
            p.setRenderer(paramIdx, renderer);
            Color c = wrapper.getColor(paramIdx);
            domainAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);

            MyHistogramDataset dataset = new MyHistogramDataset();
            dataset.setType(HistogramType.FREQUENCY);
            dataset.addSeries(dataChoice.getName() + " [" + unit + "]", actualValues, histoWrapper.bins);
            p.setDomainAxis(paramIdx, domainAxis, false);
            p.mapDatasetToDomainAxis(paramIdx, paramIdx);
            p.setDataset(paramIdx, dataset);
        }
    } catch (VisADException | RemoteException e) {
        LogUtil.logException("Error creating data set", e);
    }
}

From source file:playground.benjamin.scenarios.zurich.analysis.charts.BkChartWriter.java

public static void writeChartDataToFile(String filename, JFreeChart chart) {
    filename += ".txt";
    try {//from   w  w  w.  j a v a2 s. c  om
        BufferedWriter writer = IOUtils.getBufferedWriter(filename);
        try { /*read "try" as if (plot instanceof XYPlot)*/
            XYPlot xy = chart.getXYPlot();
            String yAxisLabel = xy.getRangeAxis().getLabel();

            String xAxisLabel = "";
            if (xy.getDomainAxis() != null) {
                xAxisLabel = xy.getDomainAxis().getLabel();
            }
            String header = xAxisLabel + "\t " + yAxisLabel;
            writer.write(header);
            writer.newLine();
            for (int i = 0; i < xy.getDatasetCount(); i++) {
                XYDataset xyds = xy.getDataset(i);
                for (int seriesIndex = 0; seriesIndex < xyds.getSeriesCount(); seriesIndex++) {
                    writer.newLine();
                    writer.write("Series " + "'" + xyds.getSeriesKey(seriesIndex).toString());
                    writer.write("'");
                    writer.newLine();
                    int items = xyds.getItemCount(seriesIndex);
                    for (int itemsIndex = 0; itemsIndex < items; itemsIndex++) {
                        Number xValue = xyds.getX(seriesIndex, itemsIndex);
                        Number yValue = xyds.getY(seriesIndex, itemsIndex);
                        writer.write(xValue.toString());
                        writer.write("\t");
                        writer.write(yValue.toString());
                        writer.newLine();
                    }
                }
            }
            System.out.println("Table written to : " + filename + "\n"
                    + "==================================================");

        } catch (ClassCastException e) { //else instanceof CategoryPlot
            log.info("caught class cast exception, trying to write CategoryPlot");
            CategoryPlot cp = chart.getCategoryPlot();
            String header = "CategoryRowKey \t CategoryColumnKey \t CategoryRowIndex \t CategoryColumnIndex \t Value";
            writer.write(header);
            writer.newLine();
            for (int i = 0; i < cp.getDatasetCount(); i++) {
                CategoryDataset cpds = cp.getDataset(i);
                for (int rowIndex = 0; rowIndex < cpds.getRowCount(); rowIndex++) {
                    for (int columnIndex = 0; columnIndex < cpds.getColumnCount(); columnIndex++) {
                        Number value = cpds.getValue(rowIndex, columnIndex);
                        writer.write(cpds.getRowKey(rowIndex).toString());
                        writer.write("\t");
                        writer.write(cpds.getColumnKey(columnIndex).toString());
                        writer.write("\t");
                        writer.write(Integer.toString(rowIndex));
                        writer.write("\t");
                        writer.write(Integer.toString(columnIndex));
                        writer.write("\t");
                        writer.write(value.toString());
                        writer.newLine();
                    }
                }
            }

        }
        writer.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:playground.dgrether.analysis.charts.utils.DgChartWriter.java

public static void writeChartDataToFile(String filename, JFreeChart chart) {
    filename += ".txt";
    try {/*from  w  ww.  ja va  2s .  c  o m*/
        BufferedWriter writer = IOUtils.getBufferedWriter(filename);
        try { /*read "try" as if (plot instanceof XYPlot)*/
            XYPlot xy = chart.getXYPlot();
            String yAxisLabel = xy.getRangeAxis().getLabel();

            String xAxisLabel = "";
            if (xy.getDomainAxis() != null) {
                xAxisLabel = xy.getDomainAxis().getLabel();
            }
            String header = "#" + xAxisLabel + "\t " + yAxisLabel;
            writer.write(header);
            writer.newLine();
            //write the header
            writer.write("#");
            for (int i = 0; i < xy.getDatasetCount(); i++) {
                XYDataset xyds = xy.getDataset(i);
                int seriesIndex = 0;
                int maxItems = 0;
                int seriesCount = xyds.getSeriesCount();
                while (seriesIndex < seriesCount) {
                    writer.write("Series " + xyds.getSeriesKey(seriesIndex).toString());
                    if (seriesIndex < seriesCount - 1) {
                        writer.write("\t \t");
                    }
                    if (xyds.getItemCount(seriesIndex) > maxItems) {
                        maxItems = xyds.getItemCount(seriesIndex);
                    }
                    seriesIndex++;
                }
                writer.newLine();

                //write the data
                Number xValue, yValue = null;
                for (int itemsIndex = 0; itemsIndex < maxItems; itemsIndex++) {
                    for (int seriesIdx = 0; seriesIdx < seriesCount; seriesIdx++) {
                        if (seriesIdx < xyds.getSeriesCount() && itemsIndex < xyds.getItemCount(seriesIdx)) {
                            xValue = xyds.getX(seriesIdx, itemsIndex);
                            yValue = xyds.getY(seriesIdx, itemsIndex);
                            if (xValue != null && yValue != null) {
                                writer.write(xValue.toString());
                                writer.write("\t");
                                writer.write(yValue.toString());
                                if (seriesIdx < seriesCount - 1) {
                                    writer.write("\t");
                                }
                            }
                        }
                    }
                    writer.newLine();
                }
            }
        } catch (ClassCastException e) { //else instanceof CategoryPlot
            log.info("Due to a caught class cast exception, it should be a CategoryPlot");
            CategoryPlot cp = chart.getCategoryPlot();
            String header = "# CategoryRowKey \t CategoryColumnKey \t CategoryRowIndex \t CategoryColumnIndex \t Value";
            writer.write(header);
            writer.newLine();
            for (int i = 0; i < cp.getDatasetCount(); i++) {
                CategoryDataset cpds = cp.getDataset(i);
                for (int rowIndex = 0; rowIndex < cpds.getRowCount(); rowIndex++) {
                    for (int columnIndex = 0; columnIndex < cpds.getColumnCount(); columnIndex++) {
                        Number value = cpds.getValue(rowIndex, columnIndex);
                        writer.write(cpds.getRowKey(rowIndex).toString());
                        writer.write("\t");
                        writer.write(cpds.getColumnKey(columnIndex).toString());
                        writer.write("\t");
                        writer.write(Integer.toString(rowIndex));
                        writer.write("\t");
                        writer.write(Integer.toString(columnIndex));
                        writer.write("\t");
                        writer.write(value.toString());
                        writer.newLine();
                    }
                }
            }

        }
        writer.close();
        log.info("Chart data written to: " + filename);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:ec.util.chart.swing.Charts.java

@Nonnull
public static List<XYDataset> asDatasetList(@Nonnull final XYPlot plot) {
    return new AbstractList<XYDataset>() {

        @Override// w  w  w .ja v  a 2  s  .c om
        public XYDataset get(int index) {
            return plot.getDataset(index);
        }

        @Override
        public int size() {
            return plot.getDatasetCount();
        }
    };
}

From source file:org.codehaus.mojo.dashboard.report.plugin.chart.time.MarkerTimeChartDecorator.java

/**
 * Creates a legend item block./*from  www . j  av  a 2  s.c o m*/
 * 
 * @param item
 *            the legend item.
 * 
 * @return The block.
 */
protected void createLegendBlock(BlockContainer blockcontainerLabel) {

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

    int nbRenderer = xyplot.getDatasetCount();
    BlockContainer blockcontainer = new BlockContainer(new BorderArrangement());
    if (nbRenderer > 1) {
        BlockContainer oldLegendBlockContainer = new BlockContainer(
                new FlowArrangement(HorizontalAlignment.LEFT, VerticalAlignment.TOP, 2.0D, 2.0D));
        for (int i = 0; i < nbRenderer; i++) {
            LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(i));
            legendtitle.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
            legendtitle.setFrame(new LineBorder());
            legendtitle.setBackgroundPaint(ChartColor.WHITE);
            oldLegendBlockContainer.add(legendtitle);
        }

        blockcontainer.add(oldLegendBlockContainer, RectangleEdge.LEFT);
    } else {
        LegendTitle legendtitle = new LegendTitle(xyplot.getRenderer(0));
        legendtitle.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
        legendtitle.setFrame(new LineBorder());
        legendtitle.setBackgroundPaint(ChartColor.WHITE);
        blockcontainer.add(legendtitle, RectangleEdge.LEFT);
    }

    LegendTitle legendtitle1 = new LegendTitle(xyplot.getRenderer());
    legendtitle1.setMargin(new RectangleInsets(1.0, 1.0, 1.0, 1.0));
    legendtitle1.setFrame(new LineBorder());
    legendtitle1.setBackgroundPaint(ChartColor.WHITE);
    legendtitle1.setWrapper(blockcontainerLabel);

    blockcontainer.add(legendtitle1, RectangleEdge.RIGHT);
    blockcontainer.add(new EmptyBlock(1000D, 0.0D));

    CompositeTitle compositetitle = new CompositeTitle(blockcontainer);
    compositetitle.setPosition(RectangleEdge.BOTTOM);
    report.clearSubtitles();
    report.addSubtitle(compositetitle);
}

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

/**
 * Setter for property graphTime./*from   w  w  w  .j a  va 2s.  com*/
 *
 * @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: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
}