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

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

Introduction

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

Prototype

public XYSeries getSeries(Comparable key) 

Source Link

Document

Returns a series from the collection.

Usage

From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java

private XYItemRenderer getRouteRenderer(XYSeriesCollection solutionColl) {
    XYItemRenderer solutionRenderer = new XYLineAndShapeRenderer(true, false); // Lines only
    for (int i = 0; i < solutionColl.getSeriesCount(); i++) {
        XYSeries s = solutionColl.getSeries(i);
        XYDataItem firstCustomer = s.getDataItem(1);
        firstActivities.add(firstCustomer);
    }/*from w w  w.  ja  va2  s  .  co  m*/
    return solutionRenderer;
}

From source file:lu.lippmann.cdb.lab.mds.MDSViewBuilder.java

/**
 * //from w  w w.ja  va 2s.c o  m
 * @param clusters
 */
public static void buildKMeansChart(final List<Instances> clusters) {
    final XYSeriesCollection dataset = new XYSeriesCollection();

    final JFreeChart chart = ChartFactory.createScatterPlot("", // title 
            "X", "Y", // axis labels 
            dataset, // dataset 
            PlotOrientation.VERTICAL, true, // legend? yes 
            true, // tooltips? yes 
            false // URLs? no 
    );

    final XYPlot xyPlot = (XYPlot) chart.getPlot();

    ((NumberAxis) xyPlot.getDomainAxis()).setTickUnit(new NumberTickUnit(2.0));
    ((NumberAxis) xyPlot.getRangeAxis()).setTickUnit(new NumberTickUnit(2.0));

    Attribute clsAttribute = null;
    int nbClass = 1;
    Instances cluster0 = clusters.get(0);
    if (cluster0.classIndex() != -1) {
        clsAttribute = cluster0.classAttribute();
        nbClass = clsAttribute.numValues();
    }
    if (nbClass <= 1) {
        dataset.addSeries(new XYSeries("Serie #1", false));
    } else {
        for (int i = 0; i < nbClass; i++) {
            dataset.addSeries(new XYSeries(clsAttribute.value(i), false));
        }
    }

    final XYToolTipGenerator gen = new XYToolTipGenerator() {
        @Override
        public String generateToolTip(XYDataset dataset, int series, int item) {
            return "TODO";
        }
    };

    for (int i = 0; i < nbClass; i++) {
        dataset.getSeries(i).clear();
        xyPlot.getRenderer().setSeriesToolTipGenerator(i, gen);
    }

    final int nbClusters = clusters.size();
    for (int i = 0; i < nbClusters; i++) {
        Instances instances = clusters.get(i);
        final int nbInstances = instances.numInstances();
        for (int j = 0; j < nbInstances; j++) {
            final Instance oInst = instances.instance(j);
            dataset.getSeries(i).add(oInst.value(0), oInst.value(1));
        }
    }

    final TitledBorder titleBorder = new TitledBorder("Kmeans of projection");
    ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setMouseWheelEnabled(true);
    chartPanel.setPreferredSize(new Dimension(1200, 900));
    chartPanel.setBorder(titleBorder);
    chartPanel.setBackground(Color.WHITE);

    JXFrame frame = new JXFrame();
    frame.getContentPane().add(chartPanel);
    frame.setVisible(true);
    frame.pack();

}

From source file:userinterface.graph.PrismErrorRenderer.java

/**
 * Draws the visual representation for one data item.
 *
 * @param g2  the graphics output target.
 * @param state  the renderer state.//from  w ww.jav  a2 s.co  m
 * @param dataArea  the data area.
 * @param info  the plot rendering info.
 * @param plot  the plot.
 * @param domainAxis  the domain axis.
 * @param rangeAxis  the range axis.
 * @param dataset  the dataset.
 * @param series  the series index.
 * @param item  the item index.
 * @param crosshairState  the crosshair state.
 * @param pass  the pass index
 * @author Muhammad Omer Saeed.
 */

