Example usage for org.jfree.chart ChartFactory createXYLineChart

List of usage examples for org.jfree.chart ChartFactory createXYLineChart

Introduction

In this page you can find the example usage for org.jfree.chart ChartFactory createXYLineChart.

Prototype

public static JFreeChart createXYLineChart(String title, String xAxisLabel, String yAxisLabel,
        XYDataset dataset, PlotOrientation orientation, boolean legend, boolean tooltips, boolean urls) 

Source Link

Document

Creates a line chart (based on an XYDataset ) with default settings.

Usage

From source file:ufmotionsuite.SpiralGraph.java

public void Graph() {
    XYSeries series = new XYSeries("X vs Y");
    for (int i = 0; i < arrLength; i++) {
        //System.out.println("Run");
        series.add(theta[i], r[i]);//from   ww  w .  ja v  a2  s.c  o  m
    }
    XYDataset dataset = new XYSeriesCollection(series);
    JFreeChart chart = ChartFactory.createXYLineChart("Distance from Origin over Angle", "Theta",
            "R (Distance)", dataset, org.jfree.chart.plot.PlotOrientation.VERTICAL, true, false, false);
    BufferedImage image = chart.createBufferedImage(600, 600);
    jLabel1.setIcon(new ImageIcon(image));
    this.setSize(800, 800);
}

From source file:fr.crnan.videso3d.ihm.TrajectoryProjectionGUI.java

public TrajectoryProjectionGUI(List<VidesoTrack> tracks, Globe globe) {

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);/*from  ww  w.  j a v  a  2s. c  o  m*/

    JMenu mnParamtres = new JMenu("Paramtres");
    menuBar.add(mnParamtres);

    JMenuItem mntmNewMenuItem = new JMenuItem("New menu item");
    mnParamtres.add(mntmNewMenuItem);

    double ref = TracksStatsProducer.computeReferenceAltitude(tracks);
    XYSeriesCollection dataset = new XYSeriesCollection();

    for (VidesoTrack t : tracks) {
        dataset.addSeries(TracksStatsProducer.computeDevelopedPath(t, ref, false, globe));
    }

    JFreeChart chart = ChartFactory.createXYLineChart("Projection", "Distance (NM)", "Altitude (FL)", dataset,
            PlotOrientation.VERTICAL, false, true, false);

    ChartPanel panel = new ChartPanel(chart);
    setContentPane(panel);
    pack();
}

From source file:trendgraph.XYLineChart_AWT.java

