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.projectforge.charting.XYChartBuilder.java

public XYChartBuilder(final String title, final String xAxisLabel, final String yAxisLabel,
        final XYDataset dataset, final boolean legend) {
    this(ChartFactory.createXYLineChart(title, xAxisLabel, yAxisLabel, dataset, PlotOrientation.VERTICAL,
            legend, true, false));/*  w  w w.  j  a  va  2  s  . co m*/
}

From source file:ntpgraphic.LineChart.java

private JPanel createChartPanel() {
    String chartTitle = "NTP Graphic";
    String xAxisLabel = "Time";
    String yAxisLabel = "Roundtrip delay(ms)";

    XYDataset dataset = createDataset();

    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, xAxisLabel, yAxisLabel, dataset,
            PlotOrientation.VERTICAL, rootPaneCheckingEnabled, rootPaneCheckingEnabled,
            rootPaneCheckingEnabled);//from  w w w. java2 s .  com

    File imageFile = new File("NTPGraphic.png");
    int width = 640;
    int height = 480;

    try {
        ChartUtilities.saveChartAsPNG(imageFile, chart, width, height);
    } catch (IOException ex) {
        System.err.println(ex);
    }

    return new ChartPanel(chart);
}

From source file:mls.FramePlot.java

private JFreeChart createChartVarianza(final XYDataset datasetVarianza) {
    final JFreeChart result = ChartFactory.createXYLineChart("Varianza campionaria", "n", "vc", datasetVarianza,
            PlotOrientation.VERTICAL, false, true, false);
    final XYPlot plot = result.getXYPlot();
    ValueAxis axis = plot.getDomainAxis();
    axis.setAutoRange(true);//from   w  ww.  j ava2  s .c  o m
    axis.setFixedAutoRange(1500);

    axis = plot.getRangeAxis();
    axis.setAutoRange(true);
    axis.setRange(10, 100);
    plot.getRenderer().setSeriesPaint(0, Color.MAGENTA);
    return result;
}

From source file:pi.bestdeal.models.Charts.java

public void XYChart(XYSeriesCollection mydataset) {
    JFreeChart chart = ChartFactory.createXYLineChart("XY Chart", // Title
            "x-axis", // x-axis Label
            "y-axis", // y-axis Label
            mydataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );//w ww . j a v a 2 s.co  m
    XYItemRenderer rend = chart.getXYPlot().getRenderer();

    ChartPanel crepart = new ChartPanel(chart);
    Plot plot = chart.getPlot();
    this.add(crepart);

}

From source file:etssi.Graphique.java

/**
 * Creates a chart.//from  w  w w .ja v a2 s  .  c om
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart chart = ChartFactory.createXYLineChart("Graphique", // chart title
            "Tranche Horaire (0 avant 6h, 1 de 6h  10h, 2 de 10h  16h, 3 de 16h  20h, 4 aprs 20h ", // x axis label
            "Montant passagers", // 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.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);

    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:adams.gui.visualization.jfreechart.chart.XYLineChart.java

/**
 * Performs the actual generation of the chart.
 *
 * @param data   the data to use/*from w  ww . java 2s  .c  om*/
 * @return      the chart
 */
@Override
protected JFreeChart doGenerate(XYDataset data) {
    return ChartFactory.createXYLineChart(m_Title, m_LabelX, m_LabelY, data, m_Orientation.getOrientation(),
            m_Legend, m_ToolTips, false);
}

From source file:eu.choreos.vv.chart.YIntervalChart.java

private static JFreeChart createChart(XYDataset dataset, String chartTitle, String xLabel, String yLabel) {

    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            xLabel, // domain axis label
            yLabel, // range axis label
            dataset, // initial series
            PlotOrientation.VERTICAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );//from   w w  w  . j  av  a2s .  com

    // set chart background
    chart.setBackgroundPaint(Color.white);

    // set a few custom plot features
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(new Color(0xffffe0));
    plot.setDomainGridlinesVisible(true);
    plot.setDomainGridlinePaint(Color.lightGray);
    plot.setRangeGridlinePaint(Color.lightGray);

    // set the plot's axes to display integers
    TickUnitSource ticks = NumberAxis.createIntegerTickUnits();
    NumberAxis domain = (NumberAxis) plot.getDomainAxis();
    domain.setStandardTickUnits(ticks);
    domain.resizeRange(1.1);
    domain.setLowerBound(0.5);

    NumberAxis range = (NumberAxis) plot.getRangeAxis();
    range.setStandardTickUnits(ticks);
    range.setUpperBound(range.getUpperBound() * 1.1);

    // render shapes and lines
    DeviationRenderer renderer = new DeviationRenderer(true, true);
    plot.setRenderer(renderer);
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);

    // set the renderer's stroke
    Stroke stroke = new BasicStroke(3f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_BEVEL);
    renderer.setBaseOutlineStroke(stroke);

    //TODO: render the deviation with the same color as the line
    //        renderer.setBaseFillPaint(new Color(255, 200, 200));
    //        renderer.setUseOutlinePaint(flag);
    //        renderer.setUseFillPaint(flag);

    // label the points
    NumberFormat format = NumberFormat.getNumberInstance();
    format.setMaximumFractionDigits(2);
    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);
    renderer.setBaseItemLabelGenerator(generator);
    renderer.setBaseItemLabelsVisible(true);

    //TODO: fix the visible area to show the deviation

    return chart;
}

