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:com.choicemaker.cm.modelmaker.gui.panels.HoldVsAccuracyPlotPanel.java

private void buildPanel() {
    XYSeriesCollection dataset = new XYSeriesCollection();
    String title = ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.title");
    data = new XYSeries(title);
    dataset.addSeries(data);//from  ww w .  j  av a  2s  .  co m
    final PlotOrientation orientation = PlotOrientation.VERTICAL;
    chart = ChartFactory.createXYLineChart(title,
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.cm.accuracy"),
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.holdpercentage"),
            dataset, orientation, true, true, true);
    MouseListener tableMouseListener = new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            Point origin = e.getPoint();
            JTable src = (JTable) e.getSource();
            int row = src.rowAtPoint(origin);
            int col = src.columnAtPoint(origin);
            ModelMaker mm = parent.getModelMaker();
            if (src == accuracyTable) {
                if (col < 2) {
                    if (!Float.isNaN(accuracyData[row][2]) && !Float.isNaN(accuracyData[row][3]))
                        mm.setThresholds(new Thresholds(accuracyData[row][2], accuracyData[row][3]));
                } else if (col == 2) {
                    if (!Float.isNaN(accuracyData[row][2]))
                        mm.setDifferThreshold(accuracyData[row][2]);
                } else {
                    if (!Float.isNaN(accuracyData[row][3]))
                        mm.setMatchThreshold(accuracyData[row][3]);
                }
            } else {
                if (col < 2) {
                    if (!Float.isNaN(hrData[row][2]) && !Float.isNaN(hrData[row][3]))
                        mm.setThresholds(new Thresholds(hrData[row][2], hrData[row][3]));
                } else if (col == 2) {
                    if (!Float.isNaN(hrData[row][2]))
                        mm.setDifferThreshold(hrData[row][2]);
                } else {
                    if (!Float.isNaN(hrData[row][3]))
                        mm.setMatchThreshold(hrData[row][3]);
                }
            }
        }
    };
    chart.setBackgroundPaint(getBackground());
    accuracyTable = new AccuracyTable(true, accuracies);
    accuracyTable.addMouseListener(tableMouseListener);
    accuracyPanel = getPanel(accuracyTable,
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.table.hrvsacc"));

    hrTable = new AccuracyTable(false, hrs);
    hrTable.addMouseListener(tableMouseListener);
    hrPanel = getPanel(hrTable,
            ChoiceMakerCoreMessages.m.formatMessage("train.gui.modelmaker.panel.holdvsacc.table.accvshr"));

    accuracyTable.setEnabled(false);
    hrTable.setEnabled(false);
}

From source file:guineu.modules.filter.Alignment.RANSACGCGC.AlignmentGCGCRansacPlot.java

public AlignmentGCGCRansacPlot() {
    super(null, true);

    dataset = new XYSeriesCollection();
    chart = ChartFactory.createXYLineChart("", null, null, dataset, PlotOrientation.VERTICAL, true, true,
            false);/*from   www .  j a v a2 s  . c  o m*/

    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    // legend constructed by ChartFactory
    legend = chart.getLegend();
    legend.setItemFont(legendFont);
    //     legend.setFrame(BlockBorder.NONE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    // set default renderer properties
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseLinesVisible(false);
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesShape(0, dataPointsShape);
    renderer.setSeriesShape(1, dataPointsShape);
    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GRAY);
    renderer.setSeriesPaint(2, Color.BLUE);
    renderer.setBaseItemLabelPaint(labelsColor);

    plot.setRenderer(renderer);

}

From source file:com.bdb.weather.display.summary.WindSummary.java

/**
 * Create the plot./*from  ww w . ja v a  2s.  co  m*/
 * 
 * @return The panel that contains the plot
 */
