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:org.usfirst.frc.team2084.neuralnetwork.RobotHeadingTest.java

/**
 * /*from w w w  .ja v  a 2  s  .c  om*/
 */
@Override
public void run() {
    try {
        final DefaultValueDataset headingData = new DefaultValueDataset(0);
        final DefaultValueDataset desiredHeadingData = new DefaultValueDataset(0);
        final CompassPlot headingPlot = new CompassPlot();
        headingPlot.addDataset(headingData);
        headingPlot.addDataset(desiredHeadingData);
        final JFreeChart headingChart = new JFreeChart("Heading", headingPlot);

        final XYSeries headingTimeSeries = new XYSeries("Heading");
        final XYSeriesCollection headingTimeData = new XYSeriesCollection();
        headingTimeData.addSeries(headingTimeSeries);
        final JFreeChart headingTimeChart = ChartFactory.createXYLineChart("Heading vs. Time", "Time",
                "Heading", headingTimeData, PlotOrientation.VERTICAL, true, true, false);

        final XYSeries errorTimeSeries = new XYSeries("Error");
        final XYSeriesCollection errorTimeData = new XYSeriesCollection();
        errorTimeData.addSeries(errorTimeSeries);
        final JFreeChart errorTimeChart = ChartFactory.createXYLineChart("Error vs. Time", "Time", "Error",
                errorTimeData, PlotOrientation.VERTICAL, true, true, false);

        SwingUtilities.invokeAndWait(() -> {
            final JFrame frame = new JFrame("Charts");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final Container content = frame.getContentPane();
            content.setLayout(new BoxLayout(content, BoxLayout.PAGE_AXIS));

            final JPanel chartPanel = new JPanel();
            chartPanel.setLayout(new GridLayout(2, 2));
            content.add(chartPanel);

            final ChartPanel headingPanel = new ChartPanel(headingChart);
            chartPanel.add(headingPanel);

            final ChartPanel headingTimePanel = new ChartPanel(headingTimeChart);
            chartPanel.add(headingTimePanel);

            final ChartPanel errorTimePanel = new ChartPanel(errorTimeChart);
            chartPanel.add(errorTimePanel);

            final JPanel buttonPanel = new JPanel();
            content.add(buttonPanel);

            final JButton startButton = new JButton("Start");
            final JButton stopButton = new JButton("Stop");

            startButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    stop();
                    startButton.setEnabled(false);
                    stopButton.setEnabled(true);
                    start(headingData, desiredHeadingData, headingTimeSeries, errorTimeSeries);
                }
            });
            buttonPanel.add(startButton);

            stopButton.addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    stop();
                    startButton.setEnabled(true);
                    stopButton.setEnabled(false);
                }
            });
            stopButton.setEnabled(false);
            buttonPanel.add(stopButton);

            frame.pack();
            frame.setVisible(true);
        });
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:de.atomfrede.tools.evalutation.tools.plot.custom.CustomSimplePlot.java

@Override
protected JFreeChart createChart(XYDatasetWrapper... datasetWrappers) {
    XYDatasetWrapper mainDataset = datasetWrappers[0];

    JFreeChart chart = ChartFactory.createXYLineChart(mainDataset.getSeriesName(), "Index",
            mainDataset.getSeriesName(), mainDataset.getDataset(), PlotOrientation.VERTICAL, true, false,
            false);/*w ww .ja  v  a  2 s  .c  o  m*/

    XYPlot plot = (XYPlot) chart.getPlot();
    // all adjustments for first/main dataset
    plot.getRangeAxis(0).setLowerBound(mainDataset.getMinimum());
    plot.getRangeAxis(0).setUpperBound(mainDataset.getMaximum());
    // some additional "design" stuff for the plot
    plot.getRenderer(0).setSeriesPaint(0, mainDataset.getSeriesColor());
    plot.getRenderer(0).setSeriesStroke(0, new BasicStroke(mainDataset.getStroke()));

    for (int i = 1; i < datasetWrappers.length; i++) {
        XYDatasetWrapper wrapper = datasetWrappers[i];
        plot.setDataset(i, wrapper.getDataset());
        chart.setTitle(chart.getTitle().getText() + "/" + wrapper.getSeriesName());

        NumberAxis axis = new NumberAxis(wrapper.getSeriesName());
        plot.setRangeAxis(i, axis);
        plot.setRangeAxisLocation(i, AxisLocation.BOTTOM_OR_RIGHT);

        plot.getRangeAxis(i).setLowerBound(wrapper.getMinimum() - 15.0);
        plot.getRangeAxis(i).setUpperBound(wrapper.getMaximum() + 15.0);
        // map the second dataset to the second axis
        plot.mapDatasetToRangeAxis(i, i);

        XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
        renderer.setBaseShapesVisible(false);
        renderer.setSeriesStroke(0, new BasicStroke(wrapper.getStroke()));
        plot.setRenderer(i, renderer);
        plot.getRenderer(i).setSeriesPaint(0, wrapper.getSeriesColor());
    }
    // change the background and gridline colors
    plot.setBackgroundPaint(Color.white);
    plot.setDomainMinorGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    return chart;
}

