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:edu.memphis.ccrg.lida.framework.gui.panels.ActivationChartPanel.java

/** Creates new form JChartGuiPanel */
public ActivationChartPanel() {
    chart = ChartFactory.createXYLineChart("", "Tick", "Activation", dataset, PlotOrientation.VERTICAL, true,
            true, false);/* ww w .j  a  v  a 2  s .c  om*/
    chart.setBackgroundPaint(new Color(238, 233, 233));
    XYPlot plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
    plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    initComponents();
}

From source file:com.planetmayo.debrief.satc.util.StraightLineCullingTestForm.java

private void createChart() {
    collections = new XYSeriesCollection();
    chart = ChartFactory.createXYLineChart("main", "x", "y", collections, PlotOrientation.VERTICAL, false,
            false, false);/* ww  w  .j a v a  2s .  c  o  m*/

    ChartPanel panel = new ChartPanel(chart);
    panel.setPreferredSize(new Dimension(800, 600));
    setContentPane(panel);
}

From source file:AsymptoticFreedom.GraphViewPanel.java

public JFreeChart getResultChart() {
    // XY ?//ww  w . j  a v  a2s .co m
    int quark_size = ViewPanel.quark_list.size();
    if (quark_size < 2)
        return new JFreeChart(new XYPlot());

    // XY Dataset  
    XYSeriesCollection data = new XYSeriesCollection();
    //System.out.println(series.get(0).getY(30));
    for (XYSeries s : series) {
        data.addSeries(s);
    }

    final JFreeChart chart = ChartFactory.createXYLineChart("Potential", "Distance", "Potential", data,
            PlotOrientation.VERTICAL, true, true, false);
    chart.setTitle("Potential of quarks"); //  ?
    XYPlot plot = (XYPlot) chart.getPlot();
    //plot.addRangeMarker(new ValueMarker(15,Color.RED,new BasicStroke(2.0f)));
    for (int i = 0; i < quark_size; i++) {
        for (int j = i + 1; j < quark_size; j++) {
            Quark quark1 = ViewPanel.quark_list.get(i);
            Quark quark2 = ViewPanel.quark_list.get(j);
            double distance = quark1.pos.distance(quark2.pos);
            double value = quark1.calculatePotential(quark2);
            String anno_title = String.format("V_ %c-%c", quark1.color.charAt(0), quark2.color.charAt(0));
            //System.out.println(anno_title);
            XYPointerAnnotation pointer = new XYPointerAnnotation(anno_title, distance, value,
                    3.0 * Math.PI / 4.0);
            plot.addAnnotation(pointer);
        }
    }
    plot.getRangeAxis().setRange(-500, 4000);
    return chart;
}

From source file:org.dkpro.tc.ml.report.util.ScatterplotRenderer.java

@Override
public void write(OutputStream aStream) throws IOException {
    JFreeChart chart = ChartFactory.createXYLineChart("Scatterplot", "Gold", "Prediction", aDataset,
            PlotOrientation.VERTICAL, false, false, false);

    XYDotRenderer renderer = new XYDotRenderer();
    renderer.setDotHeight(2);/*from w w  w.j  a  va 2 s . c  o m*/
    renderer.setDotWidth(2);

    double padding = (max - min) / 10;

    chart.getXYPlot().setRenderer(renderer);
    chart.getXYPlot().getRangeAxis().setRange(min - padding, max + padding);
    chart.getXYPlot().getDomainAxis().setRange(min - padding, max + padding);
    ChartUtil.writeChartAsPDF(aStream, chart, 400, 400);
}

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

