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

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

Introduction

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

Prototype

public DefaultXYZDataset() 

Source Link

Document

Creates a new DefaultXYZDataset instance, initially containing no data.

Usage

From source file:maltcms.ui.fileHandles.csv.CSV2JFCLoader.java

@Override
public void run() {
    CSV2TableLoader tl = new CSV2TableLoader(this.ph, this.is);

    DefaultTableModel dtm;/*from   w  ww  . j  a  v  a  2 s .  c om*/
    try {
        dtm = tl.call();
        if (this.mode == CHART.XY) {
            XYSeriesCollection cd = new XYSeriesCollection();
            for (int j = 0; j < dtm.getColumnCount(); j++) {
                XYSeries xys = new XYSeries(dtm.getColumnName(j));
                for (int i = 0; i < dtm.getRowCount(); i++) {
                    Object o = dtm.getValueAt(i, j);
                    try {
                        double d = Double.parseDouble(o.toString());
                        xys.add(i, d);
                        Logger.getLogger(getClass().getName()).log(Level.INFO, "Adding {0} {1} {2}",
                                new Object[] { i, d, dtm.getColumnName(j) });
                    } catch (Exception e) {
                    }
                }
                cd.addSeries(xys);
            }
            XYLineAndShapeRenderer d = new XYLineAndShapeRenderer(true, false);
            XYPlot xyp = new XYPlot(cd, new NumberAxis("category"), new NumberAxis("value"), d);

            JFreeChart jfc = new JFreeChart(this.title, xyp);
            jtc.setChart(jfc);
            Logger.getLogger(getClass().getName()).info("creating chart done");
        } else if (this.mode == CHART.MATRIX) {
            DefaultXYZDataset cd = new DefaultXYZDataset();
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Name of column 0: {0}",
                    dtm.getColumnName(0));
            if (dtm.getColumnName(0).isEmpty()) {
                Logger.getLogger(getClass().getName()).info("Removing column 0");
                dtm = removeColumn(dtm, 0);
            }
            if (dtm.getColumnName(dtm.getColumnCount() - 1).equalsIgnoreCase("filename")) {
                dtm = removeColumn(dtm, dtm.getColumnCount() - 1);
            }
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {
                    sb.append(dtm.getValueAt(i, j) + " ");
                }
                sb.append("\n");
            }
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Table before sorting: {0}", sb.toString());
            //                dtm = sort(dtm);
            StringBuilder sb2 = new StringBuilder();
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {
                    sb2.append(dtm.getValueAt(i, j) + " ");
                }
                sb2.append("\n");
            }
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Table after sorting: {0}", sb2.toString());
            int rows = dtm.getRowCount();
            int columns = dtm.getColumnCount();
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Storing {0} * {1} elements, {2} total!",
                    new Object[] { columns, rows, rows * columns });
            double[][] data = new double[3][(columns * rows)];
            ArrayDouble.D1 dt = new ArrayDouble.D1((columns) * rows);
            double min = Double.POSITIVE_INFINITY;
            double max = Double.NEGATIVE_INFINITY;
            EvalTools.eqI(rows, columns, this);
            int k = 0;
            for (int i = 0; i < dtm.getRowCount(); i++) {
                for (int j = 0; j < dtm.getColumnCount(); j++) {

                    Object o = dtm.getValueAt(i, j);
                    try {
                        double d = Double.parseDouble(o.toString());
                        if (d < min) {
                            min = d;
                        }
                        if (d > max) {
                            max = d;
                        }
                        data[0][k] = (double) i;
                        data[1][k] = (double) j;
                        data[2][k] = d;
                        dt.set(k, d);
                        k++;
                        //System.out.println("Adding "+i+" "+d+" "+dtm.getColumnName(j));
                    } catch (Exception e) {
                    }
                }
                //cd.addSeries(xys);
            }
            cd.addSeries(this.title, data);
            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[dtm.getColumnCount()];
            for (int i = 0; i < colnames.length; i++) {
                colnames[i] = dtm.getColumnName(i);
            }
            NumberAxis na1 = new SymbolAxis("category", colnames);
            na1.setVerticalTickLabels(false);
            NumberAxis na2 = new SymbolAxis("category", colnames);
            na1.setVerticalTickLabels(true);
            XYPlot xyp = new XYPlot(cd, na1, na2, xyb);
            xyb.setSeriesToolTipGenerator(0, new XYToolTipGenerator() {

                @Override
                public String generateToolTip(XYDataset xyd, int i, int i1) {
                    return "[" + colnames[xyd.getX(i, i1).intValue()] + ":"
                            + colnames[xyd.getY(i, i1).intValue()] + "] = "
                            + ((XYZDataset) xyd).getZValue(i, i1) + "";
                }
            });

            JFreeChart jfc = new JFreeChart(this.title, xyp);
            NumberAxis values = new NumberAxis("value");
            values.setAutoRange(false);
            values.setRangeWithMargins(min, max);
            PaintScaleLegend psl = new PaintScaleLegend(ps, values);
            psl.setBackgroundPaint(jfc.getBackgroundPaint());
            jfc.addSubtitle(psl);
            psl.setStripWidth(50);
            psl.setPadding(20, 20, 20, 20);
            psl.setHeight(200);
            psl.setPosition(RectangleEdge.RIGHT);
            jtc.setChart(jfc);
        }
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }

    ph.finish();
}

