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.ufrgs.enq.jcosmo.test.VLEdiagramsGAMESS.java

public JPanel calcAcetoneWater() throws Exception {
    super.setTitle("P vs x1");
    double T = 298.15;
    setLayout(new BorderLayout());

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();
    COSMOSACCompound c1 = db.getComp("ethyl-acetate");
    COSMOSACCompound c2 = db.getComp("water");

    double[] cavityVolume = new double[2];
    cavityVolume[0] = c1.Vcosmo;/*from w  w  w .  j  a  va  2  s  .c o  m*/
    cavityVolume[1] = c2.Vcosmo;

    double[][] sigma = new double[2][];

    sigma[0] = c1.sigma;
    sigma[1] = c2.sigma;

    SigmaProfileGenerator c1Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS,
            c1.name.toLowerCase() + ".log");
    SigmaProfileGenerator c2Sigma = new SigmaProfileGenerator(SigmaProfileGenerator.FileType.GAMESS,
            c2.name.toLowerCase() + ".log");
    sigma[0] = c1Sigma.getSigmaProfile();
    sigma[1] = c2Sigma.getSigmaProfile();

    COSMOSAC cosmosac = new COSMOSAC();
    cosmosac.setParameters(cavityVolume, c1.charge, sigma);
    cosmosac.setIgnoreSG(true);
    cosmosac.setSigmaHB(COSMOSAC.SIGMAHB * 1.2);

    cosmosac.setTemperature(T);

    double[] x1 = new double[n];
    double[] x2 = new double[n];
    double[] gamma1 = new double[n];
    double[] gamma2 = new double[n];
    double[] z = new double[2];
    double[] lnGamma = new double[2];
    z[0] = 0.00;
    int j = 0;
    while (z[0] < 1.0001) {
        z[1] = 1 - z[0];
        x1[j] = z[0];
        x2[j] = z[1];
        cosmosac.setComposition(z);
        cosmosac.activityCoefficient(lnGamma);
        gamma1[j] = Math.exp(lnGamma[0]);
        gamma2[j] = Math.exp(lnGamma[1]);
        z[0] += 0.05;
        j++;
    }

    double[] Psat = new double[2];
    Psat[0] = 13000;
    Psat[1] = 3000;
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot1;
    XYSeriesCollection dataset = new XYSeriesCollection();
    XYSeries liq = new XYSeries("liquid");
    XYSeries vap = new XYSeries("vapor");
    XYSeries raoult = new XYSeries("Raoult's Law");
    for (int i = 0; i < n; i++) {
        liq.add(x1[i], P[i]);
        vap.add(y1[i], P[i]);
    }
    raoult.add(0, Psat[1]);
    raoult.add(1, Psat[0]);
    dataset.addSeries(liq);
    dataset.addSeries(vap);
    dataset.addSeries(raoult);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction: x1, y1", "P/KPa", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot1 = (XYPlot) chart.getPlot();
    plot1.getDomainAxis().setRange(new Range(0.0, 1.0));

    plot1.setDataset(dataset);

    //      XYSplineRenderer r = new XYSplineRenderer();
    //      BasicStroke stroke = new BasicStroke(2f);
    //      r.setStroke(stroke);
    //      plot1.setRenderer(r);
    //      r.setBaseShapesVisible(false);

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp1 = new JPanel(new BorderLayout());
    jp1.add(chartPanel);

    add(jp1, BorderLayout.CENTER);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp1;
}

From source file:be.nbb.demetra.dfm.output.FactorChart.java