From source file:org.dkpro.lab.reporting.ChartUtilTest.java

@Test
public void testPDF() throws Exception {
    double[][] data = new double[2][10];

    for (int n = 1; n < 10; n++) {
        data[0][n] = 1.0 / n;// w ww .j  ava2s  .  c  o  m
        data[1][n] = 1.0 - (1.0 / n);
    }

    DefaultXYDataset dataset = new DefaultXYDataset();
    dataset.addSeries("data", data);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Recall", "Precision", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.getXYPlot().setRenderer(new XYSplineRenderer());
    chart.getXYPlot().getRangeAxis().setRange(0.0, 1.0);
    chart.getXYPlot().getDomainAxis().setRange(0.0, 1.0);

    File tmp = File.createTempFile("testfile", ".pdf");
    try (OutputStream os = new FileOutputStream(tmp)) {
        ChartUtil.writeChartAsPDF(os, chart, 400, 400);
    }

    // Do not have an assert here because the creation date encoded in the PDF changes
    //        String ref = FileUtils.readFileToString(new File("src/test/resources/chart/test.pdf"),
    //                "UTF-8");
    //        String actual = FileUtils.readFileToString(tmp, "UTF-8");
    //        assertEquals(ref, actual);
}

From source file:api3.transform.PlotWave.java

public void plot(double[][] signal, String name, long samplerate) {

    frame.setTitle(name);/*from w  ww . j  a  v a  2s  .  c om*/

    XYSeries[] soundWave = new XYSeries[signal.length];
    for (int j = 0; j < signal.length; ++j) {
        soundWave[j] = new XYSeries("sygnal" + j);
        for (int i = 0; i < signal[0].length; ++i) {
            double index = (samplerate == 0) ? i : 1000.0 * (double) i / (double) samplerate;
            soundWave[j].add(index, signal[j][i]);
        }
    }

    XYSeriesCollection dataset = new XYSeriesCollection();
    for (int j = 0; j < signal.length; ++j) {
        dataset.addSeries(soundWave[j]);
    }

    JFreeChart chart = //            (samplerate ==0 )?
            //            ChartFactory.createXYBarChart(
            //            name,
            //            "prbka",
            //            false,
            //            "warto",
            //            new XYBarDataset(dataset,0.0625),
            //            PlotOrientation.VERTICAL,
            //            true,false,false)
            //            :
            ChartFactory.createXYLineChart(name, "prbka", "warto", dataset,
                    PlotOrientation.VERTICAL, true, false, false);

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

    final NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();

    slider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent event) {
            int value = slider.getValue();
            double minimum = domainAxis.getRange().getLowerBound();
            double maximum = domainAxis.getRange().getUpperBound();
            double delta = (0.1f * (domainAxis.getRange().getLength()));
            if (value < lastValue) { // left
                minimum = minimum - delta;
                maximum = maximum - delta;
            } else { // right
                minimum = minimum + delta;
                maximum = maximum + delta;
            }
            DateRange range = new DateRange(minimum, maximum);
            domainAxis.setRange(range);
            lastValue = value;
            if (lastValue == slider.getMinimum() || lastValue == slider.getMaximum()) {
                slider.setValue(SLIDER_DEFAULT_VALUE);
            }
        }

    });

    plot.addRangeMarker(new ValueMarker(0, Color.BLACK, new BasicStroke(1)));

    ChartPanel chartPanel = new ChartPanel(chart);
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4),
            BorderFactory.createEtchedBorder());
    chartPanel.setBorder(border);

    chartPanel.addMouseWheelListener(addZoomWheel());

    panel.add(chartPanel);
    JPanel dashboard = new JPanel(new BorderLayout());
    dashboard.setBorder(BorderFactory.createEmptyBorder(0, 4, 4, 4));
    dashboard.add(slider);
    panel.add(dashboard, BorderLayout.SOUTH);

    frame.getContentPane().add((JPanel) panel, BorderLayout.CENTER);

    frame.pack();
    frame.setVisible(true);
}

From source file:org.simbrain.plot.timeseries.TimeSeriesPlotPanel.java

/**
 * Initialize Chart Panel.//from  w ww.ja  v a 2 s  . c  o m
 */
public void init() {

    // Generate the graph
    chart = ChartFactory.createXYLineChart("Time series", // Title
            "Iterations", // x-axis Label
            "Value(s)", // y-axis Label
            model.getDataset(), // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    chartPanel.setChart(chart);
    chart.setBackgroundPaint(null);

    // Create chart settings listener
    model.addChartSettingsListener(new ChartSettingsListener() {
        public void chartSettingsUpdated() {

            // Handle range properties
            chart.getXYPlot().getRangeAxis().setAutoRange(model.isAutoRange());
            if (!model.isAutoRange()) {
                chart.getXYPlot().getRangeAxis().setRange(model.getRangeLowerBound(),
                        model.getRangeUpperBound());
            }

            // Handle domain properties
            if (model.isFixedWidth()) {
                chart.getXYPlot().getDomainAxis().setFixedAutoRange(model.getWindowSize());
            } else {
                chart.getXYPlot().getDomainAxis().setFixedAutoRange(-1);
                chart.getXYPlot().getDomainAxis().setAutoRange(true);
            }

        }
    });

    // Invoke an initial event in order to set default settings
    model.fireSettingsChanged();
}