From source file:com.rapidminer.gui.plotter.charts.BubbleChartPlotter.java

private void prepareNumericalData() {
    DataTable dataTable = getDataTable();
    this.nominal = false;
    xyzDataSet = new DefaultXYZDataset();

    if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0 && axis[BUBBLE_SIZE_AXIS] >= 0) {

        this.bubbleSizeMin = Double.POSITIVE_INFINITY;
        this.bubbleSizeMax = Double.NEGATIVE_INFINITY;
        this.xAxisMin = Double.POSITIVE_INFINITY;
        this.xAxisMax = Double.NEGATIVE_INFINITY;
        this.yAxisMin = Double.POSITIVE_INFINITY;
        this.yAxisMax = Double.NEGATIVE_INFINITY;
        this.minColor = Double.POSITIVE_INFINITY;
        this.maxColor = Double.NEGATIVE_INFINITY;

        List<double[]> dataList = new LinkedList<>();
        synchronized (dataTable) {
            Iterator<DataTableRow> i = dataTable.iterator();
            while (i.hasNext()) {
                DataTableRow row = i.next();

                double xValue = row.getValue(axis[X_AXIS]);
                double yValue = row.getValue(axis[Y_AXIS]);
                double bubbleSizeValue = row.getValue(axis[BUBBLE_SIZE_AXIS]);

                double colorValue = Double.NaN;
                if (colorColumn >= 0) {
                    colorValue = row.getValue(colorColumn);
                }//from   w ww  .ja va2 s  . c  o  m

                if (!Double.isNaN(xValue) && !Double.isNaN(yValue) && !Double.isNaN(bubbleSizeValue)) {
                    double[] data = new double[4];
                    data[X_AXIS] = xValue;
                    data[Y_AXIS] = yValue;
                    data[BUBBLE_SIZE_AXIS] = bubbleSizeValue;
                    data[3] = colorValue;

                    this.bubbleSizeMin = MathFunctions.robustMin(this.bubbleSizeMin, bubbleSizeValue);
                    this.bubbleSizeMax = MathFunctions.robustMax(this.bubbleSizeMax, bubbleSizeValue);
                    this.xAxisMin = MathFunctions.robustMin(this.xAxisMin, xValue);
                    this.yAxisMin = MathFunctions.robustMin(this.yAxisMin, yValue);
                    this.xAxisMax = MathFunctions.robustMax(this.xAxisMax, xValue);
                    this.yAxisMax = MathFunctions.robustMax(this.yAxisMax, yValue);
                    this.minColor = MathFunctions.robustMin(this.minColor, colorValue);
                    this.maxColor = MathFunctions.robustMax(this.maxColor, colorValue);

                    dataList.add(data);
                }
            }
        }

        double[][] data = new double[3][dataList.size()];
        this.colors = new double[dataList.size()];

        int index = 0;
        double scaleFactor = Math.min(this.xAxisMax - this.xAxisMin, this.yAxisMax - this.yAxisMin) / 4.0d;
        for (double[] d : dataList) {
            data[X_AXIS][index] = d[X_AXIS];
            data[Y_AXIS][index] = d[Y_AXIS];
            data[BUBBLE_SIZE_AXIS][index] = ((d[BUBBLE_SIZE_AXIS] - bubbleSizeMin)
                    / (bubbleSizeMax - bubbleSizeMin) + 0.1) * scaleFactor;
            this.colors[index] = d[3];
            index++;
        }

        xyzDataSet.addSeries("All", data);
    }
}

