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

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

Introduction

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

Prototype

public void addSeries(XYSeries series) 

Source Link

Document

Adds a series to the collection and sends a DatasetChangeEvent to all registered listeners.

Usage

From source file:org.spantus.exp.segment.draw.AbstractGraphGenerator.java

protected XYSeries newSeries(String name, XYSeriesCollection collection) {
    XYSeries series = new XYSeries(name);
    series.setDescription(name);//from  w w  w. jav  a2 s  .  c o  m
    collection.addSeries(series);
    return series;
}

From source file:no.ntnu.mmfplanner.ui.graph.SaNpvChart.java

private void updateModel() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYPlot plot = ((XYPlot) getChart().getPlot());
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();

    // the x=0 line
    XYSeries line = new XYSeries("");
    line.add(1.0, 0.0);//from  w w  w  .j a v a  2 s.c o m
    line.add(project.getPeriods(), 0.0);
    dataset.addSeries(line);

    // adds the line plot for each mmf
    int[][] saNpvValues = project.getSaNpvTable();
    for (int mmfI = 0; mmfI < saNpvValues.length; mmfI++) {
        Mmf mmf = project.get(mmfI);
        XYSeries values = new XYSeries(mmf.getId() + ": " + mmf.getName());

        for (int period = 1; period <= saNpvValues[mmfI].length; period++) {
            values.add(period, saNpvValues[mmfI][period - 1]);
        }

        dataset.addSeries(values);
        renderer.setSeriesShapesVisible(mmfI + 1, false);
        renderer.setSeriesStroke(mmfI + 1, SERIES_STROKE);
        renderer.setSeriesPaint(mmfI + 1, CHART_COLOR[mmfI % CHART_COLOR.length]);
    }

    plot.setDataset(dataset);
}

From source file:edu.fullerton.viewerplugin.PluginSupport.java

public static int scaleRange(XYSeriesCollection mtds, Double miny, Double maxy) {
    int exp = PluginSupport.getExp(miny, maxy);
    if (exp > 0 && exp < 100) {
        int nseries = mtds.getSeriesCount();
        XYSeries[] newSeries = new XYSeries[nseries];

        double scale = Math.pow(10, exp);
        for (int s = 0; s < nseries; s++) {
            XYSeries ds = (XYSeries) mtds.getSeries(s);
            Comparable skey = mtds.getSeriesKey(s);
            XYSeries nds = new XYSeries(skey, true);
            for (int item = 0; item < ds.getItemCount(); item++) {
                double x = ds.getX(item).doubleValue();
                double y = ds.getY(item).doubleValue();

                y *= scale;//from   w w w  .  j a v  a 2s.  c  om
                nds.add(x, y);
            }
            newSeries[s] = nds;
        }
        mtds.removeAllSeries();
        for (int s = 0; s < nseries; s++) {
            mtds.addSeries(newSeries[s]);
        }
    } else {
        exp = 0;
    }
    return exp;
}

From source file:telas.TelaGrafico.java

public void criaGrafico(ArrayList<Processo> listapronto) {
    JFreeChart chart = null;//from  w  ww .  ja v  a 2 s .co m

    XYSplineRenderer renderer = new XYSplineRenderer();
    XYSeriesCollection dataset = new XYSeriesCollection();

    ValueAxis x = new NumberAxis();
    ValueAxis y = new NumberAxis();

    XYSeries serie = new XYSeries("Processos");

    XYPlot plot;

    for (int fila = 0; fila < listapronto.size(); fila++) {

        serie.add(listapronto.get(fila).getTsurto(), listapronto.get(fila).getTespera());
    }
    dataset.addSeries(serie);
    x.setLabel("Processos");
    y.setLabel("Tempo de espera");
    plot = new XYPlot(dataset, x, y, renderer);

    chart = new JFreeChart(plot);
    chart.setTitle("Processos");

    ChartPanel myChartPanel = new ChartPanel(chart, true);
    myChartPanel.setSize(jPanel1.getWidth(), jPanel1.getHeight());
    myChartPanel.setVisible(true);
    jPanel1.removeAll();
    jPanel1.add(myChartPanel);
    jPanel1.revalidate();
    jPanel1.repaint();
}