From source file:org.uncommons.watchmaker.swing.evolutionmonitor.PopulationFitnessView.java

PopulationFitnessView(boolean islands) {
    super(new BorderLayout());
    meanSeries = new XYSeries(islands ? "Global Mean Fitness" : "Population Mean Fitness");
    dataSet.addSeries(bestSeries);/*from w w w .  j  a  va  2  s. c o m*/
    dataSet.addSeries(meanSeries);
    chart = ChartFactory.createXYLineChart(islands ? "Global Population Fitness" : "Population Fitness",
            islands ? "Epochs" : "Generations", "Fitness", dataSet, PlotOrientation.VERTICAL, true, // Legend.
            false, // Tooltips.
            false);
    this.domainAxis = chart.getXYPlot().getDomainAxis();
    this.rangeAxis = chart.getXYPlot().getRangeAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setLowerMargin(0);
    domainAxis.setUpperMargin(0.05);
    domainAxis.setRangeWithMargins(0, SHOW_FIXED_GENERATIONS);
    rangeAxis.setRange(minY, maxY);
    ChartPanel chartPanel = new ChartPanel(chart, ChartPanel.DEFAULT_WIDTH, ChartPanel.DEFAULT_HEIGHT,
            ChartPanel.DEFAULT_MINIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MINIMUM_DRAW_HEIGHT,
            ChartPanel.DEFAULT_MAXIMUM_DRAW_WIDTH, ChartPanel.DEFAULT_MAXIMUM_DRAW_HEIGHT, false, // Buffered
            false, // Properties
            true, // Save
            true, // Print
            false, // Zoom
            false); // Tooltips
    add(chartPanel, BorderLayout.CENTER);
    add(createControls(islands), BorderLayout.SOUTH);
}

From source file:com.cs572.assignments.Project2.view.LineChartPanel.java

/**
 * Creates a chart./*from  w w w .j  av  a  2s . co  m*/
 *
 * @param dataset the data for the chart.
 *
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Expression Tree", // chart title
            "DataPoints", // x axis label
            "Output", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // 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.setSeriesLinesVisible(1, true);
    renderer.setSeriesShapesVisible(0, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 * A demonstration application showing an XY series containing a null value.
 *
 * @param title  the frame title.//from ww  w  .  ja  v  a2s  . c  o  m
 */
public XYSeriesDemo(final String title) {

    super(title);
    final XYSeries series = new XYSeries("Random Data");
    series.add(1.0, 500.2);
    series.add(5.0, 694.1);
    series.add(4.0, 100.0);
    series.add(12.5, 734.4);
    series.add(17.3, 453.2);
    series.add(21.2, 500.2);
    series.add(21.9, null);
    series.add(25.6, 734.4);
    series.add(30.0, 453.2);
    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("XY Series Demo", "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:historyView.HistoryJFrame.java

/**
 * Creates new form HistoryJFrame/* w w w  .ja v a 2  s .com*/
 */
public HistoryJFrame() {
    initComponents();
    //set window in the center of the screen
    //Get the size of the screen
    Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
    //Determine the new location of the window
    int w = this.getSize().width;
    int h = this.getSize().height;
    int x = (dim.width - w) / 2;
    int y = (dim.height - h) / 2;
    //Move the window
    this.setLocation(x, y);

    XYSeries breathingSeries = new XYSeries("Breathing Rate");
    XYSeries oxygenSeries = new XYSeries("Oxygen");
    XYSeries temperatureSeries = new XYSeries("Temperature");
    XYSeries bloodPressureSeries = new XYSeries("Blood Pressure");
    XYSeries heartRateSeries = new XYSeries("Heart Rate");

    // add date to all the series
    for (Map.Entry<String, PatientData> entry : model.getSelectedPatient().data.entrySet()) {
        breathingSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getBreathing());
        oxygenSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getOxygen());
        temperatureSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getTemperature());
        bloodPressureSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getBloodPressure());
        heartRateSeries.add(Double.parseDouble(entry.getKey()), entry.getValue().getHeartRate());
    }

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(breathingSeries);
    dataset.addSeries(oxygenSeries);
    dataset.addSeries(temperatureSeries);
    dataset.addSeries(bloodPressureSeries);
    dataset.addSeries(heartRateSeries);

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("XY Chart", // Title
            "time(s)", // x-axis Label
            "Rate", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );

    this.setLayout(new java.awt.BorderLayout());
    ChartPanel CP = new ChartPanel(chart);
    chart.getPlot().setBackgroundAlpha(1);
    chart.getPlot().setBackgroundPaint(Color.BLUE);

    HistoryButtonsJPanel buttonPanel = new HistoryButtonsJPanel();

    ChartUtilities.applyCurrentTheme(chart);
    this.add(CP, BorderLayout.CENTER);
    this.add(buttonPanel, BorderLayout.PAGE_END);
    this.validate();
}

