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:br.com.ant.system.util.ChartUtil.java

public void createCaminhoPercorrido(EstatisticaColetor estatisticaColetor) {

    // Create a simple XY chart

    JFrame frame = new JFrame();

    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();

    Map<Cidade, List<Estatistica>> mapformigasEstatisticas = new HashMap<Cidade, List<Estatistica>>();
    for (Estatistica e : estatisticaColetor.getEstatisticas()) {
        if (mapformigasEstatisticas.containsKey(e.getCidadeInicial())) {
            mapformigasEstatisticas.get(e.getCidadeInicial()).add(e);
        } else {/*from w ww .  ja v  a 2  s.  c  o  m*/
            List<Estatistica> lista = new ArrayList<Estatistica>();
            lista.add(e);

            mapformigasEstatisticas.put(e.getCidadeInicial(), lista);
        }
    }

    Set<Cidade> cidades = mapformigasEstatisticas.keySet();
    for (Cidade c : cidades) {
        // for (int i = 0; i < 2; i++) {
        List<Estatistica> list = (List<Estatistica>) mapformigasEstatisticas.get(c);

        XYSeries series = new XYSeries(c.getNome());
        dataset.addSeries(series);

        for (Estatistica e : list) {
            if (e.getFormigaId() == 1) {
                series.add(e.getIteracao(), e.getDistanciaPercorrida());
            }
        }
    }

    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("", "Iterao", "Distancia (Km)", dataset,
            PlotOrientation.VERTICAL, true, true, false);
    frame.getContentPane().add(new ChartPanel(chart));

    frame.setPreferredSize(new Dimension(600, 600));
    frame.setMinimumSize(new Dimension(600, 600));
    frame.setMaximumSize(new Dimension(600, 600));
    frame.setVisible(true);

    try {
        ChartUtilities.saveChartAsJPEG(new File("chart.jpg"), chart, 500, 300);
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
    }
}

From source file:chart.JChartSegment.java

/**
 * Creates a sample chart.//from  w  w w .  j  a  v a  2  s .  c o  m
 *
 * @param dataset the dataset.
 *
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset, List<NSubsequence> subsequence) {
    final JFreeChart chart = ChartFactory.createXYLineChart("Test", "Time", "Value", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(Color.WHITE);
    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);
    MyRender renderer = new MyRender(dataset, subsequence);
    plot.setRenderer(renderer);
    renderer.setSeriesShapesVisible(0, false);
    chart.setBackgroundPaint(Color.white);
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);
    return chart;
}

From source file:celeste.Celeste.java

public void generarGrafica(XYSeriesCollection coleccion, boolean shapes) {
    JFreeChart grafica;//w  ww  .j  ava 2s.  c o  m

    grafica = ChartFactory.createXYLineChart("", "", "", coleccion, PlotOrientation.HORIZONTAL, true, true,
            false);
    // configuracion de la grafica
    XYPlot xyplot = (XYPlot) grafica.getPlot();
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    int n = coleccion.getSeriesCount();
    for (int l = 1; l < n; l = l + 2) {
        xylineandshaperenderer.setSeriesShape(l, new Ellipse2D.Double(-3 + l, -3 + l, 15, 15));
        xylineandshaperenderer.setSeriesShapesVisible(l, shapes);
    }

    //generacion ventana grafica
    ChartPanel Panel = new ChartPanel(grafica);
    JFrame Ventana = new JFrame("JFreeChart");
    Ventana.getContentPane().add(Panel);
    Ventana.pack();
    Ventana.setVisible(true);
    Ventana.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
}

From source file:chart.JChart.java

/**
 * Creates a sample chart.//from  ww  w .ja  v a 2  s .com
 *
 * @param dataset the dataset.
 *
 * @return A sample chart.
 */
private JFreeChart createChart(final XYDataset dataset, List<NSubsequence> anomalies) {
    final JFreeChart chart = ChartFactory.createXYLineChart("Test", "Time", "Value", dataset,
            PlotOrientation.VERTICAL, false, false, false);
    chart.setBackgroundPaint(Color.WHITE);

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

    final XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.white);
    //        plot.setRangeGridlinePaint(Color.white);
    //        plot.setAxisOffset(new Spacer(Spacer.ABSOLUTE, 5.0, 5.0, 5.0, 5.0));
    plot.setDomainCrosshairVisible(true);
    plot.setRangeCrosshairVisible(true);

    //      final XYItemRenderer renderer = plot.getRenderer();
    MyRender renderer = new MyRender(dataset, anomalies);
    plot.setRenderer(renderer);
    renderer.setSeriesShapesVisible(0, false);
    chart.setBackgroundPaint(Color.white);
    //        DateAxis axis = (DateAxis) plot.getDomainAxis();
    //        axis.setDateFormatOverride(new SimpleDateFormat("S"));
    NumberAxis yAxis = (NumberAxis) plot.getRangeAxis();
    yAxis.setAutoRangeIncludesZero(false);

    return chart;
}

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

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

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

    chart.setBackgroundPaint(Color.white);

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

    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);

    plot.setDomainCrosshairVisible(true);
    plot.setDomainCrosshairLockedOnData(true);
    plot.setRangeCrosshairVisible(true);
    plot.setRangeCrosshairLockedOnData(true);

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setShapesFilled(true);

    // 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:com.itemanalysis.jmetrik.graph.nicc.NonparametricCurvePanel.java

