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

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

Introduction

In this page you can find the example usage for org.jfree.data.xy DefaultXYDataset 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.DefaultXYDatasetTest.java

/**
 * Serialize an instance, restore it, and check for equality.
 *///from  w  w  w .  ja v  a2s .c om
public void testSerialization() {

    DefaultXYDataset d1 = new DefaultXYDataset();
    DefaultXYDataset 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 = (DefaultXYDataset) 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[][] data1 = new double[][] { x1, y1 };
    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 = (DefaultXYDataset) in.readObject();
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    assertEquals(d1, d2);

}

From source file:com.bt.aloha.sipstone.GenGraph.java

private XYDataset[] createDataset_TotalCallCreated_CallsPerSecond() {
    DefaultXYDataset dataSet = new DefaultXYDataset();
    DefaultXYDataset percDataSet = new DefaultXYDataset();
    final String CPS = "CPS";
    List<Double> calls = data.get("TotalCallCreated");
    List<Double> callRate = data.get("CallRate(P)");
    List<Double> succCall = data.get("SuccessfulCall(P)");
    List<Double> failedCall = data.get("FailedCall(P)");
    double[] callsArray = new double[calls.size()];
    double[] callRateArray = new double[calls.size()];
    double[] percSuccessfullArray = new double[calls.size()];
    for (int i = 0; i < calls.size(); i++) {
        callsArray[i] = calls.get(i).doubleValue();
        callRateArray[i] = callRate.get(i).doubleValue();
        percSuccessfullArray[i] = (100 * succCall.get(i)) / (succCall.get(i) + failedCall.get(i));
    }/*from   w w  w.  ja  v a 2  s  .com*/
    dataSet.addSeries(CPS, new double[][] { callsArray, callRateArray });
    percDataSet.addSeries("%", new double[][] { callsArray, percSuccessfullArray });
    return new XYDataset[] { dataSet, percDataSet };
}

From source file:org.limy.eclipse.qalab.task.DistanceGraphTask.java

/**
 * @param root/*from  ww  w .  jav a 2  s  . c  o m*/
 * @return 
 * @throws TransformerException 
 */
private DefaultXYDataset createDataset(Element root) throws TransformerException {

    DefaultXYDataset dataset = new DefaultXYDataset();
    List<Point2D> points = new ArrayList<Point2D>();

    Iterable<Node> nodes = XmlXpathUtils.getNodeList(root, "/JDepend/Packages/Package");
    for (Node node : nodes) {
        if (XPathAPI.selectSingleNode(node, "Stats") == null) {
            continue;
        }
        double i = Double
                .parseDouble(XPathAPI.selectSingleNode(node, "Stats/I").getFirstChild().getNodeValue());
        double a = Double
                .parseDouble(XPathAPI.selectSingleNode(node, "Stats/A").getFirstChild().getNodeValue());

        log("I = " + i + ", A = " + a);
        points.add(new Point2D.Double(i, a));
    }

    double[][] values = new double[2][points.size()];
    for (int i = 0; i < points.size(); i++) {
        values[0][i] = points.get(i).getX();
        values[1][i] = points.get(i).getY();
    }
    dataset.addSeries("key", values);

    return dataset;
}

From source file:cish.CISH.java

/**
 * Draws the global / local ratio plot in this Plugin window.
 *//*from   w w  w .  jav a2s .c  o m*/