public XYLineChart_AWT(int yearStart, int yearEnd, String[] creditUnionName, String columnName)
        throws SQLException {
    super("Graph");
    super.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.yearStart = yearStart;
    this.yearEnd = yearEnd;
    this.creditUnionName = creditUnionName;
    this.columnName = columnName;
    saveGraphButton = new JButton("Save Graph");
    saveGraphButton.setBorderPainted(false);
    saveGraphButton.setFocusPainted(false);

    JFreeChart xylineChart = ChartFactory.createXYLineChart("CU Report", "Year (YYYY)", //X-axis
            columnName, //Y-axis (replace with columnName
            createDataset(), PlotOrientation.VERTICAL, true, true, false);

    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(1000, 800)); //(x, y)
    final XYPlot plot = xylineChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();

    renderer.setSeriesPaint(0, Color.RED); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(0, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(1, Color.BLUE); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(1, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(2, Color.GREEN); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(2, new BasicStroke(3.0f)); //Font size

    renderer.setSeriesPaint(3, Color.yellow); //can be GREEN, YELLOW, ETC.

    renderer.setSeriesStroke(3, new BasicStroke(3.0f)); //Font size

    plot.setRenderer(renderer);/*from w ww .  ja  va 2s. co  m*/
    chartPanel.setLayout(new FlowLayout(FlowLayout.TRAILING));
    chartPanel.add(saveGraphButton);
    setContentPane(chartPanel);
    pack();
    RefineryUtilities.centerFrameOnScreen(this);
    setVisible(true);

    saveGraphButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Rectangle rect = chartPanel.getBounds();
            FileChooser chooser = new FileChooser();

            //get chosen path and save the variable
            String path = chooser.getPath();
            path = path.replace("\\", "/");

            String format = "png";
            String fileName = path + "." + format;
            BufferedImage captureImage = new BufferedImage(rect.width, rect.height,
                    BufferedImage.TYPE_INT_ARGB);
            chartPanel.paint(captureImage.getGraphics());

            File file = new File(fileName);

            try {
                ImageIO.write(captureImage, format, file);

                //write data to file
            } catch (IOException ex) {
                Logger.getLogger(XYLineChart_AWT.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
}

From source file:jmbench.plots.OperationsVersusSizePlot.java

public OperationsVersusSizePlot(String title, String ylabel) {
    chart = ChartFactory.createXYLineChart(title, "Matrix Size", ylabel, null, PlotOrientation.VERTICAL, true,
            false, false);/*from w  w  w.j  a  va 2  s .c om*/

    //        chart.removeLegend();
    plot = (XYPlot) chart.getPlot();

    plot.setBackgroundPaint(Color.WHITE);

    //        final NumberAxis rangeAxis = new LogarithmicAxis(ylabel);
    //        plot.setRangeAxis(rangeAxis);

    // one of the numbers is getting cropped.  this will make it fully visible
    chart.setPadding(new RectangleInsets(5, 0, 0, 5));

}

From source file:analisisnumerico.Graficador.java

private JFreeChart crearDiagrama(XYDataset conjuntoDatos) {
    JFreeChart diag = ChartFactory.createXYLineChart("Graficador", //Titulo Grafica
            "X", // Leyenda eje X
            "Y", // Leyenda eje Y
            conjuntoDatos, // Los datos
            PlotOrientation.VERTICAL, //orientacion
            false, // ver titulo de linea
            false, //tooltips
            false //URL
    );// www . ja  v  a2  s . com
    return diag;
}

From source file:geneticalgorithm.gui.view.VGraphic.java

public VGraphic(String title, String xLabel, String yLabel) {
    setSize(800, 600);/*from   www.  j av  a 2  s  . co  m*/
    setLocationRelativeTo(this);
    setTitle(title);

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent arg0) {
            dispose();
        }
    });
    setLayout(new BorderLayout());

    average = new XYSeries("Average");
    offline = new XYSeries("Offline");
    online = new XYSeries("Online");

    dataset = new XYSeriesCollection();
    dataset.addSeries(average);
    dataset.addSeries(offline);
    dataset.addSeries(online);

    chart = ChartFactory.createXYLineChart(title, xLabel, yLabel, dataset, PlotOrientation.VERTICAL, true, true,
            false);
    add(new ChartPanel(chart), BorderLayout.CENTER);

    JPanel south = new JPanel(new MigLayout());

    lblAverage = new JLabel("");
    lblAverage.setHorizontalTextPosition(SwingConstants.LEFT);
    lblAverage.setFont(new Font("ARIAL", Font.BOLD, 26));
    JLabel lblAverageTitle = new JLabel("Average: ");
    lblAverageTitle.setFont(new Font("ARIAL", Font.BOLD, 26));
    south.add(lblAverageTitle);
    south.add(lblAverage, "wrap");

    lblOffline = new JLabel("");
    lblOffline.setHorizontalTextPosition(SwingConstants.LEFT);
    lblOffline.setFont(new Font("ARIAL", Font.BOLD, 26));
    JLabel lblOfflineTitle = new JLabel("Offline: ");
    lblOfflineTitle.setFont(new Font("ARIAL", Font.BOLD, 26));
    south.add(lblOfflineTitle);
    south.add(lblOffline, "wrap");

    lblOnline = new JLabel("");
    lblOnline.setHorizontalTextPosition(SwingConstants.LEFT);
    lblOnline.setFont(new Font("ARIAL", Font.BOLD, 26));
    JLabel lblOnlineTitle = new JLabel("Online: ");
    lblOnlineTitle.setFont(new Font("ARIAL", Font.BOLD, 26));
    south.add(lblOnlineTitle);
    south.add(lblOnline, "wrap");

    add(south, BorderLayout.SOUTH);
}