private JFreeChart createMarginViewChart() {
    JFreeChart result = ChartFactory.createXYLineChart("", "", "", Charts.emptyXYDataset(),
            PlotOrientation.VERTICAL, false, false, false);
    result.setPadding(TsCharts.CHART_PADDING);

    XYPlot plot = result.getXYPlot();/*w w  w.j  a  v  a 2 s  . co  m*/
    plot.setDatasetRenderingOrder(DatasetRenderingOrder.FORWARD);

    LinesThickness linesThickness = LinesThickness.Thin;

    XYLineAndShapeRenderer factor = new LineRenderer(FACTOR_INDEX);
    plot.setRenderer(FACTOR_INDEX, factor);

    XYLineAndShapeRenderer filtered = new LineRenderer(FILTERED_INDEX);
    plot.setRenderer(FILTERED_INDEX, filtered);

    XYDifferenceRenderer difference = new XYDifferenceRenderer();
    difference.setAutoPopulateSeriesPaint(false);
    difference.setAutoPopulateSeriesStroke(false);
    difference.setBaseStroke(TsCharts.getNormalStroke(linesThickness));
    plot.setRenderer(DIFFERENCE_INDEX, difference);

    DateAxis domainAxis = new DateAxis();
    domainAxis.setTickMarkPosition(DateTickMarkPosition.MIDDLE);
    domainAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setDomainAxis(domainAxis);

    NumberAxis rangeAxis = new NumberAxis();
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setTickLabelPaint(TsCharts.CHART_TICK_LABEL_COLOR);
    plot.setRangeAxis(rangeAxis);

    return result;
}

From source file:Result3.java

public void createGraphs() {
    XYSeries a_data = new XYSeries("A");
    XYSeries c_data = new XYSeries("C");
    XYSeries g_data = new XYSeries("G");
    XYSeries t_data = new XYSeries("T");
    for (int i = 0; i < a.length; i++) {
        a_data.add(i, a[i]);//from w w w.j  a va  2 s . co  m
        c_data.add(i, c[i]);
        g_data.add(i, g[i]);
        t_data.add(i, t[i]);
    }

    XYSeriesCollection my_data_series = new XYSeriesCollection();
    my_data_series.addSeries(a_data);
    my_data_series.addSeries(c_data);
    my_data_series.addSeries(g_data);
    my_data_series.addSeries(t_data);

    JFreeChart XYLineChart = ChartFactory.createXYLineChart("Frequency Table", "Position", "No. of Occurences",
            my_data_series, PlotOrientation.VERTICAL, true, true, false);
    bImage1 = (BufferedImage) XYLineChart.createBufferedImage(690, 337);
    ImageIcon imageIcon1 = new ImageIcon(bImage1);
    jLabel1.setIcon(imageIcon1);

}

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

/**
 * Creates a chart.//  w  ww.j  ava2  s .  c o m
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
protected JFreeChart createChart(XYDataset dataset) {

    // create the chart...
    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...
    chart.setBackgroundPaint(Color.white);

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

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setBaseLinesVisible(false);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    rangeAxis.setAutoRangeIncludesZero(false);
    rangeAxis.setUpperMargin(0);
    rangeAxis.setLowerMargin(0);

    NumberAxis domainAxis = (NumberAxis) plot.getDomainAxis();
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    domainAxis.setAutoRangeIncludesZero(false);
    domainAxis.setUpperMargin(0);
    domainAxis.setLowerMargin(0);

    // OPTIONAL CUSTOMISATION COMPLETED.
    setXSummary(dataset);
    return chart;

}

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

/**
 * Creates a chart./*  w ww  .j  a  v  a 2  s  . c o m*/
 * 
 * @param dataset  the data for the chart.
 * 
 * @return a chart.
 */
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
    );

    chart.setBackgroundPaint(Color.white);

    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

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

    XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setBaseShapesFilled(true);
    renderer.setLegendItemLabelGenerator(new SOCRXYSeriesLabelGenerator());

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    setXSummary(dataset);
    return chart;

}

From source file:org.gephi.statistics.plugin.dynamic.DynamicNbNodes.java

