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:max.hubbard.Factoring.Graphing.java

private static JFreeChart createChart(final XYDataset dataset, String equation) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart(equation, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from   w  ww  . ja v a 2  s .c  om*/

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    chart.setBackgroundPaint(Color.white);

    //        final StandardLegend legend = (StandardLegend) chart.getLegend();
    //              legend.setDisplaySeriesShapes(true);

    // get a reference to the plot for further customisation...
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    //    plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setRange(new Range(-50, 50));
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

From source file:com.marmoush.jann.chart.LineImg.java

@Override
public void createPNG() {
    JFreeChart chart = ChartFactory.createXYLineChart(getTitle(), getxAxisTitle(), getyAxisTitle(),
            getXySeriesCollec(), getOrientation(), isLegend(), isTooltips(), isUrls());
    setChart(chart);/*from w  w  w .  j  a v a2s.co  m*/
    super.createPNG();
}

From source file:Charts.LineChart.java

private JFreeChart makeJFreeChart(String title, String x, String y) {
    final JFreeChart lineChart = ChartFactory.createXYLineChart(title, // chart title
            x, // x axis label
            y, // y axis label
            this.createDataset(), // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*www  .  j a  va2s. c o  m*/
    return lineChart;
}

From source file:app.gui.ViewGraphic.java

public ViewGraphic(String title) {
    setSize(600, 400);/*from  w  ww . j  a  v  a  2 s.c  om*/
    setLocationRelativeTo(this);
    setTitle(title);

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

    serieError = new XYSeries(title);

    dataset = new XYSeriesCollection();
    dataset.addSeries(serieError);

    chart = ChartFactory.createXYLineChart(title, Translate.get("GUI_PERIODS"), Translate.get("GUI_ERROR"),
            dataset, PlotOrientation.VERTICAL, true, true, false);
    add(new ChartPanel(chart), BorderLayout.CENTER);

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

    lblError = new JLabel("");
    lblError.setHorizontalTextPosition(SwingConstants.LEFT);
    lblError.setFont(new Font("ARIAL", Font.BOLD, 26));
    JLabel lblErrorTitle = new JLabel(Translate.get("GUI_ERROR") + ": ");
    lblErrorTitle.setFont(new Font("ARIAL", Font.BOLD, 26));
    south.add(lblErrorTitle);
    south.add(lblError, "wrap");

    add(south, BorderLayout.SOUTH);
    setVisible(true);
}

From source file:ip.ui.plot.PlotGenerator.java

public void generateErrorChart(List<Double> errors, String plotFileName) throws IOException {
    XYSeries data = new XYSeries("Errors");

    for (int i = 1; i <= errors.size(); ++i) {
        data.add(i, errors.get(i - 1));//from   w w w  . j a v  a2 s  .  c  o  m
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(data);
    JFreeChart chart = ChartFactory.createXYLineChart("Squared error", "Epoch number", "Squared Error", dataset,
            PlotOrientation.VERTICAL, false, true, true);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, false);
    chart.getXYPlot().setRenderer(renderer);

    File XYChart = new File(plotFileName);
    ChartUtilities.saveChartAsJPEG(XYChart, chart, chartWidth, chartHeight);
}

From source file:Graphing.graphXY.java

public JPanel getXYgraphPanel() {
    XYDataset dataSet = getDataSet();/*from   ww w  .j  av  a2 s  .  c o m*/
    JFreeChart graph = ChartFactory.createXYLineChart(this.name, this.xLabel, this.yLabel, dataSet, this.p,
            this.Legend, this.toolTips, false);

    return new ChartPanel(graph);
}

From source file:edu.pdi2.visual.ViewSignature.java

public ViewSignature(String name, byte[] sign) {
    super();//from w  w  w.  j a v a  2 s .  co  m
    XYSeries signature = new XYSeries("Signature");
    for (int i = 0; i < sign.length; i++) {
        signature.add(i, sign[i]);
    }

    JFrame frame = new JFrame();
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(signature);
    JFreeChart signatureG = ChartFactory.createXYLineChart("Signature " + name, "Valorx", "Valory", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    ChartPanel chartpanel = new ChartPanel(signatureG);
    chartpanel.setPreferredSize(new Dimension(390, 290));
    frame.setContentPane(chartpanel);
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    frame.pack();
    frame.setSize(400, 300);
    frame.setVisible(true);
    if (name == " RED")
        frame.setLocation(0, 300);
    else
        frame.setLocation(400, 300);

}

From source file:org.samjoey.graphing.GraphUtility.java

/**
 *
 * @param games the games to graph/* w  w  w.j  av a2 s.co m*/
 * @param key the variable to create the graph with
 * @param start if index, the index at which to start, else the percent in
 * the game at which to start
 * @param stop if index, the index at which to end, else the percent in the
 * game at which to end
 * @param index
 * @return
 */
public static ChartPanel getCustomGraph(Game[] games, String key, double start, double stop, boolean index) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    for (Game game : games) {
        ArrayList<Double> data = game.getVar(key);
        int begin;
        int end;
        if (index) {
            begin = (int) start;
            end = (int) stop;
        } else {
            begin = (int) (data.size() / start);
            end = (int) (data.size() / stop);
        }
        XYSeries series = GraphUtility.createSeries(data.subList(begin, end), "" + game.getId());
        dataset.addSeries(series);
    }
    JFreeChart chart = ChartFactory.createXYLineChart(key, // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, false, // include legend
            true, // tooltips
            false // urls
    );
    XYPlot plot = chart.getXYPlot();
    XYItemRenderer rend = plot.getRenderer();
    for (int i = 0; i < games.length; i++) {
        Game g = games[i];
        if (g.getWinner() == 1) {
            rend.setSeriesPaint(i, Color.RED);
        }
        if (g.getWinner() == 2) {
            rend.setSeriesPaint(i, Color.BLACK);
        }
        if (g.getWinner() == 0) {
            rend.setSeriesPaint(i, Color.PINK);
        }
    }
    ChartPanel chartPanel = new ChartPanel(chart);
    return chartPanel;
}

From source file:ihm.mainActivity.java

/**
 * Creates new form testBuild//w w  w  .  java  2  s  .  com
 */
public mainActivity() {
    dataList = new DataList();
    dataList.addObserver(this);
    chart = ChartFactory.createXYLineChart("Graphique", "x", "Value", createDataset(), PlotOrientation.VERTICAL,
            true, true, false);
    fileChooser = new JFileChooser();
    fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
    FileNameExtensionFilter filter = new FileNameExtensionFilter("CSV Files", "csv");
    fileChooser.setFileFilter(filter);
    initComponents();
}

From source file:com.mycompany.istudy.principalservices.GraphicalView.java

/**
 * Overwrites the method of createXYLineChart from ChartFactory interface
 * and creates a XYLine Chart./* w  w  w.  j av a2 s .  co  m*/
 * @param applicationTitle
 * @param chartTitle
 * @param investedHoursPerWeek
 * @param hoursToBeInvested 
 */
public GraphicalView(String applicationTitle, String chartTitle, Map<Double, Double> investedHoursPerWeek,
        Map<Double, Double> hoursToBeInvested) {
    super(applicationTitle);
    xylineChart = ChartFactory.createXYLineChart(chartTitle, "Calender Weeks", "Invested Study-hours",
            createDataset(investedHoursPerWeek, hoursToBeInvested), PlotOrientation.VERTICAL, true, true,
            false);
    ChartPanel chartPanel = new ChartPanel(xylineChart);
    chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    final XYPlot plot = xylineChart.getXYPlot();
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesPaint(0, Color.BLUE);
    renderer.setSeriesPaint(1, Color.RED);
    renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    plot.setRenderer(renderer);
    setContentPane(chartPanel);
}