From source file:org.agmip.ui.afsirs.frames.GraphOutput.java

public void addWeather() {
    int nyr = utils.getNYR();
    XYSeries etSeries = new XYSeries("ET");
    double[][] ET = utils.getET();
    for (int i = 0; i < 10/*ET.length*/; i++) {
        for (int j = 0; j < 10/*ET[0].length*/; j++) {
            etSeries.add(i * ET[0].length + j, ET[i][j]);
        }/*  w w  w . j  av a 2 s  . c  om*/
    }

    XYSeries rainSeries = new XYSeries("RAIN");
    double[][] RAIN = utils.getRain();
    for (int i = 0; i < 10/*RAIN.length*/; i++) {
        for (int j = 0; j < 10/*RAIN[0].length*/; j++) {
            rainSeries.add(i * RAIN[0].length + j, RAIN[i][j]);
        }
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(etSeries);
    dataset.addSeries(rainSeries);

    JFreeChart chart = ChartFactory.createXYLineChart("Weather Data", "Days", "Inches",
            dataset/*,
                   PlotOrientation.VERTICAL, true, true, false*/);
    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.GRAY);
    plot.setDomainGridlinePaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    ChartPanel panel = new ChartPanel(chart);
    jTabbedPane1.addTab("Weather", panel);

}

From source file:org.hsh.bfr.db.gui.dbtable.editoren.MyChartDialog.java

/**
 * Creates a sample dataset.//from   www . j  a  v a2 s .c  o  m
 * 
 * @return a sample dataset.
 */