public String getReport() {
    //Transform to Map
    Map<Double, Integer> map = new HashMap<Double, Integer>();
    for (Interval<Integer> interval : counts.getIntervals()) {
        map.put(interval.getLow(), interval.getValue());
    }/*w  w w  .  j  a  va2s  . co  m*/

    //Time series
    XYSeries dSeries = ChartUtils.createXYSeries(map, "Nb Nodes Time Series");

    XYSeriesCollection dataset = new XYSeriesCollection();
    dataset.addSeries(dSeries);

    JFreeChart chart = ChartFactory.createXYLineChart("# Nodes Time Series", "Time", "# Nodes", dataset,
            PlotOrientation.VERTICAL, true, false, false);

    chart.removeLegend();
    ChartUtils.decorateChart(chart);
    ChartUtils.scaleChart(chart, dSeries, false);
    String imageFile = ChartUtils.renderChart(chart, "nb-nodes-ts.png");

    NumberFormat f = new DecimalFormat("#0.000");

    String report = "<HTML> <BODY> <h1>Dynamic Number of Nodes Report </h1> " + "<hr>" + "<br> Bounds: from "
            + f.format(bounds.getLow()) + " to " + f.format(bounds.getHigh()) + "<br> Window: " + window
            + "<br> Tick: " + tick + "<br><br><h2> Number of nodes over time: </h2>" + "<br /><br />"
            + imageFile;

    /*for (Interval<Integer> count : counts) {
    report += count.toString(dynamicModel.getTimeFormat().equals(DynamicModel.TimeFormat.DOUBLE)) + "<br />";
    }*/
    report += "<br /><br /></BODY></HTML>";
    return report;
}

From source file:org.cyberoam.iview.charts.XYLine.java

/**
 * This method generates JFreeChart instance for XYLine chart with iView customization.
 * @param reportID specifies that for which report Chart is being prepared.
 * @param rsw specifies data set which would be used for the Chart
 * @param requeest used for Hyperlink generation from URL.
 * @return jfreechart instance with iView Customization.
 *//* w  w  w  . j a  v a2 s  .  c om*/
public static JFreeChart getChart(int reportID, ResultSetWrapper rsw, HttpServletRequest request) {
    ReportBean reportBean = ReportBean.getRecordbyPrimarykey(reportID);
    JFreeChart chart = null;
    try {
        ReportColumnBean reportColumnBean = null;
        GraphBean graphBean = null;
        DataLinkBean dataLinkBean = null;
        XYDataset dataset = null;
        XYSeriesCollection seriesCollection = new XYSeriesCollection();
        XYSeries series = new XYSeries(reportBean.getTitle());
        graphBean = GraphBean.getRecordbyPrimarykey(reportBean.getGraphId());//Getting GraphBean
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getXColumnId());//getting ReportColumnBean For X Axis
        String xColumnDBname = reportColumnBean.getDbColumnName();
        String xColumnName = reportColumnBean.getColumnName();
        //Wheather DataLink is Given For X Axis column
        if (reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getYColumnId());
        String yColumnDBname = reportColumnBean.getDbColumnName();
        String yColumnName = reportColumnBean.getColumnName();
        //if DataLink is not Given For X Axis column then Check of Y Axis Column
        if (dataLinkBean == null && reportColumnBean.getDataLinkId() != -1) {
            dataLinkBean = DataLinkBean.getRecordbyPrimarykey(reportColumnBean.getDataLinkId());
        }
        reportColumnBean = ReportColumnBean.getRecordByPrimaryKey(reportBean.getReportId(),
                graphBean.getZColumnId());
        String zColumnDbname = reportColumnBean.getDbColumnName();
        //Preparing DataSet
        String data = "";
        rsw.beforeFirst();
        while (rsw.next()) {
            data = rsw.getString(xColumnDBname);
            series.add(Long.parseLong((data).substring(data.length() - 2)),
                    new Long(rsw.getLong(yColumnDBname)).longValue());
        }
        seriesCollection.addSeries(series);

        dataset = seriesCollection;
        // create the chart...
        chart = ChartFactory.createXYLineChart("", // chart title
                "", // domain axis label
                "", seriesCollection, // data
                PlotOrientation.VERTICAL, // orientation
                false, // include legend
                true, // tooltips?
                false // URLs?
        );
        /*
         * Additional iView Customization.
         */
        //Set the background color for the chart...
        chart.setBackgroundPaint(Color.white);

        //Get a reference to the plot for further customisation...
        XYPlot plot = chart.getXYPlot();
        plot.setBackgroundPaint(new Color(245, 245, 245));
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setForegroundAlpha(0.7f);

        //Set the range axis to display integers only...
        NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
        if (reportColumnBean.getColumnFormat() == TabularReportConstants.BYTE_FORMATTING) {
            rangeAxis.setTickUnit(new ByteTickUnit(rangeAxis.getUpperBound() / 4));
        }
        rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());
        rangeAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        rangeAxis.setTickLabelsVisible(true);
        rangeAxis.setTickMarksVisible(false);
        rangeAxis.setAxisLineVisible(false);

        Axis domainAxis = plot.getDomainAxis();
        domainAxis.setTickLabelFont(new Font("Vandara", Font.CENTER_BASELINE, 10));
        domainAxis.setTickMarksVisible(false);
        domainAxis.setAxisLineVisible(false);

        XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
        renderer.setSeriesPaint(0, Color.DARK_GRAY);
        renderer.setSeriesStroke(0, new BasicStroke(1));
    } catch (Exception e) {
        e.printStackTrace();
    }

    return chart;
}

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