@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairState, int pass) {

    if (!drawError) {
        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);
        return;
    }

    switch (currentMethod) {

    case PrismErrorRenderer.ERRORBARS:

        if (pass == 0 && dataset instanceof XYSeriesCollection && getItemVisible(series, item)) {

            synchronized (dataset) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;

                PlotOrientation orientation = plot.getOrientation();
                // draw the error bar for the y-interval
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                double y0 = it.getYValue() + it.getError();
                double y1 = it.getYValue() - it.getError();
                double x = collection.getXValue(series, item);

                RectangleEdge edge = plot.getRangeAxisEdge();
                double yy0 = rangeAxis.valueToJava2D(y0, dataArea, edge);
                double yy1 = rangeAxis.valueToJava2D(y1, dataArea, edge);
                double xx = domainAxis.valueToJava2D(x, dataArea, plot.getDomainAxisEdge());
                Line2D line;
                Line2D cap1;
                Line2D cap2;
                double adj = this.capLength / 2.0;
                if (orientation == PlotOrientation.VERTICAL) {
                    line = new Line2D.Double(xx, yy0, xx, yy1);
                    cap1 = new Line2D.Double(xx - adj, yy0, xx + adj, yy0);
                    cap2 = new Line2D.Double(xx - adj, yy1, xx + adj, yy1);
                } else { // PlotOrientation.HORIZONTAL
                    line = new Line2D.Double(yy0, xx, yy1, xx);
                    cap1 = new Line2D.Double(yy0, xx - adj, yy0, xx + adj);
                    cap2 = new Line2D.Double(yy1, xx - adj, yy1, xx + adj);
                }

                g2.setPaint(getItemPaint(series, item));

                if (this.errorStroke != null) {
                    g2.setStroke(this.errorStroke);
                } else {
                    g2.setStroke(getItemStroke(series, item));
                }
                g2.draw(line);
                g2.draw(cap1);
                g2.draw(cap2);
            }

        }

        super.drawItem(g2, state, dataArea, info, plot, domainAxis, rangeAxis, dataset, series, item,
                crosshairState, pass);

        break;

    case PrismErrorRenderer.ERRORDEVIATION:

        synchronized (dataset) {
            // do nothing if item is not visible
            if (!getItemVisible(series, item)) {
                return;
            }

            // first pass draws the shading
            if (pass == 0) {

                XYSeriesCollection collection = (XYSeriesCollection) dataset;
                XYSeries s = collection.getSeries(series);
                PrismXYDataItem it = (PrismXYDataItem) s.getDataItem(item);

                State drState = (State) state;

                double x = collection.getXValue(series, item);
                double yLow = it.getYValue() - it.getError();
                double yHigh = it.getYValue() + it.getError();

                RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
                RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

                double xx = domainAxis.valueToJava2D(x, dataArea, xAxisLocation);
                double yyLow = rangeAxis.valueToJava2D(yLow, dataArea, yAxisLocation);
                double yyHigh = rangeAxis.valueToJava2D(yHigh, dataArea, yAxisLocation);

                PlotOrientation orientation = plot.getOrientation();
                if (orientation == PlotOrientation.HORIZONTAL) {
                    drState.lowerCoordinates.add(new double[] { yyLow, xx });
                    drState.upperCoordinates.add(new double[] { yyHigh, xx });
                } else if (orientation == PlotOrientation.VERTICAL) {
                    drState.lowerCoordinates.add(new double[] { xx, yyLow });
                    drState.upperCoordinates.add(new double[] { xx, yyHigh });
                }

                if (item == (dataset.getItemCount(series) - 1)) {
                    // last item in series, draw the lot...
                    // set up the alpha-transparency...
                    Composite originalComposite = g2.getComposite();
                    g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float) this.alpha));
                    g2.setPaint(getItemPaint(series, item));
                    GeneralPath area = new GeneralPath();
                    double[] coords = (double[]) drState.lowerCoordinates.get(0);
                    area.moveTo((float) coords[0], (float) coords[1]);
                    for (int i = 1; i < drState.lowerCoordinates.size(); i++) {
                        coords = (double[]) drState.lowerCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    int count = drState.upperCoordinates.size();
                    coords = (double[]) drState.upperCoordinates.get(count - 1);
                    area.lineTo((float) coords[0], (float) coords[1]);
                    for (int i = count - 2; i >= 0; i--) {
                        coords = (double[]) drState.upperCoordinates.get(i);
                        area.lineTo((float) coords[0], (float) coords[1]);
                    }
                    area.closePath();
                    g2.fill(area);
                    g2.setComposite(originalComposite);

                    drState.lowerCoordinates.clear();
                    drState.upperCoordinates.clear();
                }
            }
            if (isLinePass(pass)) {

                // the following code handles the line for the y-values...it's
                // all done by code in the super class
                if (item == 0) {
                    State s = (State) state;
                    s.seriesPath.reset();
                    s.setLastPointGood(false);
                }

                if (getItemLineVisible(series, item)) {
                    drawPrimaryLineAsPath(state, g2, plot, dataset, pass, series, item, domainAxis, rangeAxis,
                            dataArea);
                }
            }

            // second pass adds shapes where the items are ..
            else if (isItemPass(pass)) {

                // setup for collecting optional entity info...
                EntityCollection entities = null;
                if (info != null) {
                    entities = info.getOwner().getEntityCollection();
                }

                drawSecondaryPass(g2, plot, dataset, pass, series, item, domainAxis, dataArea, rangeAxis,
                        crosshairState, entities);
            }

        }

        break;
    default:
        return;
    }
}