void drawRatioPlot() {
    //Set the chartpanel
    DefaultXYDataset dataset = new DefaultXYDataset();
    if (lRatios != null) {
        for (int i = 0; i < lRatios.length; i++) {
            if (gRatios[i] != Double.POSITIVE_INFINITY && lRatios[i] != Double.POSITIVE_INFINITY) {
                dataset.addSeries(tss.get(i).getName(),
                        new double[][] { new double[] { gRatios[i] }, new double[] { lRatios[i] } });
            }
        }
    }

    JFreeChart chart = ChartFactory.createScatterPlot("CISH Ratio", "Global Ratio", "Local Ratio", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    //chart.getXYPlot().getDomainAxis().setRange(0, 1);
    //chart.getXYPlot().getRangeAxis().setRange(0, 1);
    chart.setBackgroundPaint(null);
    chart.getPlot().setBackgroundPaint(null);
    ChartPanel chartPanel = new ChartPanel(chart);
    setPrecisionRecallPlot(chartPanel);
}

From source file:com.bt.aloha.sipstone.GenGraph.java

private XYDataset[] createDataset_CallsPerSecond_AvgResponseTime() {
    DefaultXYDataset dataSet = new DefaultXYDataset();
    DefaultXYDataset percDataSet = new DefaultXYDataset();
    final String CPS = "CPS";
    List<Double> respTime = data.get("ResponseTime1(P)");
    List<Double> callRate = data.get("CallRate(P)");
    List<Double> succCall = data.get("SuccessfulCall(P)");
    List<Double> failedCall = data.get("FailedCall(P)");
    double[] respTimeArray = new double[respTime.size()];
    double[] callRateArray = new double[respTime.size()];
    double[] percSuccessfullArray = new double[respTime.size()];
    for (int i = 0; i < respTime.size(); i++) {
        respTimeArray[i] = respTime.get(i).doubleValue();
        callRateArray[i] = callRate.get(i).doubleValue();
        percSuccessfullArray[i] = (100 * succCall.get(i)) / (succCall.get(i) + failedCall.get(i));
    }//from   www  .  j ava2 s.c o m
    dataSet.addSeries(CPS, new double[][] { callRateArray, respTimeArray });
    percDataSet.addSeries("%", new double[][] { callRateArray, percSuccessfullArray });

    double[] limitArray = new double[2];
    limitArray[0] = 200;
    limitArray[1] = 200;
    double[] callsLimitArray = new double[2];
    callsLimitArray[0] = callRateArray[0];
    callsLimitArray[1] = callRateArray[callRateArray.length - 1];

    return new XYDataset[] { dataSet, percDataSet };
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a residue plot.//from  w w  w .ja  v  a  2  s.c o m
 * 
 * @param yValues
 * @param header
 * @param xAxis
 * @param yAxis
 * @param seriesNames
 * @return
 */
public JFreeChart createResiduePlot(List<Double[]> yValues, String header, String xAxis, String yAxis,
        List<String> seriesNames) {
    LinkedList<XYLineAnnotation> lines = new LinkedList<XYLineAnnotation>();
    DefaultXYDataset xyDataSet = new DefaultXYDataset();
    for (int j = 0; j < yValues.size(); j++) {
        XYSeries series = new XYSeries(seriesNames.get(j));
        for (int i = 0; i < yValues.get(j).length; i++) {
            series.add(i + 1, yValues.get(j)[i]);
            float dash[] = { 10.0f };
            BasicStroke stroke = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f,
                    dash, 0.0f);
            XYLineAnnotation annotation = new XYLineAnnotation(i + 1, 0, i + 1, yValues.get(j)[i], stroke,
                    Color.BLUE);
            lines.add(annotation);
        }
        xyDataSet.addSeries(seriesNames.get(j), series.toArray());
    }
    JFreeChart chart = ChartFactory.createScatterPlot(header, xAxis, yAxis, xyDataSet, PlotOrientation.VERTICAL,
            true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setNoDataMessage("NO DATA");
    plot.setDomainZeroBaselineVisible(true);
    plot.setRangeZeroBaselineVisible(true);
    for (int i = 0; i < lines.size(); i++) {
        plot.addAnnotation(lines.get(i));
    }
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.black);
    renderer.setUseOutlinePaint(true);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setTickMarkInsideLength(2.0f);
    domainAxis.setTickMarkOutsideLength(0.0f);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setTickMarkInsideLength(2.0f);
    rangeAxis.setTickMarkOutsideLength(0.0f);

    return chart;
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotDataSet(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape)
        throws ConvertException {
    double[][] points = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY);
    String legend = shortLegend.get(id);
    Color color = colors.get(id);
    Shape shape = shapes.get(id);

    if (addInfoInLegend) {
        legend = longLegend.get(id);/*from   ww w  .  j av a2  s . co  m*/
    }

    if (color == null) {
        color = defaultColor;
    }

    if (shape == null) {
        shape = defaultShape;
    }

    if (points != null) {
        DefaultXYDataset dataset = new DefaultXYDataset();
        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(drawLines, true);

        dataset.addSeries(legend, points);
        renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        renderer.setSeriesPaint(0, color);
        renderer.setSeriesShape(0, shape);

        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        plot.setDataset(i, dataset);
        plot.setRenderer(i, renderer);
    }
}

From source file:delphsim.model.Resultado.java

/**
 * Mtodo para construir una grfica de tipo <CODE>JFreeChart</CODE> con
 * los valores de este resultado y sus funciones y obtener como resultado
 * el panel de tipo <CODE>ChartPanel</CODE> que la contiene.
 * @return Un panel <CODE>ChartPanel</CODE> con la nueva grfica.
 *//*from w  w  w  . j  a v a2s  .  c om*/
public ChartPanel construirPanelResultado() {
    DefaultXYDataset data = new DefaultXYDataset();
    for (int i = 0; i < this.getNumFunciones(); i++) {
        String nombre = this.funciones[i].getNombre();
        double[][] puntos = new double[2][this.puntosTiempo.size()];
        for (int j = 0; j < this.puntosTiempo.size(); j++) {
            puntos[0][j] = Double.valueOf(this.puntosTiempo.get(j).toString());
            puntos[1][j] = this.funciones[i].getPunto(j);
        }
        data.addSeries(nombre, puntos);
    }
    JFreeChart chart = ChartFactory.createXYLineChart(this.getTitulo(), // ttulo laaargo
            this.getXLabel(), // xLabel
            this.getYLabel(), // yLabel
            data, // datos
            PlotOrientation.VERTICAL, true, // legenda
            true, // tooltips
            false // URLs
    );
    for (int i = 0; i < this.getNumFunciones(); i++) {
        chart.getXYPlot().getRenderer().setSeriesStroke(i, new BasicStroke(this.funciones[i].getGrosor()));
        chart.getXYPlot().getRenderer().setSeriesPaint(i, this.funciones[i].getColor());
    }
    ChartPanel panel = new ChartPanel(chart, // grfica
            true, // propiedades
            false, // guardar
            false, // imprimir
            true, // zoom
            true // tooltips
    );
    this.grafica = chart;
    return panel;
}

From source file:de.bund.bfr.knime.pmmlite.views.chart.ChartCreator.java

private List<XYDataset> createStrictDataSets(Plotable plotable, String id) throws UnitException {
    List<XYDataset> dataSets = new ArrayList<>();

    for (Map<String, Integer> choiceMap : plotable.getAllChoices(varX.getName())) {
        double[][] dataPoints = plotable.getPoints(varX, varY, choiceMap);

        if (dataPoints == null) {
            dataSets.add(null);// ww  w  .  ja v  a 2 s  . com
            continue;
        }

        DefaultXYDataset dataSet = new DefaultXYDataset();
        StringBuilder addLegend = new StringBuilder();

        for (Map.Entry<String, Integer> entry : choiceMap.entrySet()) {
            if (!entry.getKey().equals(varX.getName())) {
                Double value = plotable.getVariables().get(entry.getKey()).get(entry.getValue());

                if (value != null) {
                    String s = NumberFormat.getInstance(Locale.US).format(value);

                    addLegend.append(" (" + entry.getKey() + "=" + s + ")");
                }
            }
        }

        dataSet.addSeries(legend.get(id) + addLegend, dataPoints);
        dataSets.add(dataSet);
    }

    return dataSets;
}

From source file:de.bund.bfr.knime.pmm.common.chart.ChartCreator.java

private void plotBoth(XYPlot plot, Plotable plotable, String id, Color defaultColor, Shape defaultShape,
        double minX, double maxX) throws ConvertException {
    double[][] modelPoints = plotable.getFunctionPoints(paramX, paramY, unitX, unitY, transformX, transformY,
            minX, maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    double[][] dataPoints = plotable.getPoints(paramX, paramY, unitX, unitY, transformX, transformY);
    double[][] functionErrors = null;
    String legend = shortLegend.get(id);
    Color color = colors.get(id);
    Shape shape = shapes.get(id);

    if (showConfidenceInterval) {
        functionErrors = plotable.getFunctionErrors(paramX, paramY, unitX, unitY, transformX, transformY, minX,
                maxX, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY);
    }// w  w  w  .  j ava  2  s  .c o  m

    if (addInfoInLegend) {
        legend = longLegend.get(id);
    }

    if (color == null) {
        color = defaultColor;
    }

    if (shape == null) {
        shape = defaultShape;
    }

    if (modelPoints != null) {
        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        if (functionErrors != null) {
            YIntervalSeriesCollection functionDataset = new YIntervalSeriesCollection();
            DeviationRenderer functionRenderer = new DeviationRenderer(true, false);
            YIntervalSeries series = new YIntervalSeries(legend);

            for (int j = 0; j < modelPoints[0].length; j++) {
                double error = Double.isNaN(functionErrors[1][j]) ? 0.0 : functionErrors[1][j];

                series.add(modelPoints[0][j], modelPoints[1][j], modelPoints[1][j] - error,
                        modelPoints[1][j] + error);
            }

            functionDataset.addSeries(series);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesFillPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            if (dataPoints != null) {
                functionRenderer.setBaseSeriesVisibleInLegend(false);
            }

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        } else {
            DefaultXYDataset functionDataset = new DefaultXYDataset();
            XYLineAndShapeRenderer functionRenderer = new XYLineAndShapeRenderer(true, false);

            functionDataset.addSeries(legend, modelPoints);
            functionRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
            functionRenderer.setSeriesPaint(0, color);
            functionRenderer.setSeriesShape(0, shape);

            if (dataPoints != null) {
                functionRenderer.setBaseSeriesVisibleInLegend(false);
            }

            plot.setDataset(i, functionDataset);
            plot.setRenderer(i, functionRenderer);
        }
    }

    if (dataPoints != null) {
        DefaultXYDataset dataSet = new DefaultXYDataset();
        XYLineAndShapeRenderer dataRenderer = new XYLineAndShapeRenderer(drawLines, true);

        dataSet.addSeries(legend, dataPoints);
        dataRenderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
        dataRenderer.setSeriesPaint(0, color);
        dataRenderer.setSeriesShape(0, shape);

        int i;

        if (plot.getDataset(0) == null) {
            i = 0;
        } else {
            i = plot.getDatasetCount();
        }

        plot.setDataset(i, dataSet);
        plot.setRenderer(i, dataRenderer);
    }
}