From source file:it.eng.spagobi.engines.chart.bo.charttypes.blockcharts.TimeBlockChart.java

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

    ArrayList<Activity> activities = new ArrayList<Activity>();

    RegularTimePeriod timePeriod = null;

    SourceBean sbRows = SourceBean.fromXMLString(res);
    List listAtts = sbRows.getAttributeAsList("ROW");
    // Run all rows
    if (listAtts == null) {
        logger.error("Null rows retrieved from dataset");
        return null;
    }//ww w . j  av a 2  s  .  c  o m
    int j = 0;
    // for each activity
    logger.debug("retrieved number rows: " + listAtts.size());
    for (Iterator iterator = listAtts.iterator(); iterator.hasNext();) {
        SourceBean row = (SourceBean) iterator.next();
        Activity activity = new Activity(row, beginDateFormat, beginHourFormat);
        activities.add(activity);
        logger.debug(
                "Activity built from " + activity.getBeginDate() + " minutes" + activity.getMinutes() != null
                        ? activity.getMinutes().toString()
                        : "");
        if (maxDateFound != null && !activity.getBeginDate().after(maxDateFound)) {
        } else {
            maxDateFound = activity.getBeginDate();
        }

        if (minDateFound != null && !activity.getBeginDate().before(minDateFound)) {
        } else {
            minDateFound = activity.getBeginDate();
        }
    }

    //      count days
    long daysBetween;
    if (dateMin != null && dateMax != null) {
        logger.debug(
                "use date limit defined in template: from " + dateMin.toString() + " to " + dateMax.toString());
        daysBetween = daysBetween(dateMin, dateMax);
    } else {
        logger.debug(
                "use date limit found: from " + minDateFound.toString() + " to " + maxDateFound.toString());
        daysBetween = daysBetween(minDateFound, maxDateFound);
    }
    logger.debug("Days between the two dates " + daysBetween);
    // add a date to include extremis
    long minutesBetweenLong = daysBetween * 24 * 60 * 2; // raddoppio in caso di sovrapposizioni
    int mbl = Long.valueOf(minutesBetweenLong).intValue();

    DefaultXYZDataset dataset = new DefaultXYZDataset();

    ArrayList<Long> xValuesList = new ArrayList<Long>();
    ArrayList<Double> yValuesList = new ArrayList<Double>();
    ArrayList<Double> zValuesList = new ArrayList<Double>();

    annotations = new HashMap<String, AnnotationBlock>();
    // run all the activities
    for (Iterator iterator = activities.iterator(); iterator.hasNext();) {
        Activity activity = (Activity) iterator.next();

        // insert only if activty falls inside the min and max Range (idf defined)
        if (dateMin != null && dateMax != null
                && (activity.getBeginDate().after(dateMax) || activity.getBeginDate().before(dateMin))) {
            logger.debug(
                    "Activity discarde because starting out of selected bounds in " + activity.getBeginDate());
        } else {
            logger.debug("Inserting activity with begin date " + activity.getBeginDate() + " adn pattern "
                    + activity.getPattern());
            RegularTimePeriod rtp = new Day(activity.getBeginDate());
            long secondmills = rtp.getFirstMillisecond();

            Minute minute = activity.getMinutes();
            for (int i = 0; i < activity.getDuration(); i++) {
                // convert from hour to number axis (da sessantesimi a centesimi!)
                Integer hour = Integer.valueOf(minute.getHourValue());
                Integer minuteValue = Integer.valueOf(minute.getMinute());
                Double doubleMinuteValue = Double.valueOf(((double) minuteValue.intValue()));
                // minuteValue : 60 = x :100
                double convertedMinuteValue = (doubleMinuteValue * 100) / 60.0;
                double convertedMinuteValueCent = convertedMinuteValue / 100;

                double hourD = (double) hour.intValue();
                double converted = hourD + convertedMinuteValueCent;

                String yVal = Double.valueOf(converted).toString();

                xValuesList.add(new Long(secondmills));
                yValuesList.add(Double.valueOf(yVal));

                Object cosa = patternRangeIndex.get(activity.getPattern());

                if (cosa != null) {
                    zValuesList.add(
                            Double.valueOf(patternRangeIndex.get(activity.getPattern())).doubleValue() + 0.5);
                } else {
                    zValuesList.add(-1.0);
                }
                //               xvalues[j]=secondmills;
                //               yvalues[j]=Double.valueOf(yVal);
                //               zvalues[j]=patternRangeIndex.get(activity.getPattern())+0.5;

                //System.out.println("Date: "+activity.getBeginDate()+":"+Double.valueOf(xvalues[j]).toString()+", Hour: "+Double.valueOf(yvalues[j]).toString()+", Value: "+Double.valueOf(zvalues[j]).toString());
                if (annotations.get(activity.getCode()) == null) {
                    AnnotationBlock annotation = new AnnotationBlock(activity.getCode());
                    annotation.setXPosition(xValuesList.get(j).doubleValue());
                    annotation.setYPosition(yValuesList.get(j).doubleValue());
                    annotations.put(annotation.getAnnotation(), annotation);
                }
                minute = (Minute) minute.next();
                j++;
            }
        }

    }
    //      create arrays
    double[] xvalues = new double[xValuesList.size()];
    double[] yvalues = new double[yValuesList.size()];
    double[] zvalues = new double[zValuesList.size()];

    for (int i = 0; i < zValuesList.size(); i++) {
        Long l = xValuesList.get(i);
        xvalues[i] = l;
        Double d2 = yValuesList.get(i);
        yvalues[i] = d2;
        Double d = zValuesList.get(i);
        zvalues[i] = d;
    }

    logger.debug("adding the serie");
    dataset.addSeries("Series 1", new double[][] { xvalues, yvalues, zvalues });

    datasetMap.getDatasets().put("1", dataset);
    logger.debug("OUT");
    return datasetMap;
}

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