private ChartViewer createPlot() {
    JFreeChart chart = ChartFactory.createXYLineChart("", "", "", null, PlotOrientation.VERTICAL, true, true,
            true);
    plot = (XYPlot) chart.getPlot();
    ChartViewer panel = new ChartViewer(chart);
    panel.setPrefSize(500, 300);
    panel.addChartMouseListener(this);

    //
    // Set up the Domain Axis (X)
    //
    dateAxis = new DateAxis("Time");
    dateAxis.setDateFormatOverride(interval.getLegacyFormat());
    dateAxis.setVerticalTickLabels(true);
    plot.setDomainAxis(dateAxis);

    valueAxis = WindSpeedRangeAxis.create();
    plot.setRangeAxis(valueAxis);

    //
    // Set up the renderer to generate tool tips, not show shapes
    //
    DefaultXYItemRenderer renderer = new DefaultXYItemRenderer();
    renderer.setBaseShapesVisible(false);
    renderer.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    interval.getLegacyFormat(), Speed.getDefaultFormatter()));
    renderer.setDefaultEntityRadius(1);
    plot.setRenderer(SUSTAINED_WIND_SERIES, renderer);

    renderer = new DefaultXYItemRenderer();
    WeatherSenseConstants.configureGustRenderer(renderer, 0);
    plot.setRenderer(GUST_SERIES, renderer);

    return panel;
}

From source file:edu.ucla.stat.SOCR.chart.demo.LineChartDemo3.java

/**
 * Creates a chart./* w w  w  .  ja  va 2  s .c  om*/
 * 
 * @param dataset  a dataset.
 * 
 * @return A chart based on the supplied dataset.
 */
protected JFreeChart createChart(XYDataset dataset) {

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainLabel, // x axis label
            rangeLabel, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, !legendPanelOn, // include legend
            true, // tooltips
            false // urls
    );

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setDrawOutlines(true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    setXSummary(dataset);
    return chart;
}

From source file:net.sf.mzmine.modules.peaklistmethods.alignment.ransac.AlignmentRansacPlot.java

public AlignmentRansacPlot() {
    super(null, true);

    dataset = new XYSeriesCollection();
    chart = ChartFactory.createXYLineChart("", null, null, dataset, PlotOrientation.VERTICAL, true, true,
            false);/*from   w w  w  .  j  av  a  2  s  .  c  o m*/

    chart.setBackgroundPaint(Color.white);
    setChart(chart);

    // title
    chartTitle = chart.getTitle();
    chartTitle.setMargin(5, 0, 0, 0);
    chartTitle.setFont(titleFont);

    // legend constructed by ChartFactory
    legend = chart.getLegend();
    legend.setItemFont(legendFont);
    legend.setFrame(BlockBorder.NONE);

    // set the plot properties
    plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    // set grid properties
    plot.setDomainGridlinePaint(gridColor);
    plot.setRangeGridlinePaint(gridColor);

    // set crosshair (selection) properties

    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    plot.setDomainCrosshairPaint(crossHairColor);
    plot.setRangeCrosshairPaint(crossHairColor);
    plot.setDomainCrosshairStroke(crossHairStroke);
    plot.setRangeCrosshairStroke(crossHairStroke);

    // set default renderer properties
    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setBaseLinesVisible(false);
    renderer.setBaseShapesVisible(true);
    renderer.setSeriesShape(0, dataPointsShape);
    renderer.setSeriesShape(1, dataPointsShape);
    renderer.setSeriesLinesVisible(2, true);
    renderer.setSeriesShapesVisible(2, false);
    renderer.setSeriesPaint(0, Color.RED);
    renderer.setSeriesPaint(1, Color.GRAY);
    renderer.setSeriesPaint(2, Color.BLUE);
    renderer.setBaseItemLabelPaint(labelsColor);

    plot.setRenderer(renderer);

}

From source file:org.mwc.cmap.xyplot.views.CrossSectionViewer.java

protected CrossSectionViewer(final Composite parent) {
    _chartFrame = new ChartComposite(parent, SWT.NONE, null, true) {
        @Override//from  w  ww  .  j  av a  2  s . c o m
        public void mouseUp(MouseEvent event) {
            super.mouseUp(event);
            JFreeChart c = getChart();
            if (c != null) {
                c.setNotify(true); // force redraw
            }
        }
    };

    _chart = ChartFactory.createXYLineChart("Cross Section", // Title
            "Distance (km)", // X-Axis label
            "Elevation (m)", // Y-Axis label
            _dataset, // Dataset,
            PlotOrientation.VERTICAL, true, // Show legend,
            true, // tooltips
            true // urs
    );

    // Fix the axises start at zero
    final ValueAxis yAxis = _chart.getXYPlot().getRangeAxis();
    yAxis.setLowerBound(0);
    final ValueAxis xAxis = _chart.getXYPlot().getDomainAxis();
    xAxis.setLowerBound(0);

    _chartFrame.setChart(_chart);
    _chartFrame.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            clearPlot();
            _chartFrame.removeDisposeListener(this);
        }
    });
}