public static JFreeChart createChart(XYDataset xydataset) {
    JFreeChart jfreechart = ChartFactory.createXYLineChart("Normal Distribution Demo 2", "X", "Y", xydataset,
            PlotOrientation.VERTICAL, true, true, false);
    XYPlot xyplot = (XYPlot) jfreechart.getPlot();
    xyplot.setDomainZeroBaselineVisible(true);
    xyplot.setRangeZeroBaselineVisible(true);
    xyplot.setDomainPannable(true);//from   w w w. j  a  va2 s  .c o m
    xyplot.setRangePannable(true);
    ValueAxis valueaxis = xyplot.getDomainAxis();
    valueaxis.setLowerMargin(0.0D);
    valueaxis.setUpperMargin(0.0D);
    XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer) xyplot.getRenderer();
    xylineandshaperenderer.setDrawSeriesLineAsPath(true);
    xylineandshaperenderer.setSeriesStroke(0, new BasicStroke(1.5F));
    xylineandshaperenderer.setSeriesStroke(1, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 4F }, 0.0F));
    xylineandshaperenderer.setSeriesStroke(2,
            new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 6F, 4F, 3F, 3F }, 0.0F));
    xylineandshaperenderer.setSeriesStroke(3, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] { 4F, 4F }, 0.0F));
    XYPointerAnnotation xypointerannotation = new XYPointerAnnotation(" = -2.0, \262 = 0.5", -2D,
            0.56399999999999995D, 3.9269908169872414D);
    xypointerannotation.setLabelOffset(4D);
    xypointerannotation.setTextAnchor(TextAnchor.BOTTOM_RIGHT);
    xypointerannotation.setBackgroundPaint(Color.yellow);
    xyplot.addAnnotation(xypointerannotation);
    XYPointerAnnotation xypointerannotation1 = new XYPointerAnnotation(" = 0.0, \262 = 0.2",
            0.22500000000000001D, 0.80000000000000004D, 0.0D);
    xypointerannotation1.setLabelOffset(4D);
    xypointerannotation1.setTextAnchor(TextAnchor.CENTER_LEFT);
    xypointerannotation1.setBackgroundPaint(new Color(0, 0, 255, 63));
    xyplot.addAnnotation(xypointerannotation1);
    XYPointerAnnotation xypointerannotation2 = new XYPointerAnnotation(" = 0.0, \262 = 1.0", 0.75D,
            0.29999999999999999D, 5.497787143782138D);
    xypointerannotation2.setLabelOffset(4D);
    xypointerannotation2.setTextAnchor(TextAnchor.HALF_ASCENT_LEFT);
    xypointerannotation2.setBackgroundPaint(new Color(255, 0, 0, 63));
    xyplot.addAnnotation(xypointerannotation2);
    XYPointerAnnotation xypointerannotation3 = new XYPointerAnnotation(" = 0.0, \262 = 5.0", 3D,
            0.074999999999999997D, 4.7123889803846897D);
    xypointerannotation3.setLabelOffset(4D);
    xypointerannotation3.setTextAnchor(TextAnchor.BOTTOM_CENTER);
    xypointerannotation3.setBackgroundPaint(new Color(0, 255, 0, 63));
    xyplot.addAnnotation(xypointerannotation3);
    return jfreechart;
}

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

/**
 * Creates a new demo.//from   www .j av  a2s . c  om
 *
 * @param title  the frame title.
 */
public LineChartDemo4(final String title) {

    super(title);

    // create a dataset...
    final XYDataset dataset = new SampleXYDataset();

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

    final XYPlot plot = chart.getXYPlot();
    plot.getDomainAxis().setLowerMargin(0.0);
    plot.getDomainAxis().setUpperMargin(0.0);

    // add the chart to a panel...
    final ChartPanel chartPanel = new ChartPanel(chart);
    chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));
    setContentPane(chartPanel);

}

From source file:org.uncommons.maths.demo.GraphPanel.java

public void generateGraph(String title, Map<Double, Double> observedValues, Map<Double, Double> expectedValues,
        double expectedMean, double expectedStandardDeviation, boolean discrete) {
    XYSeriesCollection dataSet = new XYSeriesCollection();
    XYSeries observedSeries = new XYSeries("Observed");
    dataSet.addSeries(observedSeries);/*from  w  w w  . ja  va2s  . c  o m*/
    XYSeries expectedSeries = new XYSeries("Expected");
    dataSet.addSeries(expectedSeries);

    for (Map.Entry<Double, Double> entry : observedValues.entrySet()) {
        observedSeries.add(entry.getKey(), entry.getValue());
    }

    for (Map.Entry<Double, Double> entry : expectedValues.entrySet()) {
        expectedSeries.add(entry.getKey(), entry.getValue());
    }

    JFreeChart chart = ChartFactory.createXYLineChart(title, "Value", "Probability", dataSet,
            PlotOrientation.VERTICAL, true, false, false);
    XYPlot plot = (XYPlot) chart.getPlot();
    if (discrete) {
        // Render markers at each data point (these discrete points are the
        // distibution, not the lines between them).
        plot.setRenderer(new XYLineAndShapeRenderer());
    } else {
        // Render smooth lines between points for a continuous distribution.
        XYSplineRenderer renderer = new XYSplineRenderer();
        renderer.setBaseShapesVisible(false);
        plot.setRenderer(renderer);
    }

    chartPanel.setChart(chart);
}

From source file:com.googlecode.logVisualizer.chart.LineChartBuilder.java

