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

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

Introduction

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

Prototype

public void setDomainAxis(int index, ValueAxis axis, boolean notify) 

Source Link

Document

Sets a domain axis and, if requested, sends a PlotChangeEvent to all registered listeners.

Usage

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

/**
 * Plot the displayed {@link DataChoice}.
 * //w  w  w. j a va  2s . co  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);
    }
}