private XYDataset createDataset() {

    series2.clear();
    Datenpunkte = "";
    for (int i = 0; i < table1.getModel().getRowCount(); i++) {
        Object o1 = table1.getModel().getValueAt(i, 0);
        Object o2 = table1.getModel().getValueAt(i, 1);
        if (o1 == null || o2 == null || o1.toString().trim().length() == 0
                || o2.toString().trim().length() == 0) {
            break;
        } else {
            String interval = o1.toString().trim();
            String function = o2.toString().trim();
            Datenpunkte += "\n" + interval + "\t" + function;
            Double tVal = getDouble(interval);
            Double val = getDouble(function);
            if (val != null && tVal != null)
                series2.add(tVal, val);
            else {
                try {
                    parseString(series2, function, interval); // z.B. sin(x)+2*cos(3*x)
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    if (Datenpunkte.length() > 0)
        Datenpunkte = Datenpunkte.substring(1);

    final XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series2);

    return dataset;

}

From source file:cachedataanalysis.FlowCache.java

public XYSeries exportReportChart() throws IOException {

    File outputHitRate = new File("report/" + name + "_" + policy + "_hitrate.txt");

    FileWriter fw = new FileWriter(outputHitRate);

    XYSeries hitRateCount = new XYSeries(name + "(" + size + " entries)");

    for (int i = 0; i < hitRateRecord.size(); i++) {
        hitRateCount.add(i, hitRateRecord.get(i));
        fw.write(i + "," + hitRateRecord.get(i) + "\n");
        fw.flush();//  w  ww  .j  a v a2s.c  o  m
    }
    fw.close();

    XYSeriesCollection HitRateData = new XYSeriesCollection();
    HitRateData.addSeries(hitRateCount);
    JFreeChart hitRateStat = ChartFactory.createXYLineChart(
            "Hit Rate variatoion throughout recording in " + name, "Seconds", "HitRate", HitRateData,
            PlotOrientation.VERTICAL, true, true, false);

    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitRate" + size + ".jpg"), hitRateStat, 1500,
            900);

    //-------------------------------

    if (!fullReport) {
        return hitRateCount;
    }

    DefaultPieDataset hitProtoData = new DefaultPieDataset();
    DefaultPieDataset missProtoData = new DefaultPieDataset();

    CategoryTableXYDataset hitProtoDataRec = new CategoryTableXYDataset();
    for (int i = 0; i < hitProtoRec.size(); i++) {
        if (i % 120 != 0) {
            continue;
        }
        HashMap<String, Integer> _map = hitProtoRec.get(i);
        for (String _str : _map.keySet()) {
            hitProtoDataRec.add(i, _map.get(_str), _str);
        }

    }

    CategoryTableXYDataset missProtoDataRec = new CategoryTableXYDataset();
    for (int i = 0; i < missProtoRec.size(); i++) {
        if (i % 120 != 0) {
            continue;
        }
        HashMap<String, Integer> _map = missProtoRec.get(i);
        for (String _str : _map.keySet()) {
            missProtoDataRec.add(i, _map.get(_str), _str);
        }

    }

    XYSeries hitCountData = new XYSeries("Hit");
    XYSeries allCountData = new XYSeries("All");

    for (int i = 0; i < hitCount.size(); i++) {
        hitCountData.add(i, hitCount.get(i));
        //hitRateCount.add(i,(float)hitCount.get(i)/(hitCount.get(i)+allCount.get(i)));
    }

    for (int i = 0; i < allCount.size(); i++) {
        allCountData.add(i, allCount.get(i));

    }

    XYSeriesCollection CountStatData = new XYSeriesCollection();

    CountStatData.addSeries(hitCountData);
    CountStatData.addSeries(allCountData);

    for (String protocol : hitProto.keySet()) {
        hitProtoData.setValue(protocol, hitProto.get(protocol));
    }

    for (String protocol : missProto.keySet()) {
        missProtoData.setValue(protocol, missProto.get(protocol));
    }

    JFreeChart hitStatRec = ChartFactory.createStackedXYAreaChart(
            "Hit Protocol Fraction throughout record in " + name, "Seconds", "Count", hitProtoDataRec);

    JFreeChart missStatRec = ChartFactory.createStackedXYAreaChart(
            "Miss Protocol Fraction throughout record in " + name, "Seconds", "Count", missProtoDataRec);

    JFreeChart hitStat = ChartFactory.createPieChart3D("Protocal Fraction of Hit Flows in " + name,
            hitProtoData, true, true, false);
    JFreeChart missStat = ChartFactory.createPieChart3D("Protocal Fraction of Miss Flows in " + name,
            missProtoData, true, true, false);
    JFreeChart countStat = ChartFactory.createXYAreaChart("Hit Count to All Packet lookup in " + name,
            "Seconds", "Count", CountStatData, PlotOrientation.VERTICAL, true, true, false);

    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitProto" + size + ".jpg"), hitStat, 1500,
            900);
    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_missProto" + size + ".jpg"), missStat, 1500,
            900);
    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitCount" + size + ".jpg"), countStat, 1500,
            900);

    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_hitProtoRecord" + size + ".jpg"), hitStatRec,
            1500, 900);
    ChartUtilities.saveChartAsJPEG(new File("report/" + name + "_missProtoRecord" + size + ".jpg"), missStatRec,
            1500, 900);

    return hitRateCount;
}

From source file:net.sf.jdmf.visualization.clustering.ChartGenerator.java

public JFreeChart generateXYChart(List<Cluster> clusters, Integer firstAttributeIndex,
        String firstAttributeName, Integer secondAttributeIndex, String secondAttributeName) {
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (Cluster cluster : clusters) {
        XYSeries series = new XYSeries(cluster.getName());

        for (Vector<Double> point : cluster.getPoints()) {
            series.add(point.get(firstAttributeIndex), point.get(secondAttributeIndex));
        }//from  www.j  a  v  a  2  s.c om

        dataset.addSeries(series);
    }

    XYToolTipGenerator xyToolTipGenerator = new XYToolTipGenerator() {
        public String generateToolTip(XYDataset dataset, int series, int item) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(String.format("<html><p style='color:#0000ff;'>Series: '%s'</p>",
                    dataset.getSeriesKey(series)));
            Cluster cl = clusters.get(series);
            Vector<Double> point = cl.getPoints().get(item);
            for (int i = 0; i < point.size(); i++) {
                //stringBuilder.append(String.format("Attr:'%d'<br/>", d));
                try {
                    String attr = _attrName.get(i);
                    stringBuilder.append(attr + " " + point.get(i) + "<br/>");
                } catch (Exception e) {
                    // Do nothing 
                }
            }
            stringBuilder.append("</html>");
            return stringBuilder.toString();
        }
    };

    /***
    return ChartFactory.createScatterPlot( "Cluster Analysis", 
    firstAttributeName, secondAttributeName, dataset, 
    PlotOrientation.VERTICAL, true, true, false );
    ***/
    JFreeChart jfc = ChartFactory.createScatterPlot("Cluster Analysis", firstAttributeName, secondAttributeName,
            dataset, PlotOrientation.VERTICAL, true, true, false);

    XYItemRenderer render = jfc.getXYPlot().getRenderer();
    render.setBaseToolTipGenerator(xyToolTipGenerator);
    return jfc;
}