/**
 * Creates a chart./*  w w w  . j  a va 2 s.  co  m*/
 * 
 * @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 2", // chart title
            "X", // x axis label
            "Y", // y axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, 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);

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

    final StandardXYItemRenderer renderer = (StandardXYItemRenderer) plot.getRenderer();
    renderer.setPlotShapes(true);
    renderer.setShapesFilled(true);
    renderer.setItemLabelsVisible(true);
    final ItemLabelPosition p = new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.BOTTOM_CENTER,
            TextAnchor.CENTER, Math.PI / 4);
    renderer.setPositiveItemLabelPosition(p);

    // 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:gui.graph.AbstractTimeSeriesGraph.java

/**
 * Re-draws the chart with the latest data, keeps range of x axis within the time bounds set.
 *//*from www  .j a  v a 2 s  .c  o  m*/
private void updateGUI() {
    mChart = ChartFactory.createXYLineChart(mTitle, mYTitle, mXTitle, mXYData, PlotOrientation.HORIZONTAL, true,
            false, false);
    final double time = (double) TimeManager.getTime(unitTime); //units will depend on the given graph (months, days, hours, minutes...)

    final double buffer = mTimeBounds / 2;
    double lower = time - (0.9 * mTimeBounds);
    double upper = time + buffer;

    if (lower < 0.0) {
        lower = 0.0;
    }
    if (upper < mTimeBounds + buffer) {
        upper = mTimeBounds + buffer;
    }

    logger.debug(TimeManager
            .log(mTitle + ": Setting XRange: lower=" + lower + ", upper=" + upper + " Unit=" + unitTime));
    mChart.getXYPlot().getRangeAxis().setRange(lower, upper);
    setXAxisRange();
    setYAxisRange();

    if (mFirstDraw == true) {
        setChartPanel(new ChartPanel(mChart));
    } else {
        getChartPanel().setChart(mChart);
    }

    getChartPanel().setPreferredSize(getSize());
    getChartPanel().repaint();
    getChartPanel().revalidate();

    this.add(getChartPanel());

    getChartPanel().updateUI();

    mFirstDraw = false;
}

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

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

    // create the chart...
    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
    );

    chart.setBackgroundPaint(Color.white);

    // get a reference to the plot for further customisation...
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundPaint(Color.lightGray);
    plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    // renderer.setSeriesLinesVisible(0, false);
    //   renderer.setSeriesShapesVisible(1, false);
    renderer.setBaseLinesVisible(false);

    plot.setRenderer(renderer);

    // change the auto tick unit selection to integer units only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    // OPTIONAL CUSTOMISATION COMPLETED.

    return chart;

}