private void createChart(String name, String title, String xLabel, String yLabel, double minScore,
        double maxScore) {
    XYSeriesCollection dataset = new XYSeriesCollection();
    final JFreeChart chart = ChartFactory.createXYLineChart(title, // chart title
            xLabel, // x axis label
            yLabel, // y axis label
            dataset, // data
            chartOrientation, // chart orientation
            showLegend, // include legend
            true, // tooltips
            false // urls
    );//from   w ww . j av  a 2 s  .co  m

    if (showLegend) {
        LegendTitle chartTitle = chart.getLegend();
        chartTitle.setPosition(legendPosition);
    }

    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);

    //        //can use this code to fix the number of tick marks on the y-axis
    //        NumberFormat myFormatter = new DecimalFormat("#.0");
    //        NumberAxis yaxis = (NumberAxis)plot.getRangeAxis();
    //        yaxis.setTickUnit(new NumberTickUnit(.1, myFormatter));

    ChartPanel panel = new ChartPanel(chart);
    panel.getPopupMenu().addSeparator();
    panel.setPreferredSize(new Dimension(width, height));

    //        this.addLocalEPSMenuItem(this, panel.getPopupMenu(), chart);//remove this line for public release versions

    chart.setPadding(new RectangleInsets(20.0, 5.0, 20.0, 5.0));
    charts.put(name, chart);

    JPanel subPanel = new JPanel();//additional panel needed to prevent gridlayout from stretching graph
    subPanel.add(panel);
    subPanel.setBackground(Color.WHITE);
    this.add(subPanel);

}

From source file:nl.umcg.qube.ui.StatisticsPanel.java

public StatisticsPanel(CAGPanel cag_panel) {
    super(new BorderLayout());
    cagPanel = cag_panel;//w  ww. j a v  a 2  s . c  om
    cagPanel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent arg0) {
            // redrawing the chart during sequence viewing is very slow
            // don't update it therefore.
            if (chart != null && !cagPanel.sequenceRunning()) {
                chart.getXYPlot().clearDomainMarkers();
                chart.getXYPlot().addDomainMarker(new ValueMarker(cagPanel.getCurrentFrameNo() + 1));
            }
        }
    });

    JPanel commandPanel = new JPanel();

    JButton calc = new JButton("Recalculate");
    calc.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            recalc();
        }
    });
    commandPanel.add(calc);

    blushLabel = new JLabel("");
    commandPanel.add(blushLabel);

    add(commandPanel, BorderLayout.NORTH);

    dataSet = new DefaultXYDataset();
    chart = ChartFactory.createXYLineChart("Blush value", "Frame no.", "arbitrary units", dataSet,
            PlotOrientation.VERTICAL, true, false, false);
    chartPanel = new ChartPanel(chart);
    add(chartPanel);
}

From source file:LineChartDemo6.java

/**
 * Creates a chart./*  w w w  .ja  v a  2s  .  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("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:Servizi.GraficoJ.java

/**
 *
 * Metodo deputato alla creazione del grafico.
 *
 * @param dataset il dataset creato dal metodo createDataset
 *
 * @return il grafico./*from www. j av a  2  s  .co m*/
 *
 */
private JFreeChart createChart(final XYDataset dataset) {

    final JFreeChart chart = ChartFactory.createXYLineChart("Grafico a Linea", //titolo

            "n individuo", //label asse delle X

            "Valore Funzione Fitness", //label asse dell Y

            dataset, // sorgente dei dati

            PlotOrientation.VERTICAL, //orientamento del grafico

            true, // mostra la legenda

            true, //usa i tooltip

            false);

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

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, true);

    plot.setRenderer(renderer);

    renderer.setBaseShapesVisible(true);

    renderer.setBaseShapesFilled(true);

    NumberFormat format = NumberFormat.getNumberInstance();

    format.setMaximumFractionDigits(2);

    XYItemLabelGenerator generator = new StandardXYItemLabelGenerator(
            StandardXYItemLabelGenerator.DEFAULT_ITEM_LABEL_FORMAT, format, format);

    renderer.setBaseItemLabelGenerator(generator);

    renderer.setBaseItemLabelsVisible(true);

    return chart;

}

From source file:org.fhcrc.cpl.toolbox.gui.chart.PanelWithLineChart.java

protected void init() {
    dataset = new XYSeriesCollection();
    renderer = new StandardXYItemRenderer();
    renderer.setPlotLines(true);/*from  w ww . j  a v a2 s.  com*/
    renderer.setBaseShapesVisible(false);

    //set all possible series to the default shape
    for (int i = 0; i < 10; i++)
        renderer.setSeriesShape(i, defaultShape);

    XYToolTipGenerator toolTipGenerator = new XYToolTipGenerator() {
        public String generateToolTip(XYDataset xyDataset, int s, int i) {
            double X = Math.round(xyDataset.getXValue(s, i) * 1000.0) / 1000.0;
            double Y = Math.round(xyDataset.getYValue(s, i) * 1000.0) / 1000.0;

            return "(" + X + ", " + Y + ")";
        }
    };

    //dhmay adding for jfreechart 1.0.6 upgrade.  If this isn't here, we get a
    //nullPointerException in XYBarRenderer.drawItemLabel
    renderer.setBaseItemLabelGenerator(new NullLabelGenerator());

    renderer.setSeriesItemLabelsVisible(0, true);
    renderer.setBaseToolTipGenerator(toolTipGenerator);

    _chart = ChartFactory.createXYLineChart(null, null, null, dataset, PlotOrientation.VERTICAL, true, true,
            false);

    _chart.getXYPlot().setRenderer(renderer);
    init(_chart);
}