From source file:erigo.filewatch.DisplayPlot.java

/**
  * Creates a new plot./*w w  w  .ja  va  2  s . c  o m*/
  *
  * @param chartTitleI   Chart title
  * @param xaxisLabelI   Label for x-axis
  * @param yaxisLabelI   Label for y-axis
  * @param xDataI      x-axis data
  * @param yDataI      y-axis data
  * @param xLocI         x-pos of lower left corner of the JFrame
  * @param yLocI         y-pos of lower left corner of the JFrame
  */
public DisplayPlot(String chartTitleI, String xaxisLabelI, String yaxisLabelI, List<Double> xDataI,
        List<Double> yDataI, int xLocI, int yLocI) {
    super("FileWatch data");
    chartTitle = chartTitleI;
    xaxisLabel = xaxisLabelI;
    yaxisLabel = yaxisLabelI;
    xData = xDataI;
    yData = yDataI;

    // Create dataset
    XYDataset dataset = createDataset();

    // Create chart
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xaxisLabel, yaxisLabel, dataset,
            PlotOrientation.VERTICAL, false, // no legend
            true, false);

    // Don't have any lower or upper margin; I think this will set the ends of the data
    // right up against the lower and upper edges of the plot
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // Create Panel
    ChartPanel panel = new ChartPanel(chart);
    setContentPane(panel);
    setSize(800, 400);
    // setLocationRelativeTo(null);  // to place in center of screen; not good if there are multiple plots
    setLocation(xLocI, yLocI);
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

}

From source file:com.seniorproject.augmentedreality.test.LineChartDemo6.java

/**
 * Creates a chart./*from w  ww  .j  a  v  a 2 s.  co  m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Line Chart Demo 6", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );

    // 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, false);
    renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    final NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}

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

/**
 * A demonstration of mouse zooming.//w ww .ja  v  a 2s . c o m
 *
 * @param title  the frame title.
 */
public MouseZoomDemo(final String title) {

    super(title);
    final SampleXYDataset data = new SampleXYDataset();
    final JFreeChart chart = ChartFactory.createXYLineChart("Mouse Zoom Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);

    this.chartPanel = new ChartPanel(chart);
    //        this.chartPanel.setHorizontalZoom(false);
    //      this.chartPanel.setVerticalZoom(false);
    this.chartPanel.setHorizontalAxisTrace(false);
    this.chartPanel.setVerticalAxisTrace(false);
    this.chartPanel.setFillZoomRectangle(true);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    final JPanel main = new JPanel(new BorderLayout());
    final JPanel checkpanel = new JPanel();
    this.xzoom = new JCheckBox("Horizontal Mouse Zooming");
    this.xzoom.setSelected(false);
    this.yzoom = new JCheckBox("Vertical Mouse Zooming");
    this.yzoom.setSelected(false);
    final CheckListener clisten = new CheckListener();
    this.xzoom.addItemListener(clisten);
    this.yzoom.addItemListener(clisten);
    checkpanel.add(this.xzoom);
    checkpanel.add(this.yzoom);
    main.add(checkpanel, BorderLayout.SOUTH);
    main.add(this.chartPanel);
    setContentPane(main);

}

From source file:de.genvlin.plugins.jfreechart.JFreeChartPluginImpl.java

public boolean plot(final XYPool xyVectorPool, final ID id) {
    final GTask t = new GTask() {
        ChartPanel panel;//w ww  .j  a va 2  s. c o m

        public void runTask() {
            XYVectorPoolWrapper dataset = new XYVectorPoolWrapper(xyVectorPool);

            JFreeChart chart = ChartFactory.createXYLineChart("JFreechart Plot Panel.", // chart title
                    "X Title", // x axis label
                    "Y Title", // y axis label
                    dataset, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // tooltips
                    false // urls
            );

            panel = new ChartPanel(chart);
            panel.setName("plot:" + dataset.getID());
        }

        public Object getResult() {
            return panel;
        }
    };//GTask

    t.addChangeListener(new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName() == GTask.FINISHED) {
                showPanel((ChartPanel) t.getResult(), "east");
            }
        }
    });
    t.start();
    return true;
}