From source file:jspritTest.util.Plotter.java

private MyActivityRenderer getProblemRenderer(final XYSeriesCollection problem) {
    MyActivityRenderer problemRenderer = new MyActivityRenderer(problem, activitiesByDataItem, firstActivities);
    problemRenderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {

        public String generateLabel(XYDataset arg0, int arg1, int arg2) {
            XYDataItem item = problem.getSeries(arg1).getDataItem(arg2);
            return labelsByDataItem.get(item);
        }//from w w  w .ja va 2 s.  c o m

    });
    problemRenderer.setBaseItemLabelsVisible(true);
    problemRenderer.setBaseItemLabelPaint(Color.BLACK);

    return problemRenderer;
}

From source file:com.graphhopper.jsprit.analysis.toolbox.Plotter.java

private MyActivityRenderer getProblemRenderer(final XYSeriesCollection problem) {
    MyActivityRenderer problemRenderer = new MyActivityRenderer(problem, activitiesByDataItem, firstActivities);
    problemRenderer.setBaseItemLabelGenerator(new XYItemLabelGenerator() {

        @Override//from   w w  w . j av  a 2  s  . c  om
        public String generateLabel(XYDataset arg0, int arg1, int arg2) {
            XYDataItem item = problem.getSeries(arg1).getDataItem(arg2);
            return labelsByDataItem.get(item);
        }

    });
    problemRenderer.setBaseItemLabelsVisible(true);
    problemRenderer.setBaseItemLabelPaint(Color.BLACK);

    return problemRenderer;
}

From source file:AltiConsole.AltiConsoleMainScreen.java

public boolean SavingFlight() {
    JFileChooser saveFile = new JFileChooser();

    String currentFligtName = null;
    if (Serial.MyFlight == null) {
        System.out.println("Serial.MyFlight is null ");
        return false;
    }/* w ww.  j a  v  a 2s  .  c o m*/
    if (flightList == null) {
        System.out.println("flightList is null ");
        return false;
    }
    if (!flightList.isValid()) {
        System.out.println("flightList is invalid ");
        return false;
    }
    if (flightList.getComponentCount() > 0) {
        System.out.println("nbr of flight " + flightList.getComponentCount() + "\n");
        System.out.println("flightname " + flightList.getSelectedValue().toString() + "\n");
        currentFligtName = flightList.getSelectedValue().toString();
    } else
        return false;

    saveFile.setSelectedFile(new File(flightList.getSelectedValue().toString() + ".csv"));
    if (saveFile.showSaveDialog(null) == JFileChooser.APPROVE_OPTION) {
        File file = saveFile.getSelectedFile();

        try {
            // get flight data
            XYSeriesCollection flightData = null;
            flightData = Serial.MyFlight.GetFlightData(flightList.getSelectedValue().toString());
            int numberOfPoints;
            numberOfPoints = flightData.getSeries(0).getItemCount();

            // Create file
            FileWriter fstream = new FileWriter(file.getName());
            BufferedWriter out = new BufferedWriter(fstream);
            out.write("time, altitude\n");
            int i;
            for (i = 0; i < numberOfPoints; i++) {
                long X, Y;
                X = flightData.getSeries(0).getX(i).longValue();
                Y = flightData.getSeries(0).getY(i).longValue();
                System.out.println(X + "," + Y + "\n");
                out.write(X + "," + Y + "\n");
            }
            // Close the output stream
            out.close();
        } catch (Exception e) {// Catch exception if any
            System.err.println("Error: " + e.getMessage());
        }
    }
    return true;
}

From source file:umontreal.iro.lecuyer.charts.XYListSeriesCollection.java

/**
 * Creates a new <TT>XYListSeriesCollection</TT> instance with default parameters and given data series.
 *    The input parameter represents a set of plotting data.
 *    Each series of the given collection corresponds to a curve on the plot.
 * /* w ww  .j a  v a2  s .  c  o  m*/
 * @param data series of point sets.
 * 
 */