From source file:edu.gcsc.vrl.jfreechart.TrajectoryPlotter.java

public JFreeChart lineChart(
        @ParamInfo(name = "Trajectories", style = "array", options = "serialization=false") Trajectory[] trajectories) {

    TitledXYSeriesCollection dataset = new TitledXYSeriesCollection();

    // set title if available
    if (trajectories.length > 0 && trajectories[0] != null) {
        dataset.setTitle(trajectories[0].getTitle());
        dataset.setxAxisLabel(trajectories[0].getxAxisLabel());
        dataset.setyAxisLabel(trajectories[0].getyAxisLabel());
        dataset.setxAxisLogarithmic(trajectories[0].isxAxisLogarithmic());
        dataset.setyAxisLogarithmic(trajectories[0].isyAxisLogarithmic());
    }/*from  ww w  .ja  va 2  s .  c  o m*/

    for (Trajectory t : trajectories) {
        dataset.addSeries(new TitledXYSeries(t));
    }

    final JFreeChart chart = ChartFactory.createXYLineChart(dataset.getTitle(), dataset.getxAxisLabel(),
            dataset.getyAxisLabel(), dataset, PlotOrientation.VERTICAL, true, true, false);

    if (dataset.isxAxisLogarithmic()) {
        chart.getXYPlot().setDomainAxis(new LogarithmicAxis(dataset.getxAxisLabel()));
    }

    if (dataset.isyAxisLogarithmic()) {
        chart.getXYPlot().setRangeAxis(new LogarithmicAxis(dataset.getyAxisLabel()));
    }

    return chart;
}

From source file:org.yooreeka.util.gui.XyGui.java

public XyGui(String title, double[] x) {

    super(title);

    errMsg = new StringBuilder();
    setLoopInt(x.length);//  w  w  w.j  av a  2 s.  c o  m

    if (checkX(x)) {

        XYSeries xydata = new XYSeries(title);

        for (int i = 0; i < loopInt; i++) {
            xydata.add(x[i], C.ZERO_DOUBLE);
        }

        xycollection = new XYSeriesCollection(xydata);

        final JFreeChart chart = ChartFactory.createXYLineChart(title, "X", "Y", xycollection,
                PlotOrientation.VERTICAL, true, true, false);

        final XYPlot plot = chart.getXYPlot();

        final NumberAxis domainAxis = new NumberAxis("x");
        plot.setDomainAxis(domainAxis);

        final NumberAxis rangeAxis = new NumberAxis("y");
        plot.setRangeAxis(rangeAxis);

        chart.setBackgroundPaint(Color.white);
        plot.setOutlinePaint(Color.black);

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

    } else {
        System.err.println(errMsg.toString());
    }
}

From source file:com.rapidminer.gui.plotter.charts.DeviationChartPlotter.java

private JFreeChart createChart(XYDataset dataset, boolean createLegend) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, createLegend, // include legend
            true, // tooltips
            false // urls
    );//from w ww.  j  a  v a  2  s .  com

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customization...
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);

    DeviationRenderer renderer = new DeviationRenderer(true, false);
    Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);
    if (dataset.getSeriesCount() == 1) {
        renderer.setSeriesStroke(0, stroke);
        renderer.setSeriesPaint(0, Color.RED);
        renderer.setSeriesFillPaint(0, Color.RED);
    } else {
        for (int i = 0; i < dataset.getSeriesCount(); i++) {
            renderer.setSeriesStroke(i, stroke);
            Color color = getColorProvider()
                    .getPointColor((double) i / (double) (dataset.getSeriesCount() - 1));
            renderer.setSeriesPaint(i, color);
            renderer.setSeriesFillPaint(i, color);
        }
    }
    renderer.setAlpha(0.12f);

    plot.setRenderer(renderer);

    ValueAxis valueAxis = plot.getRangeAxis();
    valueAxis.setLabelFont(LABEL_FONT_BOLD);
    valueAxis.setTickLabelFont(LABEL_FONT);

    return chart;
}