From source file:net.relet.freimap.NodeInfo.java

public void setLinkCountProfile(LinkedList<LinkCount> lcp) {
    if (lcp.size() == 0) {
        minLinks = 0;/*w ww  .j a v a  2  s.co  m*/
        maxLinks = 0;
        return;
    }

    XYSeries data = new XYSeries("links");
    XYSeries avail = new XYSeries("avail");
    XYSeriesCollection datac = new XYSeriesCollection(data);
    datac.addSeries(avail);
    linkCountChart = ChartFactory.createXYLineChart("average incoming link count\r\nincoming link availability",
            "time", "count", datac, PlotOrientation.VERTICAL, false, false, false);
    sexupLayout(linkCountChart);

    long first = lcp.getFirst().time, last = lcp.getLast().time, lastClock = first, count = 0, maxCount = 0;
    long aggregate = (last - first) / CHART_WIDTH;
    double sum = 0;

    /* ok, this ain't effective, we do it just to pre-calculate maxCount */
    ListIterator<LinkCount> li = lcp.listIterator();
    while (li.hasNext()) {
        LinkCount lc = li.next();
        count++;
        if (lc.time - lastClock > aggregate) {
            if (maxCount < count)
                maxCount = count;
            lastClock = lc.time;
            count = 0;
        }
    }

    //reset for second iteration
    count = 0;
    lastClock = first;

    //iterate again
    li = lcp.listIterator();
    while (li.hasNext()) {
        LinkCount lc = li.next();
        if (minLinks > lc.count)
            minLinks = lc.count;
        if (maxLinks < lc.count)
            maxLinks = lc.count;

        sum += lc.count;
        count++;

        if (aggregate == 0)
            aggregate = 1000;//dirty hack
        if (lc.time - lastClock > aggregate) {
            for (long i = lastClock; i < lc.time - aggregate; i += aggregate) {
                data.add(i * 1000, (i == lastClock) ? sum / count : Double.NaN);
                avail.add(i * 1000, (i == lastClock) ? ((double) count / maxCount) : 0);
            }

            count = 0;
            sum = 0;
            lastClock = lc.time;
        }
    }

    status = STATUS_AVAILABLE;
}

From source file:org.physionet.wfdb.examples.PlotECGQRSDemo2.java

private static JFreeChart createChart(XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart("Plot ECG Demo1 ", // chart title
            "Time (seconds)", // x axis label
            "mV", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*w w  w.j  ava  2s  .  c o  m*/

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);
    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setSeriesLinesVisible(1, false);
        renderer.setSeriesShapesVisible(1, true);
        renderer.setSeriesShapesFilled(1, true);
    }
    return chart;
}

From source file:dao.Graficos.java

public void tipoGrafico(TipoGrafico tipo) {

    switch (tipo) {

    case linear://from ww  w.  jav  a2  s.co m

        grafico = ChartFactory.createXYLineChart(titulo, xx, xy, dados, PlotOrientation.VERTICAL, true, true,
                true);

        break;

    case polar:

        grafico = ChartFactory.createPolarChart(titulo, dados, true, true, true);

        break;

    //            case barras:
    //
    //      
    //
    //                break;
    //            case pizza:
    //
    //                grafico = ChartFactory.createXYStepChart(titulo, xx, xy, dados);
    //
    //                break;
    case area:

        grafico = ChartFactory.createXYStepAreaChart(titulo, xx, xy, dados);

        break;

    }

}

From source file:com.wsntools.iris.tools.Graph.java

public Graph(Model model) {

    this.model = model;

    JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL, true,
            true, false);/*from www  .  j  a  v a 2s.  co m*/

    chartPanel = new ChartPanel(chart);
    setupChartType(chart);

    this.setLayout(new BorderLayout());
    this.add(chartPanel, BorderLayout.CENTER);
}