Example usage for org.jfree.data.xy DefaultXYZDataset addSeries

List of usage examples for org.jfree.data.xy DefaultXYZDataset addSeries

Introduction

In this page you can find the example usage for org.jfree.data.xy DefaultXYZDataset addSeries.

Prototype

public void addSeries(Comparable seriesKey, double[][] data) 

Source Link

Document

Adds a series or if a series with the same key already exists replaces the data for that series, then sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.jfree.data.xy.junit.DefaultXYZDatasetTest.java

/**
 * Confirm that cloning works.//w  w w  .ja v a 2s  .  c  o  m
 */
public void testCloning() {
    DefaultXYZDataset d1 = new DefaultXYZDataset();
    DefaultXYZDataset d2 = null;
    try {
        d2 = (DefaultXYZDataset) d1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(d1 != d2);
    assertTrue(d1.getClass() == d2.getClass());
    assertTrue(d1.equals(d2));

    // try a dataset with some content...
    double[] x1 = new double[] { 1.0, 2.0, 3.0 };
    double[] y1 = new double[] { 4.0, 5.0, 6.0 };
    double[] z1 = new double[] { 7.0, 8.0, 9.0 };
    double[][] data1 = new double[][] { x1, y1, z1 };
    d1.addSeries("S1", data1);
    try {
        d2 = (DefaultXYZDataset) d1.clone();
    } catch (CloneNotSupportedException e) {
        e.printStackTrace();
    }
    assertTrue(d1 != d2);
    assertTrue(d1.getClass() == d2.getClass());
    assertTrue(d1.equals(d2));

    // check that the clone doesn't share the same underlying arrays.
    x1[1] = 2.2;
    assertFalse(d1.equals(d2));
    x1[1] = 2.0;
    assertTrue(d1.equals(d2));
}

From source file:diet.gridr.g5k.gui.GanttChart.java

/**
 * Method creating the dataset//from w  ww .ja v a2 s.c om
 *
 * @return the dataset
 */
private XYZDataset createDataset() {

    long numberOfBlocks = HistoryUtil.durationsTimesArray[visualizationDuration]
            / HistoryUtil.blockWidthsArray[visualizationDuration];
    double[] xvalues = new double[(int) (numberOfNodes * numberOfBlocks)];
    double[] yvalues = new double[(int) (numberOfNodes * numberOfBlocks)];
    double[] zvalues = new double[(int) (numberOfNodes * numberOfBlocks)];
    double[][] data = new double[][] { xvalues, yvalues, zvalues };
    Iterator<GridJob> iterJobs = jobsList.get(visualizationDuration).iterator();
    long now = Calendar.getInstance().getTimeInMillis();
    while (iterJobs.hasNext()) {
        GridJob thisJob = iterJobs.next();
        // get the maximum date between now and the start date of the job
        long startDate = (Long.parseLong(thisJob.getParameterValue(GridJob.KEY_GRID_JOB_SCHEDTIME)) - now > 0)
                ? (Long.parseLong(thisJob.getParameterValue(GridJob.KEY_GRID_JOB_SCHEDTIME)))
                : now;
        //getDateFromOARDate(thisJob.getParameterValue(GridJob.KEY_GRID_JOB_SCHEDTIME)).getTime()-now > 0 )?getDateFromOARDate(thisJob.getParameterValue(GridJob.KEY_GRID_JOB_SCHEDTIME)).getTime():now;
        long timeFromNow = startDate - now;
        long endDateInMillis = Long.parseLong(thisJob.getParameterValue(GridJob.KEY_GRID_JOB_STARTTIME));
        //getDateFromOARDate(thisJob.getParameterValue(GridJob.KEY_GRID_JOB_STARTTIME)).getTime();
        //                    getDateFromWallTime(thisJob.getParam(GridJob.GJOB_WALLTIME));
        long wt = Long.parseLong(thisJob.getParameterValue(GridJob.KEY_GRID_JOB_WALLTIME));
        //            try {
        //                     wt = Long.parseLong(thisJob.getParameterValue(GridJob.KEY_GRID_JOB_WALLTIME));
        //            }
        //            catch (Exception e) {
        //                
        //            }
        endDateInMillis += wt;
        long chartEnd = now + HistoryUtil.durationsTimesArray[visualizationDuration];
        long endDate = (endDateInMillis - chartEnd > 0) ? chartEnd : endDateInMillis;
        long durationOfTheJob = endDate - startDate;
        long numberOfBlocksOfTheJob = durationOfTheJob / HistoryUtil.blockWidthsArray[visualizationDuration];
        int startBlock = (int) (timeFromNow / HistoryUtil.blockWidthsArray[visualizationDuration]);
        boolean printed = true;
        // if (thisJob.jobHosts.equalsIgnoreCase("")){
        if (thisJob.getParameterValue(GridJob.KEY_GRID_JOB_HOSTS) == null) {
        } else {
            Iterator<Integer> iterNodes = getNodesList(thisJob).iterator();
            while (iterNodes.hasNext()) {
                int aNode = iterNodes.next();
                for (int aBlock = 0; aBlock < numberOfBlocksOfTheJob; aBlock++) {
                    // number Of time blocks
                    try {
                        int index = (int) ((aNode - 1) * (numberOfBlocks) + aBlock + startBlock);
                        xvalues[index] = now
                                + (startBlock + aBlock) * HistoryUtil.blockWidthsArray[visualizationDuration];
                        yvalues[index] = aNode;
                        if (thisJob.getParameterValue(GridJob.KEY_GRID_JOB_ID).startsWith("0.oar")) {
                            zvalues[index] = jobsList.get(visualizationDuration).indexOf(thisJob);
                            if (printed) {
                                printed = false;
                            }
                        }
                        zvalues[index] = jobsList.get(visualizationDuration).indexOf(thisJob);
                    } catch (Exception e) {
                        LoggingManager.log(Level.CONFIG, LoggingManager.RESOURCESTOOL,
                                this.getClass().getName(), "createDataset", e);
                    }
                }
            }
        }
    }
    DefaultXYZDataset dataset = new DefaultXYZDataset();
    dataset.addSeries("Series 1", data);
    LoggingManager.log(Level.CONFIG, LoggingManager.RESOURCESTOOL, this.getClass().getName(), "createDataset",
            "Dataset created");
    return dataset;
}

From source file:sim.util.media.chart.BubbleChartGenerator.java

protected void update() {
    // we'll rebuild the plot from scratch

    SeriesAttributes[] sa = getSeriesAttributes();
    //XYPlot xyplot = (XYPlot)(chart.getPlot());
    DefaultXYZDataset dataset = new DefaultXYZDataset();

    for (int i = 0; i < sa.length; i++) {
        BubbleChartSeriesAttributes attributes = (BubbleChartSeriesAttributes) (sa[i]);
        double scale = attributes.getScale();

        // copy over values, and square-root the z-value.
        // A bug in JFreeChart means that z-values are not shown by
        // area but rather by (ugh) diameter.
        // Also we'll take advantage of this situation to allow
        // for user-defined scaling of the bubbles on a per-series basis.

        double[][] values = attributes.getValues();
        double[][] v2 = new double[values.length][values[0].length];
        for (int k = 0; k < v2.length; k++)
            for (int j = 0; j < v2[k].length; j++)
                v2[k][j] = values[k][j];
        for (int j = 0; j < v2[2].length; j++)
            v2[2][j] = Math.sqrt(scale * v2[2][j]);

        dataset.addSeries(new UniqueString(attributes.getSeriesName()), v2);
    }/*from   www  .  j  a  v  a 2 s.co m*/

    setSeriesDataset(dataset);
}

From source file:org.jfree.data.xy.junit.DefaultXYZDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *//*  w  w  w.j  a  v a2  s  . co m*/
public void testSerialization() {

    DefaultXYZDataset d1 = new DefaultXYZDataset();
    DefaultXYZDataset d2 = null;

    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (DefaultXYZDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

    // try a dataset with some content...
    double[] x1 = new double[] { 1.0, 2.0, 3.0 };
    double[] y1 = new double[] { 4.0, 5.0, 6.0 };
    double[] z1 = new double[] { 7.0, 8.0, 9.0 };
    double[][] data1 = new double[][] { x1, y1, z1 };
    d1.addSeries("S1", data1);
    try {
        ByteArrayOutputStream buffer = new ByteArrayOutputStream();
        ObjectOutput out = new ObjectOutputStream(buffer);
        out.writeObject(d1);
        out.close();

        ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
        d2 = (DefaultXYZDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

}

From source file:edu.gmu.cs.sim.util.media.chart.BubbleChartGenerator.java

protected void update() {
    // we'll rebuild the plot from scratch

    SeriesAttributes[] sa = getSeriesAttributes();
    //XYPlot xyplot = (XYPlot)(chart.getPlot());
    DefaultXYZDataset dataset = new DefaultXYZDataset();

    for (int i = 0; i < sa.length; i++) {
        BubbleChartSeriesAttributes attributes = (BubbleChartSeriesAttributes) (sa[i]);
        double scale = attributes.getScale();

        // copy over values, and square-root the z-value.
        // A bug in JFreeChart means that z-values are not shown by
        // area but rather by (ugh) diameter.
        // Also we'll take advantage of this situation to allow
        // for user-defined scaling of the bubbles on a per-series basis.

        double[][] values = attributes.getValues();
        double[][] v2 = new double[values.length][values[0].length];
        for (int k = 0; k < v2.length; k++) {
            for (int j = 0; j < v2[k].length; j++) {
                v2[k][j] = values[k][j];
            }//from  w  ww.j av  a  2s . co  m
        }
        for (int j = 0; j < v2[2].length; j++) {
            v2[2][j] = Math.sqrt(scale * v2[2][j]);
        }

        dataset.addSeries(new UniqueString(attributes.getSeriesName()), v2);
    }

    setSeriesDataset(dataset);
}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithHeatMap.java

public void setData(double[] xValues, double[] yValues, double[][] zValues) {
    this.xValues = xValues;
    this.yValues = yValues;
    this.zValues = zValues;

    double minZValue = Double.MAX_VALUE;
    double maxZValue = Double.MIN_VALUE;
    int width = xValues.length;
    int height = yValues.length;
    int numCells = width * height;
    _log.debug("Number of cells in heat map: " + numCells);
    if (zValues.length != width || zValues[0].length != height)
        throw new RuntimeException(
                "PanelWithHeatMap: wrong number of z values for x and y values (" + zValues.length + " vs. "
                        + width + ", " + zValues[0].length + " vs. " + height + ", x/y first, z second)");
    DefaultXYZDataset theDataset = new DefaultXYZDataset();
    double[][] data = new double[3][numCells];
    for (int j = 0; j < height; j++) {
        for (int i = 0; i < width; i++) {
            int cellIndex = (j * width) + i;
            data[0][cellIndex] = xValues[i];
            data[1][cellIndex] = yValues[j];
            data[2][cellIndex] = zValues[i][j];
            //keep track of lowest/highest z values
            minZValue = Math.min(zValues[i][j], minZValue);
            maxZValue = Math.max(zValues[i][j], maxZValue);
        }//ww w.  ja va  2s  . c o  m
    }
    lowerZBound = Rounder.round(minZValue, 3);
    upperZBound = Rounder.round(maxZValue, 3);
    if (lowerZBound == upperZBound)
        upperZBound += .0001;
    _log.debug("low,high values: " + lowerZBound + ", " + upperZBound);
    theDataset.addSeries("Range: " + lowerZBound + "-" + upperZBound, data);

    dataset = theDataset;
    if (renderer == null) {
        renderer = new XYBlockRenderer();
    }

    if (paintScale == null) {
        setPaintScale(createPaintScale(palette));
    }
    //This is necessary to get everything to line up
    renderer.setBlockAnchor(RectangleAnchor.BOTTOM);

    if (getPlot() != null) {
        ((XYPlot) getPlot()).setDataset(dataset);
        ((XYPlot) getPlot()).setRenderer(renderer);

        invalidate();
        return;
    }
    XYPlot plot = new XYPlot(dataset, xAxis, yAxis, renderer);

    JFreeChart chart = new JFreeChart(dataSetName, JFreeChart.DEFAULT_TITLE_FONT, plot, true);

    //        chart.addLegend(new LegendTitle(renderer));
    //        PaintScaleLegend legend = new PaintScaleLegend(paintScale, xAxis);
    //        chart.addLegend(legend);

    //        LegendItemCollection c1 = new LegendItemCollection();
    //
    //        LegendItem item1 = new LegendItem("Label", "Description",
    //                "ToolTip", "URL", true,
    //                new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0), true, Color.red,
    //                true, Color.blue, new BasicStroke(1.2f), true,
    //                new Line2D.Double(1.0, 2.0, 3.0, 4.0),
    //                new BasicStroke(2.1f), Color.green);
    //        LegendItem item2 = new LegendItem("Label", "Description",
    //                "ToolTip", "URL", true,
    //                new Rectangle2D.Double(1.0, 2.0, 3.0, 4.0),
    //                true, Color.red, true, Color.blue, new BasicStroke(1.2f), true,
    //                new Line2D.Double(1.0, 2.0, 3.0, 4.0), new BasicStroke(2.1f),
    //                Color.green);
    //        c1.add(item1);
    //
    //        chart.getLegend().setSources(new LegendItemSource[]{renderer});

    init(chart);
}

From source file:vteaexploration.plottools.panels.XYChartPanel.java

private DefaultXYZDataset createXYZDataset(ArrayList alVolumes, int x, int y, int l) {
    //System.out.println("PROFILING: New dataset, for  " + alVolumes.size() + " objects.");
    DefaultXYZDataset result = new DefaultXYZDataset();
    int counter = 0;

    double[] xCorrected = new double[alVolumes.size()];
    double[] yCorrected = new double[alVolumes.size()];
    double[] lCorrected = new double[alVolumes.size()];

    ListIterator litr = alVolumes.listIterator();

    while (litr.hasNext()) {
        //            try {
        MicroObjectModel volume = (MicroObjectModel) litr.next();
        xCorrected[counter] = processPosition(x, volume).doubleValue();
        yCorrected[counter] = processPosition(y, volume).doubleValue();
        if (l > 0) {
            lCorrected[counter] = processPosition(l, volume).doubleValue();
        } else {//  w  ww .j a va2 s .c  o m
            lCorrected[counter] = 0;
        }

        counter++;
        //            } 
        //            catch (NullPointerException e) {
        //                System.out.println("EXCEPTION:  Error building dataset.");
        //            }
    }

    double[][] series = new double[][] { xCorrected, yCorrected, lCorrected };
    result.addSeries("first", series);

    return result;
}

From source file:com.peterbochs.instrument.InstrumentPanel.java

private static XYZDataset createDataset() {
    long rowCount = Data.getRowCount(CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()),
            CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()),
            CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem()));
    long columnCount = Data.getColumnCount(CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()),
            CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()),
            CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem()));
    double[] xvalues = new double[(int) (columnCount * rowCount)];
    double[] yvalues = new double[(int) (columnCount * rowCount)];
    double[] zvalues = new double[(int) (columnCount * rowCount)];
    double[][] data = new double[][] { xvalues, yvalues, zvalues };

    // set the default z-value to zero throughout the data array.
    for (int y = 0; y < rowCount; y++) {
        for (int x = 0; x < columnCount; x++) {
            setValue(data, x, y, 0.0);// w ww  .j  a  va 2s .c o  m
        }
    }

    int dataB[] = Data.getChartData(CommonLib.convertFilesize((String) jFromComboBox.getSelectedItem()),
            CommonLib.convertFilesize((String) jToComboBox.getSelectedItem()),
            CommonLib.convertFilesize((String) jBlockSizeComboBox.getSelectedItem()));
    for (int index = 0; index < dataB.length; index++) {
        int y = (int) (index / columnCount);
        int x = (int) (index - (y * columnCount));
        setValue(data, x, y, dataB[index]);
    }

    DefaultXYZDataset dataset = new DefaultXYZDataset();
    dataset.addSeries("read/write count", data);
    return dataset;
}

