Example usage for org.jfree.chart.renderer XYItemRenderer setSeriesStroke

List of usage examples for org.jfree.chart.renderer XYItemRenderer setSeriesStroke

Introduction

In this page you can find the example usage for org.jfree.chart.renderer XYItemRenderer setSeriesStroke.

Prototype

public void setSeriesStroke(int series, Stroke stroke);

Source Link

Document

Sets the stroke used for a series and sends a RendererChangeEvent to all registered listeners.

Usage

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

/**
 * Create the charts/* w ww. j  a v a  2s.c om*/
 *
 * @throws RemoteException On badness
 * @throws VisADException On badness
 */
public void loadDatax() throws VisADException, RemoteException {

    createChart();
    times = null;
    List unitList = new ArrayList();
    List dataChoiceWrappers = getDataChoiceWrappers();
    datas.clear();
    ranges.clear();
    try {
        plot.setIgnoreDataSetChanges(true);
        plot.clearRangeAxes();
        plot.setRangeAxis(0, new NumberAxis(""), false);
        for (int dataSetIdx = 0; dataSetIdx < plot.getDatasetCount(); dataSetIdx++) {
            TimeSeriesCollection dataset = (TimeSeriesCollection) plot.getDataset(dataSetIdx);
            dataset.removeAllSeries();
        }

        //            plot.clearDatasets();
        //            dataset.setDomainIsPointsInTime(true);
        Hashtable props = new Hashtable();
        props.put(TrackDataSource.PROP_TRACKTYPE, TrackDataSource.ID_TIMETRACE);

        AxisLocation lastSide = AxisLocation.BOTTOM_OR_RIGHT;
        for (int paramIdx = 0; paramIdx < dataChoiceWrappers.size(); paramIdx++) {
            DataChoiceWrapper wrapper = (DataChoiceWrapper) dataChoiceWrappers.get(paramIdx);
            DataChoice dataChoice = wrapper.getDataChoice();
            FlatField data = getFlatField((FieldImpl) dataChoice.getData(null, props));
            Set domainSet = data.getDomainSet();
            double[][] domain = domainSet.getDoubles(false);
            double[][] samples = data.getValues(false);
            double[] var = samples[0];

            Unit unit = ucar.visad.Util.getDefaultRangeUnits(data)[0];
            Unit displayUnit = null;
            if (unit != null) {
                displayUnit = getDisplayControl().getDisplayConventions().getDisplayUnit(dataChoice.getName(),
                        null);
                if ((displayUnit != null) && !displayUnit.equals(unit)) {
                    var = displayUnit.toThis(var, unit);
                    unit = displayUnit;

                }
            }

            unitList.add(unit);
            double[] timeValues = getTimeValues(samples, (FlatField) data);
            double[][] result = filterData(var, timeValues);
            var = result[0];
            timeValues = result[1];
            TimeSeries series = new TimeSeries(dataChoice.getName() + ((unit == null) ? "" : " [" + unit + "]"),
                    FixedMillisecond.class);

            //TODO: Find the lat/lon/alt index in the domain
            times = timeValues;
            lats = domain[0];
            lons = domain[1];
            alts = domain[2];
            datas.add(var);
            long t1 = System.currentTimeMillis();
            double min = 0;
            double max = 0;
            for (int i = 0; i < var.length; i++) {
                Date dttm = new Date((long) (timeValues[i]));
                //                    series.addOrUpdate(new FixedMillisecond(dttm), var[i]);
                series.add(new FixedMillisecond(dttm), var[i]);
                if ((i == 0) || (var[i] < min)) {
                    min = var[i];
                }
                if ((i == 0) || (var[i] > max)) {
                    max = var[i];
                }
            }
            ranges.add(new ucar.unidata.util.Range(min, max));

            long t2 = System.currentTimeMillis();
            //                System.err.println ("\t time to add:" + (t2-t1));

            TimeSeriesCollection dataset = new TimeSeriesCollection();
            dataset.setDomainIsPointsInTime(true);
            dataset.addSeries(series);
            NumberAxis rangeAxis = new NumberAxis(wrapper.getLabel(unit));
            plot.setRangeAxis(paramIdx, rangeAxis, false);
            plot.setDataset(paramIdx, dataset);

            XYItemRenderer renderer = doMakeRenderer();
            plot.setRenderer(paramIdx, renderer);
            plot.mapDatasetToRangeAxis(paramIdx, paramIdx);
            Color c = wrapper.getColor(paramIdx);
            rangeAxis.setLabelPaint(c);
            renderer.setSeriesPaint(0, c);
            renderer.setSeriesStroke(0, wrapper.getLineState().getStroke());

            AxisLocation side;
            if (wrapper.getSide() == wrapper.SIDE_UNDEFINED) {
                if (lastSide == AxisLocation.TOP_OR_LEFT) {
                    side = AxisLocation.BOTTOM_OR_RIGHT;
                } else {
                    side = AxisLocation.TOP_OR_LEFT;
                }
            } else if (wrapper.getSide() == wrapper.SIDE_LEFT) {
                side = AxisLocation.TOP_OR_LEFT;
            } else {
                side = AxisLocation.BOTTOM_OR_RIGHT;
            }
            lastSide = side;
            plot.setRangeAxisLocation(paramIdx, side);
        }
    } catch (Exception exc) {
        LogUtil.logException("Error creating data set", exc);
        return;
    }

    if (dataChoiceWrappers.size() == 0) {
        NumberAxis axis = new NumberAxis("");
        plot.setRangeAxis(0, axis, false);
        ValueAxis timeAxis = doMakeDateAxis();
        plot.setDomainAxis(0, timeAxis, false);
    }

    plot.setIgnoreDataSetChanges(false);

    try {
        setLocationPositions();
    } catch (Exception exc) {
        LogUtil.logException("Error creating wayPoints", exc);
    }
}