From source file:org.usfirst.frc.team2084.neuralnetwork.HeadingNeuralNetworkTrainer.java

public HeadingNeuralNetworkTrainer() {
    outputGraphNetworkSeries = new XYSeries("Network Prediction");
    outputGraphDataSeries = new XYSeries("Error");
    final XYSeriesCollection data = new XYSeriesCollection();
    data.addSeries(outputGraphDataSeries);
    data.addSeries(outputGraphNetworkSeries);
    outputGraph = ChartFactory.createXYLineChart("Error vs. Output", "Time", "Error", data,
            PlotOrientation.VERTICAL, true, true, false);

    NumberAxis xAxis = new NumberAxis();
    xAxis.setRange(new Range(-Math.PI, Math.PI));
    xAxis.setAutoRange(false);// w ww  . j av a2 s .  c o  m
    NumberAxis yAxis = new NumberAxis();
    yAxis.setRange(new Range(-1, 1));

    XYPlot plot = (XYPlot) outputGraph.getPlot();
    plot.setDomainAxis(xAxis);
    plot.setRangeAxis(yAxis);

    network = new Network(new int[] { 1, 5, 1 }, eta, momentum, new TransferFunction.HyperbolicTangent());

    try {
        SwingUtilities.invokeAndWait(() -> {
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            final Container content = frame.getContentPane();
            content.setLayout(new BorderLayout());

            outputGraphPanel = new ChartPanel(outputGraph);
            outputGraphPanel.setDomainZoomable(false);
            outputGraphPanel.setRangeZoomable(false);
            graphPanel.add(outputGraphPanel);

            graphPanel.setLayout(new GridLayout(1, 1));
            content.add(graphPanel, BorderLayout.CENTER);
            {

                JLabel etaLabel = new JLabel("Eta:");
                etaLabel.setLabelFor(etaField);
                etaField.setText(Double.toString(network.getEta()));
                etaField.setColumns(5);
                etaField.addPropertyChangeListener("value",
                        (evt) -> eta = ((Number) evt.getNewValue()).doubleValue());
                controlPanel.add(etaLabel);
                controlPanel.add(etaField);

                JLabel momentumLabel = new JLabel("Momentum:");
                momentumLabel.setLabelFor(etaField);
                momentumField.setText(Double.toString(network.getMomentum()));
                momentumField.setColumns(5);
                momentumField.addPropertyChangeListener("value",
                        (evt) -> momentum = ((Number) evt.getNewValue()).doubleValue());
                controlPanel.add(momentumLabel);
                controlPanel.add(momentumField);

                JLabel iterationsLabel = new JLabel("Iterations:");
                iterationsLabel.setLabelFor(iterationsField);
                iterationsField.setText(Integer.toString(iterations));
                iterationsField.setColumns(10);
                iterationsField.addPropertyChangeListener("value",
                        (evt) -> iterations = ((Number) evt.getNewValue()).intValue());
                controlPanel.add(iterationsLabel);
                controlPanel.add(iterationsField);
            }

            chooseDataButton.addActionListener((e) -> {
                if (dataDirectoryChooser.showOpenDialog(frame) == JFileChooser.APPROVE_OPTION) {
                    dataDirectory = dataDirectoryChooser.getSelectedFile();
                    displayData();
                }
            });
            controlPanel.add(chooseDataButton);

            trainButton.addActionListener((e) -> trainNetwork());
            controlPanel.add(trainButton);

            saveButton.addActionListener((e) -> {
                saveNetwork();
            });
            controlPanel.add(saveButton);

            content.add(controlPanel, BorderLayout.SOUTH);

            dataDirectoryChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);

            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        });
    } catch (InvocationTargetException | InterruptedException e) {
        e.printStackTrace();
    }
}