Example usage for org.jfree.data XYSeriesCollection removeAllSeries

List of usage examples for org.jfree.data XYSeriesCollection removeAllSeries

Introduction

In this page you can find the example usage for org.jfree.data XYSeriesCollection removeAllSeries.

Prototype

public void removeAllSeries() 

Source Link

Document

Removes all the series from the collection.

Usage

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

/**
 * Create the charts//from ww w  .j  a  va 2 s  .  c  o m
 *
 * @throws RemoteException On badness
 * @throws VisADException On badness
 */
public void loadData() throws VisADException, RemoteException {

    try {
        createChart();
        for (int dataSetIdx = 0; dataSetIdx < plot.getDatasetCount(); dataSetIdx++) {
            XYSeriesCollection dataset = (XYSeriesCollection) plot.getDataset(dataSetIdx);
            dataset.removeAllSeries();
        }
        ((MyScatterPlot) plot).removeAllSeries();
        Hashtable props = new Hashtable();
        props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE);

        List dataChoiceWrappers = getDataChoiceWrappers();
        int dataSetCnt = 0;
        for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx += 2) {
            if (paramIdx + 1 >= dataChoiceWrappers.size()) {
                break;
            }
            DataChoiceWrapper wrapper1 = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx);
            DataChoiceWrapper wrapper2 = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx + 1);

            DataChoice dataChoice1 = wrapper1.getDataChoice();
            DataChoice dataChoice2 = wrapper2.getDataChoice();

            FlatField data1 = getFlatField((FieldImpl) dataChoice1.getData(null, props));
            FlatField data2 = getFlatField((FieldImpl) dataChoice2.getData(null, props));
            Unit unit1 = ucar.visad.Util.getDefaultRangeUnits((FlatField) data1)[0];
            Unit unit2 = ucar.visad.Util.getDefaultRangeUnits((FlatField) data2)[0];

            NumberAxis rangeAxis = new NumberAxis(wrapper2.getLabel(unit2));
            NumberAxis domainAxis = new NumberAxis(wrapper1.getLabel(unit1));

            domainAxis.setAutoRange(getAutoRange());

            Color c = wrapper1.getColor(paramIdx);
            MyRenderer renderer = new MyRenderer(wrapper1.getLineState().getShape());
            domainAxis.setLabelPaint(c);
            rangeAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);

            double[][] samples1 = data1.getValues(false);
            double[][] samples2 = data2.getValues(false);
            double[] timeValues1 = getTimeValues(samples1, data1);
            double[] timeValues2 = getTimeValues(samples2, data2);
            double[][] values1 = filterData(samples1[0], timeValues1);
            double[][] values2 = filterData(samples2[0], timeValues2);
            if (values1.length > 1) {
                this.timeValues1 = values1[1];
                this.timeValues2 = values2[1];
            }
            double[][] values = { values1[0], values2[0] };
            ((MyScatterPlot) plot).addSeries(values);

            //Add in a dummy dataset
            XYSeriesCollection dataset = new XYSeriesCollection(new XYSeries(""));

            if (!getAutoRange()) {
                NumberAxis oldRangeAxis = (NumberAxis) plot.getRangeAxis(dataSetCnt);
                NumberAxis oldDomainAxis = (NumberAxis) plot.getDomainAxis(dataSetCnt);
                if ((oldRangeAxis != null) && (oldDomainAxis != null)) {
                    rangeAxis.setRange(oldRangeAxis.getRange());
                    domainAxis.setRange(oldDomainAxis.getRange());
                }
            }

            plot.setDataset(dataSetCnt, dataset);
            plot.setRenderer(dataSetCnt, renderer);
            plot.setRangeAxis(dataSetCnt, rangeAxis, false);
            plot.setDomainAxis(dataSetCnt, domainAxis, false);
            plot.mapDatasetToRangeAxis(dataSetCnt, dataSetCnt);
            plot.mapDatasetToDomainAxis(dataSetCnt, dataSetCnt);

            if (!getAutoRange()) {
                rangeAxis.setAutoRange(false);
                domainAxis.setAutoRange(false);
            }

            dataSetCnt++;
        }
    } catch (Exception exc) {
        LogUtil.logException("Error creating data set", exc);
    }

}