From source file:net.sf.maltcms.chromaui.charts.Chromatogram1DChartProvider.java

/**
 *
 * @param fragments//from  ww w.  j  a  v  a  2s  . c  o  m
 * @param ticvar
 * @param useRT
 * @return
 */
public XYPlot provide1DCoPlot(List<IFileFragment> fragments, String ticvar, boolean useRT) {

    final String satVar = "scan_acquisition_time";

    DefaultXYZDataset cd = new DefaultXYZDataset();
    int rowIdx = 0;
    double min = 0;
    double max = 1;
    double minRT = Double.POSITIVE_INFINITY;
    double maxRT = Double.NEGATIVE_INFINITY;

    int y = 0;
    for (IFileFragment f : fragments) {

        double[] domainValues = null;
        if (useRT) {
            domainValues = (double[]) f.getChild(satVar).getArray().get1DJavaArray(double.class);
        } else {
            domainValues = (double[]) f.getChild("scan_index").getArray().get1DJavaArray(double.class);
        }

        double[] tic = (double[]) f.getChild(ticvar).getArray().get1DJavaArray(double.class);
        double maxtic = MathTools.max(tic);
        double mintic = MathTools.min(tic);
        double[][] values = new double[3][tic.length];
        for (int i = 0; i < tic.length; i++) {
            values[0][i] = domainValues[i];
            values[1][i] = y;
            values[2][i] = Math.sqrt((tic[i] - mintic) / (maxtic - mintic));
        }

        y++;
        cd.addSeries(f.getName(), values);
    }

    // ArrayDouble.D1 a = new ArrayDouble.D1(npoints);
    // int offset = 0;
    // for (IFileFragment f : t) {
    // Array tic = f.getChild(ticvar).getArray();
    // int len = tic.getShape()[0];
    // Array.arraycopy(tic, 0, a, offset, len);
    // offset += len;
    // }
    // histogram with fixed binsize
    // fill intensities into adequate bin, raise count in bin by one
    // afterwards, relative frequency within a bin gives a normalization
    // coefficient
    XYBlockRenderer xyb = new XYBlockRenderer();
    GradientPaintScale ps = new GradientPaintScale(ImageTools.createSampleTable(256), min, max,
            ImageTools.rampToColorArray(new ColorRampReader().readColorRamp("res/colorRamps/bcgyr.csv")));

    xyb.setPaintScale(ps);
    final String[] colnames = new String[fragments.size()];
    for (int i = 0; i < colnames.length; i++) {
        colnames[i] = StringTools.removeFileExt(fragments.get(i).getName());
    }
    NumberAxis na = null;
    if (useRT) {
        na = new NumberAxis("time [s]");
        na.setAutoRangeIncludesZero(false);
        na.setLowerMargin(0);
        na.setUpperMargin(0);
    } else {
        na = new NumberAxis("scan index");
    }
    // na.setVerticalTickLabels(true);
    XYPlot xyp = new XYPlot(cd, na, new SymbolAxis("chromatogram", colnames), xyb);
    xyb.setBlockWidth(1);
    xyp.setBackgroundPaint(Color.BLACK);
    xyb.setBaseToolTipGenerator(new XYZToolTipGenerator() {
        @Override
        public String generateToolTip(XYZDataset xyzd, int i, int i1) {
            return colnames[xyzd.getY(i, i1).intValue()] + " @" + xyzd.getXValue(i, i1) + " = "
                    + xyzd.getZValue(i, i1);
        }

        @Override
        public String generateToolTip(XYDataset xyd, int i, int i1) {
            if (xyd instanceof XYZDataset) {
                return generateToolTip((XYZDataset) xyd, i, i1);
            }
            return colnames[xyd.getY(i, i1).intValue()] + ":" + xyd.getXValue(i, i1);
        }
    });
    return xyp;
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.XYCharts.SimpleBlockChart.java

public DatasetMap calculateValue() throws Exception {
    logger.debug("IN");
    String res = DataSetAccessFunctions.getDataSetResultFromId(profile, getData(), parametersObject);

    SourceBean sbRows = SourceBean.fromXMLString(res);
    List listAtts = sbRows.getAttributeAsList("ROW");

    DefaultXYZDataset dataset = new DefaultXYZDataset();
    int length = listAtts != null ? listAtts.size() : 0;

    double[] xvalues = new double[length];
    double[] yvalues = new double[length];
    double[] zvalues = new double[length];

    double[][] data = new double[][] { xvalues, yvalues, zvalues };

    double xVal = 0;
    double yVal = 0;
    double zVal = 0;

    boolean first = true;
    int cont = 0;

    for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) {
        SourceBean category = (SourceBean) iterator.next();
        List atts = category.getContainedAttributes();

        String nameP = "";
        String value = "";
        xVal = 0;//from w  ww. ja  va2  s .c o m
        yVal = 0;
        zVal = 0;
        for (Iterator iterator2 = atts.iterator(); iterator2.hasNext();) {
            SourceBeanAttribute object = (SourceBeanAttribute) iterator2.next();

            nameP = new String(object.getKey());
            value = new String((String) object.getValue());
            if (nameP.equalsIgnoreCase("x")) {
                xVal = new Double(value).doubleValue();
                xvalues[cont] = xVal;
            }
            if (nameP.equalsIgnoreCase("y")) {
                yVal = new Double(value).doubleValue();
                yvalues[cont] = yVal;
            }
            if (nameP.equalsIgnoreCase("z")) {
                zVal = new Double(value).doubleValue();
                zvalues[cont] = zVal;

                if (minScaleValue == null)
                    minScaleValue = zVal;
                if (maxScaleValue == null)
                    maxScaleValue = zVal;
                if (zVal < minScaleValue) {
                    minScaleValue = zVal;
                }
                if (zVal > maxScaleValue) {
                    maxScaleValue = zVal;
                }
            }
        }
        cont++;
    }

    dataset.addSeries("Series 1", data);

    //XYZDataset dataset = createDataset();

    DatasetMap datasets = new DatasetMap();
    datasets.addDataset("1", dataset);
    logger.debug("OUT");
    return datasets;
}