private JFreeChart createChart(final XYDataset dataset) {
    final JFreeChart chart = ChartFactory.createXYLineChart(getTitle(), xLable, yLable, dataset,
            PlotOrientation.VERTICAL, isIncludeLegend(), true, false);
    final XYPlot plot = (XYPlot) chart.getPlot();

    double lastXValue = 0;
    if (dataset.getSeriesCount() > 0)
        lastXValue = dataset.getXValue(0, dataset.getItemCount(0) - 1);

    plot.setDomainAxis(new FixedZoomNumberAxis(lastXValue));
    plot.getDomainAxis().setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setBackgroundPaint(Color.white);
    plot.setDomainGridlinePaint(Color.black);
    plot.setRangeGridlinePaint(Color.black);
    plot.setNoDataMessage("No data available");
    if (dataset.getSeriesCount() > 0)
        ((NumberAxis) plot.getDomainAxis()).setUpperBound(lastXValue);
    ((NumberAxis) plot.getRangeAxis()).setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    final XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    for (int i = 0; i < dataset.getSeriesCount(); i++) {
        renderer.setSeriesShapesVisible(i, false);
        renderer.setSeriesStroke(i, new BasicStroke(2));
    }//  w  w w .j  a va2 s . co m
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator());
    plot.setRenderer(renderer);

    return chart;
}

From source file:no.uio.medicine.virsurveillance.charts.XYLineChart_AWT.java

public XYLineChart_AWT(String applicationTitle, String chartTitle, String xTitle, String yTitle,
        ArrayList<ArrayList<Float>> dataPoints, ArrayList<ArrayList<Float>> xAxis, ArrayList<String> titles) {
    super(applicationTitle);

    this.xAxis = xAxis;
    this.dataPoints = dataPoints;
    this.titles = titles;

    if (this.dataPoints.size() != xAxis.size() && this.dataPoints.size() != titles.size()) {
        System.out.println("Error: Data size not match");
    }//from   w  ww .j  av  a  2s.  c  om

    this.chartTitle = chartTitle;
    this.xAxisTitle = xTitle;
    this.yAxisTitle = yTitle;

    JFreeChart xylineChart = ChartFactory.createXYLineChart(chartTitle, this.yAxisTitle, this.xAxisTitle,
            createDataset(this.dataPoints, this.xAxis, this.titles), PlotOrientation.VERTICAL, true, true,
            false);

    this.chartPanel = new ChartPanel(xylineChart);
    this.chartPanel.setPreferredSize(new java.awt.Dimension(560, 367));
    this.plot = xylineChart.getXYPlot();
    this.renderer = new XYLineAndShapeRenderer();

    for (int i = 0; i < this.dataPoints.size(); i++) {
        this.renderer.setSeriesPaint(i, getColor(i));
    }

    //renderer.setSeriesStroke(0, new BasicStroke(4.0f));
    //renderer.setSeriesStroke(1, new BasicStroke(3.0f));
    //renderer.setSeriesStroke(2, new BasicStroke(2.0f));JOU
    this.plot.setRenderer(this.renderer);
    this.setContentPane(this.chartPanel);
    this.setDefaultCloseOperation(HIDE_ON_CLOSE);

}

From source file:gestionelectrica.VentanaEjemploGraf.java

private void rellenar(JPanel jp) {
    // Create a simple XY chart
    XYSeries series = new XYSeries("EC");
    series.add(1, 1);/*  w ww .ja  va2  s  .  co  m*/
    series.add(1, 2);
    series.add(2, 1);
    series.add(3, 9);
    series.add(4, 10);
    series.add(7, 15);
    series.add(10, 6);
    // Add the series to your data set
    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(series);
    // Generate the graph
    JFreeChart chart = ChartFactory.createXYLineChart("Energa comprada", // Title
            "hora", // x-axis Label
            "KWh", // y-axis Label
            dataset, // Dataset
            PlotOrientation.VERTICAL, // Plot Orientation
            true, // Show Legend
            true, // Use tooltips
            false // Configure chart to generate URLs?
    );
    JFreeChart pieChart = ChartFactory.createXYLineChart("EJEMPLOOOO", "Category", "Score", createDataset(),
            PlotOrientation.VERTICAL, true, true, false);

    System.out.println(System.getProperty("user.home"));
    System.out.println(System.getProperty("java.io.tmpdir"));
    System.out.println(System.getProperties());
    File f = new File(System.getProperty("java.io.tmpdir") + "\\chart.jpg");
    try {
        ChartUtilities.saveChartAsJPEG(f, chart, jp.getWidth(), jp.getHeight());
    } catch (IOException e) {
        System.err.println("Problem occurred creating chart.");
        System.err.println(e.getMessage());
    }
    // Adding chart into a chart panel
    //ChartPanel chartPanel = new ChartPanel(pieChart);

    // settind default size
    //chartPanel.setPreferredSize(new java.awt.Dimension(500, 270));

    // add to contentPane
    //setContentPane(chartPanel);
    //jPanel1.add(chartPanel);
    ImageIcon ic = new ImageIcon(f.getAbsolutePath());
    ImagePanel panel = new ImagePanel(ic.getImage(), jp.getWidth(), jp.getHeight());
    jp.add(panel);
    /*jPanel1.repaint();
    jPanel1.updateUI();
    jPanel1.validate();*/

    if (f.delete())
        System.out.println("BORRADO CORRECTAMENTE");
    else
        System.err.println("NO SE PUDO BORRAR");
}