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

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

Introduction

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

Prototype

public XYSeriesCollection(XYSeries series) 

Source Link

Document

Constructs a dataset and populates it with a single series.

Usage

From source file:ricecompression.RiceCompression.java

/**
 * @param args the command line arguments
 *///from  w  ww .  j a  v  a 2  s.c  o  m
public static void main(String[] args) {
    RiceCompression rice = new RiceCompression();
    XYSeries data = new XYSeries("RICE");
    for (int i = -1023; i < 1024; i++) {
        String riceCode = rice.compress(32, i);
        data.add(i, riceCode.length());
    }
    XYSeriesCollection collection = new XYSeriesCollection(data);
    JFreeChart grafica = ChartFactory.createXYLineChart("RICE", "Nmero a codificar", "Longitud del codi Rice",
            collection, PlotOrientation.VERTICAL, true, true, false);
    ChartPanel Panel = new ChartPanel(grafica);
    JFrame Ventana = new JFrame("JFreeChart");
    Ventana.getContentPane().add(Panel);
    Ventana.pack();
    Ventana.setVisible(true);
    Ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

From source file:org.jfree.chart.demo.ImageMapDemo3.java

/**
 * Starting point for the demo./*from w ww .j av  a2  s  . c o  m*/
 *
 * @param args  ignored.
 *
 * @throws ParseException if there is a problem parsing dates.
 */
public static void main(final String[] args) throws ParseException {

    //  Create a sample dataset
    final SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
    final XYSeries dataSeries = new XYSeries("Curve data");
    final ArrayList toolTips = new ArrayList();
    dataSeries.add(sdf.parse("01-Jul-2002").getTime(), 5.22);
    toolTips.add("1D - 5.22");
    dataSeries.add(sdf.parse("02-Jul-2002").getTime(), 5.18);
    toolTips.add("2D - 5.18");
    dataSeries.add(sdf.parse("03-Jul-2002").getTime(), 5.23);
    toolTips.add("3D - 5.23");
    dataSeries.add(sdf.parse("04-Jul-2002").getTime(), 5.15);
    toolTips.add("4D - 5.15");
    dataSeries.add(sdf.parse("05-Jul-2002").getTime(), 5.22);
    toolTips.add("5D - 5.22");
    dataSeries.add(sdf.parse("06-Jul-2002").getTime(), 5.25);
    toolTips.add("6D - 5.25");
    dataSeries.add(sdf.parse("07-Jul-2002").getTime(), 5.31);
    toolTips.add("7D - 5.31");
    dataSeries.add(sdf.parse("08-Jul-2002").getTime(), 5.36);
    toolTips.add("8D - 5.36");
    final XYSeriesCollection xyDataset = new XYSeriesCollection(dataSeries);
    final CustomXYToolTipGenerator ttg = new CustomXYToolTipGenerator();
    ttg.addToolTipSeries(toolTips);

    //  Create the chart
    final StandardXYURLGenerator urlg = new StandardXYURLGenerator("xy_details.jsp");
    final ValueAxis timeAxis = new DateAxis("");
    final NumberAxis valueAxis = new NumberAxis("");
    valueAxis.setAutoRangeIncludesZero(false); // override default
    final XYPlot plot = new XYPlot(xyDataset, timeAxis, valueAxis, null);
    final StandardXYItemRenderer sxyir = new StandardXYItemRenderer(
            StandardXYItemRenderer.LINES + StandardXYItemRenderer.SHAPES, ttg, urlg);
    sxyir.setShapesFilled(true);
    plot.setRenderer(sxyir);
    final JFreeChart chart = new JFreeChart("", JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    chart.setBackgroundPaint(java.awt.Color.white);

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    * 
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    // save it to an image
    try {
        final ChartRenderingInfo info = new ChartRenderingInfo(new StandardEntityCollection());
        final File file1 = new File("xychart100.png");
        ChartUtilities.saveChartAsPNG(file1, chart, 600, 400, info);

        // write an HTML page incorporating the image with an image map
        final File file2 = new File("xychart100.html");
        final OutputStream out = new BufferedOutputStream(new FileOutputStream(file2));
        final PrintWriter writer = new PrintWriter(out);
        writer.println("<HTML>");
        writer.println("<HEAD><TITLE>JFreeChart Image Map Demo</TITLE></HEAD>");
        writer.println("<BODY>");
        //            ChartUtilities.writeImageMap(writer, "chart", info);
        writer.println("<IMG SRC=\"xychart100.png\" "
                + "WIDTH=\"600\" HEIGHT=\"400\" BORDER=\"0\" USEMAP=\"#chart\">");
        writer.println("</BODY>");
        writer.println("</HTML>");
        writer.close();

    } catch (IOException e) {
        System.out.println(e.toString());
    }
    return;
}

From source file:net.sf.mzmine.chartbasics.graphicsexport.GraphicsExportDialog.java

/**
 * Launch the application.//from w w  w .j a  va  2s. c  o m
 */
public static void main(String[] args) {
    try {
        XYSeries s = new XYSeries("1");
        IntStream.range(0, 10).forEach(i -> s.add(i, i));
        XYSeriesCollection data = new XYSeriesCollection(s);
        JFreeChart chart = ChartFactory.createXYLineChart("XY", "time (s)", "intensity", data);
        GraphicsExportDialog.createInstance();
        GraphicsExportDialog.openDialog(chart);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:problematica.Graficos.java

/**
 * //from ww w. j  ava  2s .  c o m
 * @param cantCigarros
 */

public static void createGrafico(ArrayList<ArrayList<String>> datos, String nombreArchivo) {

    XYSeries series = new XYSeries("Linea de consumo");
    //como su nombre lo indica el primer valor sera asignado al eje X
    //y el segundo al eje Y

    series.add(0, 0);

    for (int i = 0; i < datos.size(); i++) {

        series.add((i + 1), Integer.parseInt(datos.get(i).get(0)));

    }

    //se crea un objeto XYDataset requerido mas adelante por el metodo que grafica
    XYDataset juegoDatos = new XYSeriesCollection(series);

    /*aqui se hace la instancia de la nueva grafica invocando al metodo de ChartFactory
    que nos dibujara una grafica de lineas este metodo como casi todos los demas
    recibe los siguientes argumentos:
            
    tipo              valor
    String            nombre de la grafica , aparecera en la parte superior centro
    String            tutulo del eje X
    String            titulo del eje Y
    XYDataset         el conjunto de datos X y Y del tipo XYDataset (aqui cambian el parametro
                      dependiendo del tipo de grafica que se quiere pueden ver todos los parametros
                      en la documentacion aqui <a href="http://www.jfree.org/jfreechart/api/javadoc/index.html
    " title="http://www.jfree.org/jfreechart/api/javadoc/index.html
    ">http://www.jfree.org/jfreechart/api/javadoc/index.html
    </a>                              iremos notando los cambios mas adelante..
     PlotOrientation  la orientacion del grafico puede ser PlotOrientation.VERTICAL o PlotOrientation.HORIZONTAL
     boolean                  muestra u oculta leyendas     
     boolean                  muestra u oculta tooltips
     boolean                  muestra u oculta urls (esta opcion aun no la entiendo del todo)
            
    generalmente solo necesitaremos cambiar los primeros 3 parametros lo demas puede quedarse asi
            
    */
    JFreeChart chart = ChartFactory.createXYLineChart("Grafico de consumo", "dias", "cantidad cigarrillos",
            juegoDatos, PlotOrientation.VERTICAL, true, false, true // Show legend
    );
    //donde guardaremos la imagen?? pues en un bufer jeje
    BufferedImage image = chart.createBufferedImage(500, 500);

    try {
        ImageIO.write(image, "jpg", new File("c:/users/public/nms/grafico/" + nombreArchivo + ".jpg"));
    } catch (IOException e) {
        System.out.println("Error de escritura");
    }

}

From source file:org.jfree.chart.demo.XYSeriesDemo1.java

private static XYDataset createDataset() {
    XYSeries xyseries = new XYSeries("Random Data");
    xyseries.add(1.0D, 500.19999999999999D);
    xyseries.add(5D, 694.10000000000002D);
    xyseries.add(4D, 100D);//ww w .j  a v  a2 s.c  o  m
    xyseries.add(12.5D, 734.39999999999998D);
    xyseries.add(17.300000000000001D, 453.19999999999999D);
    xyseries.add(21.199999999999999D, 500.19999999999999D);
    xyseries.add(21.899999999999999D, null);
    xyseries.add(25.600000000000001D, 734.39999999999998D);
    xyseries.add(30D, 453.19999999999999D);
    return new XYSeriesCollection(xyseries);
}

From source file:cz.cuni.mff.d3s.spl.demo.libselection.JFreeChartPlotter.java

private static XYDataset getDatasetFromPairList(List<Pair<Long, Long>> input) {
    XYSeries result = new XYSeries("");

    for (Pair<Long, Long> p : input) {
        result.add(p.first, p.second);//from   w w w . j a v  a2  s.co  m
    }

    return new XYSeriesCollection(result);
}

From source file:org.jfree.chart.demo.ScatterCanvas.java

public ScatterCanvas(int width, int height, int xArea, int yArea) {

    xEffectiveArea = xArea;//ww  w .j  ava  2s  .  c om
    yEffectiveArea = yArea;
    this.series = new XYSeries("series");

    final XYSeriesCollection dataset = new XYSeriesCollection(this.series);

    final JFreeChart chart = createChart(dataset);

    final ChartPanel chartPanel = new ChartPanel(chart);

    this.add(chartPanel);

    chartPanel.setPreferredSize(new java.awt.Dimension(width - padding, height - padding));

}

From source file:metodosnumericos.Graficador.java

public ChartPanel series(String f, double xi, double xs) {

    Evaluador func = new Evaluador();
    XYSeries series = new XYSeries("Funcion");

    double iter = xi;
    while (iter < xs) {
        double y = func.Evaluador2(f, iter);
        series.add(iter, y);//from  w  w w  .ja  va 2  s.  c o  m
        System.out.println(iter + " " + y);
        iter = iter + 0.2;
    }
    XYSeriesCollection collection = new XYSeriesCollection(series);

    JFreeChart chart = ChartFactory.createXYLineChart("Grafica", "X", "Y", collection);

    ChartPanel panel = new ChartPanel(chart);
    panel.setPreferredSize(new java.awt.Dimension(400, 300));
    return panel;
}

From source file:signalanalysis.Graphs.java

public Graphs(final String title, ArrayList<Float> lags, String x, String y, String name) {

    super(title);
    final XYSeries series = new XYSeries(name);
    for (int i = 0; i < lags.size(); i++) {
        series.add(i, lags.get(i));/* w  w  w  . j  a  v  a2 s  .  c o  m*/
    }

    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart(title, x, y, data, PlotOrientation.VERTICAL, true,
            true, false);

    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:org.jfree.chart.demo.LogarithmicAxisDemo2.java

private static XYDataset createDataset() {
    XYSeries xyseries = new XYSeries("Series 1");
    xyseries.add(-500D, -500D);/*from w ww .j  a v  a2s. c o  m*/
    xyseries.add(-50D, -50D);
    xyseries.add(-5D, -5D);
    xyseries.add(0.0D, 0.0D);
    xyseries.add(5D, 5D);
    xyseries.add(50D, 50D);
    xyseries.add(500D, 500D);
    return new XYSeriesCollection(xyseries);
}