public XYListSeriesCollection(XYSeriesCollection data) {
    renderer = new XYLineAndShapeRenderer(true, false);
    //  ((XYLineAndShapeRenderer)renderer).setShapesVisible(false);
    seriesCollection = data;
    for (int i = 0; i < data.getSeriesCount(); i++) {
        XYSeries serie = data.getSeries(i);
    }

    // set default colors
    for (int i = 0; i < data.getSeriesCount(); i++) {
        renderer.setSeriesPaint(i, getDefaultColor(i));
    }

    // set default plot style
    plotStyle = new String[data.getSeriesCount()];
    marksType = new String[data.getSeriesCount()];
    dashPattern = new String[data.getSeriesCount()];
    for (int i = 0; i < data.getSeriesCount(); i++) {
        marksType[i] = " ";
        plotStyle[i] = "smooth";
        dashPattern[i] = "solid";
    }
}

From source file:org.pentaho.plugin.jfreereport.reportcharts.XYChartExpression.java

protected TableXYDataset convertToTable(final XYSeriesCollection xyDataset) {
    final ExtCategoryTableXYDataset tableXYDataset = new ExtCategoryTableXYDataset();
    final int count = xyDataset.getSeriesCount();
    for (int i = 0; i < count; i++) {
        final XYSeries timeSeries = xyDataset.getSeries(i);
        final Comparable key = timeSeries.getKey();
        final int itemCount = timeSeries.getItemCount();
        for (int ic = 0; ic < itemCount; ic++) {
            final XYDataItem seriesDataItem = timeSeries.getDataItem(ic);
            tableXYDataset.add(seriesDataItem.getX(), seriesDataItem.getY(), key, false);
        }/*from   w w  w  .  ja v a 2s .  c o m*/
    }
    return tableXYDataset;
}

From source file:GUI.GUIModel.java

public void PutPoint(double key, double x, double y, JPanel GraphHerePanel) {
    Component[] a = GraphHerePanel.getComponents();
    ChartPanel chartpanel = (ChartPanel) a[0];
    JFreeChart chart = chartpanel.getChart();

    XYPlot plot = (XYPlot) chart.getPlot();
    XYSeriesCollection data = (XYSeriesCollection) plot.getDataset();
    XYSeries XYseries = data.getSeries(key);
    XYseries.add(x, y);/* w  ww.  ja va2s .c o m*/
    this.revalidate();
    this.repaint();

}

From source file:com.chart.SwingChart.java

/**
 * Export chart values to a csv file//  w  w w  .ja  va 2 s  .  co m
 * @param file CSV file
 */
private void export(File file) {
    String registro;
    int n = 0;
    int ne = 0;
    String cabecera = "Time;";
    for (int i = 0; i < plot.getDatasetCount(); i++) {
        XYSeriesCollection ds = (XYSeriesCollection) plot.getDataset(i);
        for (int j = 0; j < ds.getSeriesCount(); j++) {
            n++;
            XYSeries s = (XYSeries) ds.getSeries(j);
            cabecera += s.getKey().toString() + ";";
            if (n == 1) {
                ne = s.getItemCount();
            }
        }
    }
    String[][] exportacion = new String[ne][n + 1];
    n = 0;
    for (int i = 0; i < plot.getDatasetCount(); i++) {
        XYSeriesCollection ds = (XYSeriesCollection) plot.getDataset(i);
        for (int j = 0; j < ds.getSeriesCount(); j++) {
            XYSeries s = (XYSeries) ds.getSeries(j);
            n++;
            for (int e = 0; e < ne; e++) {
                try {
                    exportacion[e][n] = ordinateFormat.format(s.getDataItem(e).getYValue());
                } catch (Exception ex) {
                    exportacion[e][n] = "";
                }
                if (n == 1) {

                    exportacion[e][0] = abcissaFormat.format(s.getDataItem(e).getXValue());

                }
            }
        }
    }
    FileWriter fichero;

    PrintWriter pw;

    try {
        fichero = new FileWriter(file.getAbsolutePath(), false);
        pw = new PrintWriter(fichero);
        pw.println(cabecera);
        for (String[] exp : exportacion) {
            String strRegistro = "";
            for (String e : exp) {
                strRegistro += e + ";";
            }
            pw.println(strRegistro);
        }

        pw.close();
    } catch (IOException ex) {
        Global.info.log(ex);
    }
}