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:net.footballpredictions.footballstats.swing.GoalsGraph.java

/**
 * Plot goals scored and conceded against number of matches played.
 *///  ww  w.j av  a2 s.c o  m
public void updateGraph(String teamName, LeagueSeason data) {
    XYSeriesCollection dataSet = new XYSeriesCollection();

    XYSeries forSeries = new XYSeries(teamName + ' ' + messageResources.getString("graphs.scored"));
    XYSeries againstSeries = new XYSeries(teamName + ' ' + messageResources.getString("graphs.conceded"));

    int[][] goals = data.getTeam(teamName).getGoalsData();
    for (int i = 0; i < goals.length; i++) {
        forSeries.add(i, goals[i][0]);
        againstSeries.add(i, goals[i][1]);
    }

    dataSet.addSeries(forSeries);
    dataSet.addSeries(againstSeries);

    JFreeChart chart = ChartFactory.createXYLineChart(null, // Title
            messageResources.getString("graphs.matches"), messageResources.getString("combo.GraphType.GOALS"),
            dataSet, PlotOrientation.VERTICAL, true, // Legend.
            false, // Tooltips.
            false); // URLs.
    chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    int max = Math.max(goals[goals.length - 1][0], goals[goals.length - 1][1]);
    chart.getXYPlot().getRangeAxis().setRange(0, max + 1);
    XYDifferenceRenderer renderer = new XYDifferenceRenderer();
    renderer.setSeriesPaint(0, Colours.POSITIVE); // Green.
    renderer.setPositivePaint(Colours.POSITIVE_FILL); // Translucent green.
    renderer.setSeriesPaint(1, Colours.NEGATIVE); // Red.
    renderer.setNegativePaint(Colours.NEGATIVE_FILL); // Translucent red.
    chart.getXYPlot().setRenderer(renderer);
    setChart(chart);
}

From source file:CargarEntrenamiento.grafica2.java

public grafica2() {
    datosxy.removeAllSeries();/*w ww.  j a  va 2s . com*/
    XYSeries sxy = new XYSeries("pesos");
    //sxy.add(x[0], y[0]);
    y = new double[cargarEntreno.valorentreno.length];
    y = cargarEntreno.valorentreno;
    int n = y.length;
    for (int i = 0; i < n; i++) {
        sxy.add(i, y[i]);
        // System.out.print(x[i]+"-"+i+" ");
    }
    datosxy.addSeries(sxy);
    graficaxy = ChartFactory.createXYLineChart("Grafica de Progreso", "tiempo", "RM-pesos", datosxy,
            PlotOrientation.VERTICAL, true, true, true);
    graficaxy.setBackgroundPaint(Color.white);
    XYPlot plot = (XYPlot) graficaxy.getPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

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

    XYItemRenderer r = plot.getRenderer();
    if (r instanceof XYLineAndShapeRenderer) {
        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) r;
        renderer.setBaseShapesVisible(true);
        renderer.setBaseShapesFilled(true);
        renderer.setDrawSeriesLineAsPath(true);
    }
}

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

/**
 * Creates a new demo instance.//  w  w  w .  j a v a  2 s  .  c o  m
 *
 * @param title  the frame title.
 */
public SmallNumberDemo(final String title) {

    super(title);
    final XYSeries series = new XYSeries("Small Numbers");
    series.add(1.0E-5, 1.0E-16);
    series.add(5.0E-5, 2.0E-12);
    series.add(17.3E-5, 5.0E-7);
    series.add(21.2E-5, 9.0E-6);
    final XYSeriesCollection data = new XYSeriesCollection(series);
    final JFreeChart chart = ChartFactory.createXYLineChart("Small Number Demo", "X", "Y", data,
            PlotOrientation.VERTICAL, true, true, false);
    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setStandardTickUnits(new StandardTickUnitSource());
    plot.getRangeAxis().setStandardTickUnits(new StandardTickUnitSource());

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

}

From source file:net.footballpredictions.footballstats.swing.PointsGraph.java

/**
 * Plot points earned against number of matches played.
 *//*from   w w  w  .j  av  a 2s  .  co  m*/
public void updateGraph(Object[] teams, LeagueSeason data) {
    assert teams.length > 0 : "Must be at least one team selected.";
    XYSeriesCollection dataSet = new XYSeriesCollection();
    int max = 0;
    for (Object team : teams) {
        String teamName = (String) team;
        XYSeries pointsSeries = new XYSeries(teamName);

        int[] points = data.getTeam(teamName).getPointsData(data.getMetaData().getPointsForWin(),
                data.getMetaData().getPointsForDraw());
        for (int i = 0; i < points.length; i++) {
            pointsSeries.add(i, points[i]);
        }
        max = Math.max(max, points[points.length - 1]);
        dataSet.addSeries(pointsSeries);
    }
    JFreeChart chart = ChartFactory.createXYLineChart(null, // Title
            messageResources.getString("graphs.matches"), messageResources.getString("combo.GraphType.POINTS"),
            dataSet, PlotOrientation.VERTICAL, true, // Legend.
            false, // Tooltips.
            false); // URLs.
    chart.getXYPlot().getRangeAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chart.getXYPlot().getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    chart.getXYPlot().getRangeAxis().setRange(0, max + 1);
    setChart(chart);
}

From source file:phat.sensors.accelerometer.XYAccelerationsChart.java

/**
 * Creates a new graphic to plot accelerations.
 *
 * @param title  the frame title.//from   w  ww .  j  a va2  s.c  o  m
 */