From source file:com.choicemaker.cm.modelmaker.gui.panels.HoldVsAccuracyPlotPanel.java

private void buildPanel() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    String title = ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.title");
    data = new XYSeries(title);
    dataset.addSeries(data);
    final PlotOrientation orientation = PlotOrientation.VERTICAL;
    chart = ChartFactory.createXYLineChart(title,
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.cm.accuracy"),
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.holdpercentage"),
            dataset, orientation, true, true, true);
    MouseListener tableMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point origin = e.getPoint();
            JTable src = (JTable) e.getSource();
            int row = src.rowAtPoint(origin);
            int col = src.columnAtPoint(origin);
            ModelMaker mm = parent.getModelMaker();
            if (src == accuracyTable) {
                if (col < 2) {
                    if (!Float.isNaN(accuracyData[row][2]) && !Float.isNaN(accuracyData[row][3]))
                        mm.setThresholds(new Thresholds(accuracyData[row][2], accuracyData[row][3]));
                } else if (col == 2) {
                    if (!Float.isNaN(accuracyData[row][2]))
                        mm.setDifferThreshold(accuracyData[row][2]);
                } else {
                    if (!Float.isNaN(accuracyData[row][3]))
                        mm.setMatchThreshold(accuracyData[row][3]);
                }/*from   w  w w .ja  va  2s  .co m*/
            } else {
                if (col < 2) {
                    if (!Float.isNaN(hrData[row][2]) && !Float.isNaN(hrData[row][3]))
                        mm.setThresholds(new Thresholds(hrData[row][2], hrData[row][3]));
                } else if (col == 2) {
                    if (!Float.isNaN(hrData[row][2]))
                        mm.setDifferThreshold(hrData[row][2]);
                } else {
                    if (!Float.isNaN(hrData[row][3]))
                        mm.setMatchThreshold(hrData[row][3]);
                }
            }
        }
    };
    chart.setBackgroundPaint(getBackground());
    accuracyTable = new AccuracyTable(true, accuracies);
    accuracyTable.addMouseListener(tableMouseListener);
    accuracyPanel = getPanel(accuracyTable,
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.table.hrvsacc"));

    hrTable = new AccuracyTable(false, hrs);
    hrTable.addMouseListener(tableMouseListener);
    hrPanel = getPanel(hrTable,
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.table.accvshr"));

    accuracyTable.setEnabled(false);
    hrTable.setEnabled(false);
}

From source file:info.financialecology.finance.utilities.datastruct.VersatileChart.java

public void drawScatterPlot(VersatileDataTable acds, String... xyPairs) {
    ArrayList<JFreeChart> charts = new ArrayList<JFreeChart>();

    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries xySeries = new XYSeries("no_name");
    dataSet.addSeries(xySeries);

    for (int i = 0; i < xyPairs.length; i += 2) {
        List<String> rowKeys = acds.getRowKeys();

        for (String rowKey : rowKeys) {
            if (!StringUtils.startsWith(rowKey, "#")) {
                double xValue = acds.getValue(rowKey, xyPairs[i]).doubleValue();
                double yValue = acds.getValue(rowKey, xyPairs[i + 1]).doubleValue();
                xySeries.add(xValue, yValue);
            }//from   w  ww. j ava 2s. c  o m
        }

        JFreeChart chart = ChartFactory.createScatterPlot(params.title, params.xLabel, params.yLabel, dataSet,
                PlotOrientation.VERTICAL, params.legend, params.toolTips, false);

        charts.add(chart);
    }

    ChartFrame frame;

    for (JFreeChart chart : charts) {
        frame = new ChartFrame("UNKNOWN", chart);
        frame.pack();
        frame.setVisible(true);
    }
}