/**
 * Some tests for the addSeries() method.
 *//*from   w  ww .j  a v  a 2s. co m*/
@Test
public void testAddSeries() {
    DefaultXYZDataset d = new DefaultXYZDataset();
    d.addSeries("S1", new double[][] { { 1.0 }, { 2.0 }, { 3.0 } });
    assertEquals(1, d.getSeriesCount());
    assertEquals("S1", d.getSeriesKey(0));

    // check that adding a series will overwrite the old series
    d.addSeries("S1", new double[][] { { 11.0 }, { 12.0 }, { 13.0 } });
    assertEquals(1, d.getSeriesCount());
    assertEquals(12.0, d.getYValue(0, 0), EPSILON);

    // check null key
    boolean pass = false;
    try {
        d.addSeries(null, new double[][] { { 1.0 }, { 2.0 }, { 3.0 } });
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:edu.ucla.stat.SOCR.chart.SuperXYZChart.java

/**
   * //from  w w w .  ja  v a 2s.c om
   * @param isDemo data come from demo(true) or dataTable(false)
   * @return
   */
protected XYZDataset createDataset(boolean isDemo) {
    if (isDemo) {
        XYZDataset dataset = new SampleXYZDataset();
        domainLabel = "X";
        rangeLabel = "Y";
        return dataset;

    } else {
        setXYZArray();
        int len = Array.getLength(x);

        /*   Object[] xData = new Object[len]; 
           Object[] yData = new Object[len]; 
           Object[] zData = new Object[len]; 
                
           for (int i=0; i<len; i++){
              xData[i]=new Double(x[i]);
              yData[i]=new Double(y[i]);
              zData[i]=new Double(z[i]);
           }
           // create the dataset... 
           DefaultContourDataset dataset = new DefaultContourDataset((Comparable)independentHeaders[0].substring(0,independentHeaders[0].indexOf(":")), xData, yData, zData); */

        double[][] data = new double[3][len];
        for (int i = 0; i < len; i++) {
            data[0][i] = x[i];
            data[1][i] = y[i];
            data[2][i] = z[i] * zShrinkPercent / 100;
        }
        DefaultXYZDataset dataset = new DefaultXYZDataset();
        String serieName = independentHeaders[0];
        if (independentHeaders[0].indexOf(":") != -1)
            serieName = independentHeaders[0].substring(0, independentHeaders[0].indexOf(":"));

        dataset.addSeries((Comparable) serieName, data);
        return dataset;
    }

}

From source file:org.hxzon.demo.jfreechart.OtherDatasetDemo.java

private static XYZDataset createXYZDataset() {
    //        DefaultXYZDataset dataset = new DefaultXYZDataset();
    //        //x1,x2,x3,y1,y2,y3,z1,z2,z3=>x1,x2,x3,y1,y2,y3,r1,r2,r3
    //        double[][] s1 = new double[][] { { 1, 2, 3 }, { 3, 4, 5 }, { 2, 2, 4 } };
    //        dataset.addSeries("series 1", s1);
    //        double[][] s2 = new double[][] { { 11, 12 }, { 13, 14 }, { 3, 3 } };
    //        dataset.addSeries("series 2", s2);
    //        return dataset;
    DefaultXYZDataset dataset = new DefaultXYZDataset();
    double ad[] = { 2.1000000000000001D, 2.2999999999999998D, 2.2999999999999998D, 2.2000000000000002D,
            2.2000000000000002D, 1.8D, 1.8D, 1.8999999999999999D, 2.2999999999999998D, 3.7999999999999998D };
    double ad1[] = { 14.1D, 11.1D, 10D, 8.8000000000000007D, 8.6999999999999993D, 8.4000000000000004D,
            5.4000000000000004D, 4.0999999999999996D, 4.0999999999999996D, 25D };
    double ad2[] = { 2.3999999999999999D, 2.7000000000000002D, 2.7000000000000002D, 2.2000000000000002D,
            2.2000000000000002D, 2.2000000000000002D, 2.1000000000000001D, 2.2000000000000002D,
            1.6000000000000001D, 4D };/*w w w  .  j a v a2  s  . c  o  m*/
    double ad3[][] = { ad, ad1, ad2 };
    dataset.addSeries("Series 1", ad3);
    return dataset;
}

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

/**
 * Creates a sample dataset for testing.
 *
 * @return A sample dataset.//  w  w  w  . jav  a2s.  c  om
 */
public DefaultXYZDataset createSampleDataset1() {
    DefaultXYZDataset d = new DefaultXYZDataset();
    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 };
    d.addSeries("S1", data1);

    double[] x2 = new double[] { 1.0, 2.0, 3.0 };
    double[] y2 = new double[] { 4.0, 5.0, 6.0 };
    double[] z2 = new double[] { 7.0, 8.0, 9.0 };
    double[][] data2 = new double[][] { x2, y2, z2 };
    d.addSeries("S2", data2);
    return d;
}

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

/**
 * Some tests for the addSeries() method.
 *//*from   w w w  .j av a  2 s.  c  o  m*/
public void testAddSeries() {
    DefaultXYZDataset d = new DefaultXYZDataset();
    d.addSeries("S1", new double[][] { { 1.0 }, { 2.0 }, { 3.0 } });
    assertEquals(1, d.getSeriesCount());
    assertEquals("S1", d.getSeriesKey(0));

    // check that adding a series will overwrite the old series
    d.addSeries("S1", new double[][] { { 11.0 }, { 12.0 }, { 13.0 } });
    assertEquals(1, d.getSeriesCount());
    assertEquals(12.0, d.getYValue(0, 0), EPSILON);

    // check null key
    boolean pass = false;
    try {
        d.addSeries(null, new double[][] { { 1.0 }, { 2.0 }, { 3.0 } });
    } catch (IllegalArgumentException e) {
        pass = true;
    }
    assertTrue(pass);
}

From source file:com.rapidminer.gui.plotter.charts.Abstract2DChartPlotter.java

private void prepareNumericalData() {
    this.nominal = false;
    dataSet = new DefaultXYZDataset();

    if (axis[X_AXIS] >= 0 && axis[Y_AXIS] >= 0) {
        this.minColor = Double.POSITIVE_INFINITY;
        this.maxColor = Double.NEGATIVE_INFINITY;

        List<double[]> dataList = new LinkedList<double[]>();
        List<String> idList = new LinkedList<String>();
        synchronized (dataTable) {
            Iterator<DataTableRow> i = this.dataTable.iterator();
            while (i.hasNext()) {
                DataTableRow row = i.next();

                double xValue = Double.NaN;
                if (axis[X_AXIS] >= 0) {
                    xValue = row.getValue(axis[X_AXIS]);
                }//w w  w  .  j  a  v a2  s . c  o m

                double yValue = Double.NaN;
                if (axis[Y_AXIS] >= 0) {
                    yValue = row.getValue(axis[Y_AXIS]);
                }

                double colorValue = Double.NaN;
                if (colorColumn >= 0) {
                    colorValue = row.getValue(colorColumn);
                }

                if (plotColumnsLogScale) {
                    if (Tools.isLessEqual(colorValue, 0.0d)) {
                        colorValue = 0;
                    } else {
                        colorValue = Math.log10(colorValue);
                    }
                }

                // TM: removed check
                // if (!Double.isNaN(xValue) && !Double.isNaN(yValue)) {
                double[] data = new double[3];
                data[X_AXIS] = xValue;
                data[Y_AXIS] = yValue;
                data[COLOR_AXIS] = colorValue;

                if (!Double.isNaN(colorValue)) {
                    this.minColor = Math.min(this.minColor, colorValue);
                    this.maxColor = Math.max(this.maxColor, colorValue);
                }

                dataList.add(data);
                idList.add(row.getId());
                // }
            }
        }

        double[][] data = new double[3][dataList.size()];

        double minX = Double.POSITIVE_INFINITY;
        double maxX = Double.NEGATIVE_INFINITY;
        double minY = Double.POSITIVE_INFINITY;
        double maxY = Double.NEGATIVE_INFINITY;

        int index = 0;
        for (double[] d : dataList) {
            data[X_AXIS][index] = d[X_AXIS];
            data[Y_AXIS][index] = d[Y_AXIS];
            data[COLOR_AXIS][index] = d[COLOR_AXIS];

            minX = MathFunctions.robustMin(minX, d[X_AXIS]);
            maxX = MathFunctions.robustMax(maxX, d[X_AXIS]);
            minY = MathFunctions.robustMin(minY, d[Y_AXIS]);
            maxY = MathFunctions.robustMax(maxY, d[Y_AXIS]);

            index++;
        }

        // jittering
        if (this.jitterAmount > 0) {
            Random jitterRandom = new Random(2001);
            double oldXRange = maxX - minX;
            double oldYRange = maxY - minY;
            for (int i = 0; i < dataList.size(); i++) {
                if (Double.isInfinite(oldXRange) || Double.isNaN(oldXRange)) {
                    oldXRange = 0;
                }
                if (Double.isInfinite(oldYRange) || Double.isNaN(oldYRange)) {
                    oldYRange = 0;
                }
                double pertX = oldXRange * (jitterAmount / 200.0d) * jitterRandom.nextGaussian();
                double pertY = oldYRange * (jitterAmount / 200.0d) * jitterRandom.nextGaussian();
                data[X_AXIS][i] += pertX;
                data[Y_AXIS][i] += pertY;
            }
        }

        // add data
        ((DefaultXYZDataset) dataSet).addSeries("All", data);

        // id handling
        int idCounter = 0;
        for (String id : idList) {
            idMap.put(new SeriesAndItem(0, idCounter++), id);
        }
    }
}

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  ww w  . j a  va2s  .c om
        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;
}