Example usage for org.jfree.data.xy DefaultTableXYDataset getSeriesKey

List of usage examples for org.jfree.data.xy DefaultTableXYDataset getSeriesKey

Introduction

In this page you can find the example usage for org.jfree.data.xy DefaultTableXYDataset getSeriesKey.

Prototype

@Override
public Comparable getSeriesKey(int series) 

Source Link

Document

Returns the key for a series.

Usage

From source file:org.moeaframework.analysis.plot.Plot.java

/**
 * Creates a new area plot series.  The data will be stacked with
 * any preceding calls to {@code stacked}.  The series is added to the given
 * dataset, or if {@code null} a new dataset is created.
 * //www  .  j a v a 2 s .  c  om
 * @param label the label for the series
 * @param x the x values
 * @param y the y values
 * @param dataset the dataset, or {@code null} if a new dataset should be
 *        created
 * @return a reference to this {@code Plot} instance
 */
private Plot stacked(String label, List<? extends Number> x, List<? extends Number> y,
        DefaultTableXYDataset dataset) {
    if (dataset == null) {
        createXYPlot();

        XYPlot plot = chart.getXYPlot();

        if (plot.getDataset(currentDataset) instanceof DefaultTableXYDataset) {
            dataset = (DefaultTableXYDataset) plot.getDataset(currentDataset);
        } else {
            currentDataset++;
            dataset = new DefaultTableXYDataset();
        }
    }

    // generate the dataset
    XYSeries series = new XYSeries(label, true, false);

    for (int i = 0; i < x.size(); i++) {
        series.add(x.get(i), y.get(i));
    }

    dataset.addSeries(series);

    // add the dataset to the plot
    XYPlot plot = chart.getXYPlot();
    plot.setDataset(currentDataset, dataset);

    // setup the renderer
    Paint paint = paintHelper.get(dataset.getSeriesKey(0));
    StackedXYAreaRenderer renderer = new StackedXYAreaRenderer();
    renderer.setAutoPopulateSeriesStroke(false);

    renderer.setBaseStroke(new BasicStroke(3f, 1, 1));
    renderer.setBasePaint(paint);
    renderer.setBaseFillPaint(paint);

    plot.setRenderer(currentDataset, renderer);

    return this;
}