public XYAccelerationsChart(final String windowstitle, final String chartTitle, final String domainAxisLabel,
        final String rangeAxisLabel) {

    super(windowstitle);

    //Object[][][] data = new Object[3][50][2];
    xAcceleration = new XYSeries("x acc.");
    yAcceleration = new XYSeries("y acc.");
    zAcceleration = new XYSeries("z acc.");

    dataset = new XYSeriesCollection();
    dataset.addSeries(xAcceleration);
    dataset.addSeries(yAcceleration);
    dataset.addSeries(zAcceleration);

    chart = ChartFactory.createXYLineChart(chartTitle, // chart title
            domainAxisLabel, // domain axis label
            rangeAxisLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, false);

    plot = chart.getXYPlot();
    /*final NumberAxis domainAxis = new NumberAxis("x");
    final NumberAxis rangeAxis = new LogarithmicAxis("Log(y)");
    plot.setDomainAxis(domainAxis);
    plot.setRangeAxis(rangeAxis);*/
    chart.setBackgroundPaint(Color.white);
    plot.setOutlinePaint(Color.black);
    chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);
}

From source file:chart.XYChart.java

public XYChart(String applicationTitle, String chartTitle, double[] xData, double[] YDataAnalitic,
        double[] YDataNumerical1, double[] YDataNumerical2, double[] YDataNumerical3) {

    super(applicationTitle);

    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, "", "",
            createDatasetForFour(xData, YDataAnalitic, YDataNumerical1, YDataNumerical2, YDataNumerical3),
            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.RED);
    renderer.setSeriesPaint(1, Color.GREEN);
    renderer.setSeriesPaint(2, Color.YELLOW);
    renderer.setSeriesStroke(0, new BasicStroke(1.0f));
    renderer.setSeriesStroke(1, new BasicStroke(1.0f));
    renderer.setSeriesStroke(2, new BasicStroke(1.0f));
    plot.setRenderer(renderer);//from w  w  w  . j a v a2s  .  c o  m
    setContentPane(chartPanel);

    // panel.removeAll();
    //  panel.add(chartPanel);
    //  panel.validate();

}

From source file:org.ow2.clif.jenkins.chart.MovingStatChart.java

@Override
protected JFreeChart createChart() {
    XYSeriesCollection coreDataset = new XYSeriesCollection();
    coreDataset.addSeries(this.eventSerie);

    long periodMs = this.chartConfiguration.getStatisticalPeriod() * 1000L;

    XYSeriesCollection movingDataset = calculateMovingDataset(coreDataset, periodMs);
    XYSeriesCollection throughputDataset = calculateThroughputDataset(coreDataset, periodMs);

    JFreeChart chart;/*  w w w.  j  av a  2 s . c  om*/
    chart = ChartFactory
            .createXYLineChart(
                    getBasicTitle() + " "
                            + Messages.MovingChart_StatisticalPeriod(
                                    this.chartConfiguration.getStatisticalPeriod()),
                    // chart title
                    Messages.MovingChart_Time(), // x axis label
                    Messages.MovingChart_ResponseTime(), // y axis label
                    movingDataset, // data
                    PlotOrientation.VERTICAL, true, // include legend
                    true, // tooltips
                    false // urls
    );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = (XYPlot) chart.getPlot();
    configureBasicPlotProperties(plot);

    // Force the 0 on vertical axis
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(true);
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    // Force the 0 on horizontal axis
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setAutoRangeIncludesZero(true);

    attachThroughputDatasetToDedicatedAxis(throughputDataset, plot);

    // Global renderer for moving stats
    plot.setRenderer(getGlobalRenderer());

    // Dedicated Throughput renderer
    plot.setRenderer(1, getThroughputRenderer());

    return chart;
}

From source file:au.edu.jcu.kepler.hydrant.JFreeChartPlot.java

public JFreeChartPlot(PlotterBase plotterBase) {
    _plotterBase = plotterBase;/*from w  w  w.j  a  v a2s  .co  m*/
    _dataset = new XYSeriesCollection();
    _chart = ChartFactory.createXYLineChart(getName(), "", "", _dataset, PlotOrientation.VERTICAL, true, false,
            false);
    String value = plotterBase.legend.getExpression();
    _legend = new ArrayList<String>();
    if ((value != null) && !value.trim().equals("")) {
        StringTokenizer tokenizer = new StringTokenizer(value, ",");
        while (tokenizer.hasMoreTokens()) {
            _legend.add(tokenizer.nextToken().trim());
        }
    }
}

From source file:loldmg.GUI.MainFrame.java

private JFreeChart createChart(final XYDataset dataset) {

    // create the chart...
    final JFreeChart newchart = ChartFactory.createXYLineChart("Auto Attack DPS", // chart title
            "Level", // x axis label
            "Damage", // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );//  w w w  . j a v  a 2  s. c  o m

    // NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
    newchart.setBackgroundPaint(Color.GRAY);

    // get a reference to the plot for further customisation...
    final XYPlot plot = newchart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    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 newchart;

}

From source file:umontreal.iro.lecuyer.charts.MultipleDatasetChart.java

/**
 * Initializes a new <TT>MultipleDatasetChart</TT>.
 * /*from   w w w.  j  a va 2 s .  c  om*/
 */
public MultipleDatasetChart() {
    super();

    // create the chart...
    chart = ChartFactory.createXYLineChart(null, // chart title
            null, // x axis label
            null, // y axis label
            null, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tool tips
            false // urls
    );

    datasetList = new ArrayList<SSJXYSeriesCollection>();
    // Initialize axis variables
    XAxis = new Axis((NumberAxis) ((XYPlot) chart.getPlot()).getDomainAxis(), Axis.ORIENTATION_HORIZONTAL);
    YAxis = new Axis((NumberAxis) ((XYPlot) chart.getPlot()).getRangeAxis(), Axis.ORIENTATION_VERTICAL);
}