Example usage for org.jfree.chart.renderer.xy XYSplineRenderer setBaseShapesVisible

List of usage examples for org.jfree.chart.renderer.xy XYSplineRenderer setBaseShapesVisible

Introduction

In this page you can find the example usage for org.jfree.chart.renderer.xy XYSplineRenderer setBaseShapesVisible.

Prototype

public void setBaseShapesVisible(boolean flag) 

Source Link

Document

Sets the base 'shapes visible' flag and sends a RendererChangeEvent to all registered listeners.

Usage

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   ww  w . ja va2s.com*/
    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:org.ala.spatial.web.services.GDMWSController.java

public static void generateCharts123(String outputdir) {
    try {//  www . j  a  v  a  2  s. co  m
        IniReader ir = new IniReader(outputdir + "/gdm_params.txt");
        double intercept = ir.getDoubleValue("GDMODEL", "Intercept");

        // 1. read the ObservedVsPredicted.csv file
        System.out.println("Loading csv data");
        CSVReader csv = new CSVReader(new FileReader(outputdir + "ObservedVsPredicted.csv"));
        List<String[]> rawdata = csv.readAll();
        double[][] dataCht1 = new double[2][rawdata.size() - 1];
        double[][] dataCht2 = new double[2][rawdata.size() - 1];

        // for Chart 1: obs count
        int[] obscount = new int[11];
        for (int i = 0; i < obscount.length; i++) {
            obscount[i] = 0;
        }

        System.out.println("populating data");
        for (int i = 1; i < rawdata.size(); i++) {
            String[] row = rawdata.get(i);
            double obs = Double.parseDouble(row[4]);
            dataCht1[0][i - 1] = Double.parseDouble(row[6]);
            dataCht1[1][i - 1] = obs;

            dataCht2[0][i - 1] = Double.parseDouble(row[5]) - intercept;
            dataCht2[1][i - 1] = obs;

            int obc = (int) Math.round(obs * 10);
            obscount[obc]++;
        }

        DefaultXYDataset dataset1 = new DefaultXYDataset();
        dataset1.addSeries("", dataCht1);

        DefaultXYDataset dataset2 = new DefaultXYDataset();
        dataset2.addSeries("", dataCht2);

        DefaultCategoryDataset dataset3 = new DefaultCategoryDataset();
        for (int i = 0; i < obscount.length; i++) {
            String col = "0." + i + "-0." + (i + 1);
            if (i == 10) {
                col = "0.9-1.0";
            }
            dataset3.addValue(obscount[i] + 100, "col", col);
        }
        generateChartByType("Response Histogram", "Observed Dissimilarity Class", "Number of Site Pairs",
                dataset3, outputdir, "bar", "resphist");

        XYDotRenderer renderer = new XYDotRenderer();
        //Shape cross = ShapeUtilities.createDiagonalCross(3, 1);
        //renderer.setSeriesShape(0, cross);
        renderer.setDotWidth(3);
        renderer.setDotHeight(3);
        renderer.setSeriesPaint(0, Color.BLACK);

        JFreeChart jChart1 = ChartFactory.createScatterPlot(
                "Observed versus predicted compositional dissimilarity",
                "Predicted Compositional Dissimilarity", "Observed Compositional Dissimilarity", dataset1,
                PlotOrientation.VERTICAL, false, false, false);
        jChart1.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        XYPlot plot = (XYPlot) jChart1.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRenderer(0, renderer);

        NumberAxis domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        NumberAxis range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        double dMinPred = domain.getRange().getLowerBound();
        double dMaxPred = domain.getRange().getUpperBound();

        double dMinObs = range.getRange().getLowerBound();
        double dMaxObs = range.getRange().getUpperBound();

        System.out.println("1..pred.min.max: " + dMinPred + ", " + dMaxPred);

        int regressionLineSegs = 10;
        double dInc = (dMaxPred - dMinPred) / regressionLineSegs;
        double[][] dataReg1 = new double[2][regressionLineSegs + 1];
        DefaultXYDataset dsReg1 = new DefaultXYDataset();
        int i = 0;
        for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) {
            dataReg1[0][i] = d;
            dataReg1[1][i] = d;
        }
        dsReg1.addSeries("", dataReg1);
        XYSplineRenderer regressionRenderer = new XYSplineRenderer();
        regressionRenderer.setBaseSeriesVisibleInLegend(true);
        regressionRenderer.setSeriesPaint(0, Color.RED);
        regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f));
        regressionRenderer.setBaseShapesVisible(false);
        plot.setDataset(1, dsReg1);
        plot.setRenderer(1, regressionRenderer);

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/obspredissim.png"), jChart1, 600, 400);

        // For chart 3
        JFreeChart jChart2 = ChartFactory.createScatterPlot(
                "Observed compositional dissimilarity vs predicted ecological distance",
                "Predicted ecological distance", "Observed Compositional Dissimilarity", dataset2,
                PlotOrientation.VERTICAL, false, false, false);
        jChart2.getTitle().setFont(new Font(Font.MONOSPACED, Font.PLAIN, 14));

        plot = (XYPlot) jChart2.getPlot();
        plot.setBackgroundPaint(Color.WHITE);
        plot.setDomainZeroBaselineVisible(true);
        plot.setRangeZeroBaselineVisible(true);
        plot.setDomainGridlinesVisible(true);
        plot.setDomainGridlinePaint(Color.LIGHT_GRAY);
        plot.setDomainGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRangeGridlinesVisible(true);
        plot.setRangeGridlinePaint(Color.LIGHT_GRAY);
        plot.setRangeGridlineStroke(new BasicStroke(0.5F, 0, 1));
        plot.setRenderer(0, renderer);

        domain = (NumberAxis) plot.getDomainAxis();
        domain.setAutoRangeIncludesZero(false);
        domain.setAxisLineVisible(false);
        domain.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        range = (NumberAxis) plot.getRangeAxis();
        range.setAutoRangeIncludesZero(false);
        range.setAxisLineVisible(false);
        range.setLabelFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));

        dMinPred = domain.getRange().getLowerBound();
        dMaxPred = domain.getRange().getUpperBound();

        dMinObs = range.getRange().getLowerBound();
        dMaxObs = range.getRange().getUpperBound();

        System.out.println("2.pred.min.max: " + dMinPred + ", " + dMaxPred);

        regressionLineSegs = 10;
        dInc = (dMaxPred - dMinPred) / regressionLineSegs;
        dataReg1 = new double[2][regressionLineSegs + 1];
        dsReg1 = new DefaultXYDataset();
        i = 0;
        for (double d = dMinPred; d <= dMaxPred; d += dInc, i++) {
            dataReg1[0][i] = d;
            dataReg1[1][i] = (1.0 - Math.exp(-d));
        }
        dsReg1.addSeries("", dataReg1);
        regressionRenderer.setBaseSeriesVisibleInLegend(true);
        regressionRenderer.setSeriesPaint(0, Color.RED);
        regressionRenderer.setSeriesStroke(0, new BasicStroke(1.5f));
        regressionRenderer.setBaseShapesVisible(false);
        plot.setDataset(1, dsReg1);
        plot.setRenderer(1, regressionRenderer);

        System.out.println("Writing image....");
        ChartUtilities.saveChartAsPNG(new File(outputdir + "plots/dissimdist.png"), jChart2, 600, 400);

    } catch (Exception e) {
        System.out.println("Unable to generate charts 2 and 3:");
        e.printStackTrace(System.out);
    }
}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

@SuppressWarnings("deprecation")
public JPanel calcMethanolMethilAcetate() throws Exception {
    super.setTitle("P vs x1");
    double T = 25;

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("methanol");
    comps[1] = db.getComp("methyl-acetate");

    COSMOSAC cosmosac = new COSMOSAC();
    cosmosac.setComponents(comps);/*from  ww  w . j  a v a2  s . c om*/

    cosmosac.setTemperature(T + 273.15);

    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[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.5785;
    parAntoine[0][1] = 3638.27;
    parAntoine[0][2] = 239.500;
    parAntoine[1][0] = 14.2456;
    parAntoine[1][1] = 2662.78;
    parAntoine[1][2] = 219.690;

    double[] Psat = pSat(parAntoine, T);
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot2;
    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);
    plot2 = (XYPlot) chart.getPlot();
    plot2.getDomainAxis().setRange(new Range(0.0, 1.0));
    plot2.getRangeAxis().setRange(new Range(15.0, 30.0));

    plot2.setDataset(dataset);

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

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp = new JPanel(new BorderLayout());
    jp.add(chartPanel, BorderLayout.CENTER);

    add(jp);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp;
}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

@SuppressWarnings("deprecation")
public JPanel calcMethanolMethilAcetateMOPAC() throws Exception {
    super.setTitle("P vs x1");
    double T = 25;

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("methanol");
    comps[1] = db.getComp("methyl-acetate");

    COSMOSAC cosmosac = new COSMOPAC();
    cosmosac.setComponents(comps);/*  w  w w .  j  a v a  2s . c  o m*/

    cosmosac.setTemperature(T + 273.15);

    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[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.5785;
    parAntoine[0][1] = 3638.27;
    parAntoine[0][2] = 239.500;
    parAntoine[1][0] = 14.2456;
    parAntoine[1][1] = 2662.78;
    parAntoine[1][2] = 219.690;

    double[] Psat = pSat(parAntoine, T);
    double[] P = calcPx(x1, x2, gamma1, gamma2, Psat);
    double[] y1 = calcY(x1, gamma1, Psat, P);

    XYPlot plot2;
    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);
    plot2 = (XYPlot) chart.getPlot();
    plot2.getDomainAxis().setRange(new Range(0.0, 1.0));
    plot2.getRangeAxis().setRange(new Range(15.0, 30.0));

    plot2.setDataset(dataset);

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

    ChartPanel chartPanel = new ChartPanel(chart);
    JPanel jp = new JPanel(new BorderLayout());
    jp.add(chartPanel, BorderLayout.CENTER);

    add(jp);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);

    return jp;
}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

@SuppressWarnings("deprecation")
public JPanel calcEthTol() throws Exception {
    super.setTitle("P vs x1");
    double T = 60;
    setLayout(new BorderLayout());

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("ethanol");
    comps[1] = db.getComp("toluene");

    COSMOSAC cosmosac = new COSMOSAC();
    cosmosac.setComponents(comps);//w ww .java 2s  .c  om

    cosmosac.setTemperature(T + 273.15);

    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[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.8958;
    parAntoine[0][1] = 3795.17;
    parAntoine[0][2] = 230.918;
    parAntoine[1][0] = 13.9320;
    parAntoine[1][1] = 3056.96;
    parAntoine[1][2] = 217.625;

    double[] Psat = pSat(parAntoine, T);
    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.getRangeAxis().setRange(new Range(15.0, 50.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 jp = new JPanel(new BorderLayout());
    jp.add(chartPanel);

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

    return jp;
}

From source file:br.ufrgs.enq.jcosmo.test.VLEdiagrams.java

/**
 * VLE diagrams using sigma profile by MOPAC
 * // w  w  w. j  a  v  a  2  s. c  o  m
 * @return
 * @throws Exception 
 */
@SuppressWarnings("deprecation")
public JPanel calcEthTolMOPAC() throws Exception {
    super.setTitle("P vs x1");
    double T = 60;
    setLayout(new BorderLayout());

    COSMOSACDataBase db = COSMOSACDataBase.getInstance();

    COSMOSACCompound comps[] = new COSMOSACCompound[2];
    comps[0] = db.getComp("ethanol");
    comps[1] = db.getComp("toluene");

    COSMOSAC cosmosac = new COSMOPAC();
    cosmosac.setComponents(comps);

    cosmosac.setTemperature(T + 273.15);

    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[][] parAntoine = new double[3][3];
    parAntoine[0][0] = 16.8958;
    parAntoine[0][1] = 3795.17;
    parAntoine[0][2] = 230.918;
    parAntoine[1][0] = 13.9320;
    parAntoine[1][1] = 3056.96;
    parAntoine[1][2] = 217.625;

    double[] Psat = pSat(parAntoine, T);
    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.getRangeAxis().setRange(new Range(15.0, 50.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 jp = new JPanel(new BorderLayout());
    jp.add(chartPanel);

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

    return jp;
}

From source file:org.openscience.cdk.applications.taverna.basicutilities.ChartTool.java

/**
 * Creates a line chart.//from   ww w .  j  av a 2s  .c  om
 * 
 * @param title
 * @param categoryAxisLabel
 *            (X-Axis label)
 * @param valueAxisLabel
 *            (Y-Axis label)
 * @param dataset
 * @param includeZero
 *            True when zero shall be included to the axis range.
 * @return JfreeChart instance.
 */
public JFreeChart createXYLineSplineChart(String title, String categoryAxisLabel, String valueAxisLabel,
        XYDataset dataset, boolean includeZero, boolean drawShapes) {
    JFreeChart chart = ChartFactory.createXYLineChart(title, categoryAxisLabel, valueAxisLabel, dataset,
            this.orientation, this.drawLegend, false, false);
    // set the background color for the chart...
    chart.setBackgroundPaint(Color.white);
    chart.setAntiAlias(true);
    XYPlot plot = chart.getXYPlot();
    plot.setBackgroundAlpha(0.4f);
    ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setLowerMargin(0.025);
    domainAxis.setUpperMargin(0.025);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setAutoRangeIncludesZero(includeZero);
    plot.setRenderer(new XYSplineRenderer(100));
    XYSplineRenderer renderer = (XYSplineRenderer) plot.getRenderer();
    renderer.setSeriesPaint(0, Color.blue);
    renderer.setSeriesPaint(1, Color.red);
    renderer.setSeriesPaint(2, Color.green);
    renderer.setSeriesPaint(3, Color.darkGray);
    renderer.setSeriesPaint(4, Color.yellow);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseShapesVisible(drawShapes);
    renderer.setBaseShapesFilled(true);
    return chart;
}

From source file:edu.cudenver.bios.chartsvc.resource.LegendResource.java

private XYPlot buildScatterPlot(Chart chart) throws ResourceException {
    // the first series is treated as the x values
    if (chart.getSeries() == null || chart.getSeries().size() <= 0)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data series specified");

    // create the jfree chart series
    XYSeriesCollection chartData = new XYSeriesCollection();
    // use a spline renderer to make the connecting lines smooth
    XYSplineRenderer rend = new XYSplineRenderer();

    int seriesIdx = 0;
    for (Series series : chart.getSeries()) {
        XYSeries xySeries = new XYSeries(series.getLabel());

        List<Double> xList = series.getXCoordinates();
        List<Double> yList = series.getYCoordinates();
        if (xList != null && yList != null && xList.size() == yList.size()) {
            for (int i = 0; i < xList.size(); i++) {
                xySeries.add(xList.get(i), yList.get(i));
            }//  w  w  w .j a v a2s  . c o m
        }

        // set the line style
        rend.setSeriesPaint(seriesIdx, Color.BLACK);
        if (seriesIdx > 0) {
            rend.setSeriesStroke(seriesIdx, new BasicStroke(1.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                    1.0f, new float[] { (float) seriesIdx, (float) 2 * seriesIdx }, 0.0f));
        }
        // add the series to the data set
        chartData.addSeries(xySeries);
        seriesIdx++;
    }

    // turn off shapes displayed at each data point to make a smooth curve
    rend.setBaseShapesVisible(false);

    // Create the line chart
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    if (chart.getXAxis() != null) {
        Axis xAxisSpec = chart.getXAxis();
        xAxis.setLabel(xAxisSpec.getLabel());
        if (!Double.isNaN(xAxisSpec.getRangeMin()) && !Double.isNaN(xAxisSpec.getRangeMax())) {
            xAxis.setRange(xAxisSpec.getRangeMin(), xAxisSpec.getRangeMax());
        }
    }
    NumberAxis yAxis = new NumberAxis();
    if (chart.getYAxis() != null) {
        Axis yAxisSpec = chart.getYAxis();
        yAxis.setLabel(chart.getYAxis().getLabel());
        if (!Double.isNaN(yAxisSpec.getRangeMin()) && !Double.isNaN(yAxisSpec.getRangeMax())) {
            xAxis.setRange(yAxisSpec.getRangeMin(), yAxisSpec.getRangeMax());
        }
    }
    XYPlot plot = new XYPlot((XYDataset) chartData, xAxis, yAxis, rend);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    return plot;
}

From source file:edu.cudenver.bios.chartsvc.resource.ScatterPlotResource.java

/**
 * Create a JFreeChart object from the chart specification.  JFreechart provides 
 * functionality to render 2D scatter plots as jpeg images
 * /*from  ww w.j a v  a  2s. c  om*/
 * @param chart chart specification object
 * @return JFreeChart object
 * @throws ResourceException
 */
private JFreeChart buildScatterPlot(Chart chart) throws ResourceException {
    ArrayList<LineStyle> lineStyleList = chart.getLineStyleList();

    float dashedLength = 1.0f;
    float spaceLength = 1.0f;
    float thickness = 1.0f;

    // the first series is treated as the x values
    if (chart.getSeries() == null || chart.getSeries().size() <= 0)
        throw new ResourceException(Status.CLIENT_ERROR_BAD_REQUEST, "No data series specified");

    // create the jfree chart series
    XYSeriesCollection chartData = new XYSeriesCollection();
    // use a spline renderer to make the connecting lines smooth
    XYSplineRenderer rend = new XYSplineRenderer();

    int seriesIdx = 0;

    for (Series series : chart.getSeries()) {
        XYSeries xySeries = new XYSeries(series.getLabel());

        List<Double> xList = series.getXCoordinates();
        List<Double> yList = series.getYCoordinates();
        if (xList != null && yList != null && xList.size() == yList.size()) {
            for (int i = 0; i < xList.size(); i++) {
                xySeries.add(xList.get(i), yList.get(i));
            }
        }

        if (seriesIdx >= 0 && seriesIdx < lineStyleList.size()) {
            LineStyle lineStyle = lineStyleList.get(seriesIdx);
            dashedLength = (float) lineStyle.getDashLength();
            spaceLength = (float) lineStyle.getSpaceLength();
            thickness = (float) lineStyle.getWidth();
        } else {
            dashedLength = 1.0f;
            spaceLength = 1.0f;
            thickness = 1.0f;
        }

        // set the line style
        rend.setSeriesPaint(seriesIdx, Color.BLACK);

        if (seriesIdx >= 0) {
            /*rend.setSeriesStroke(seriesIdx, 
                  new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND,
                1.0f, new float[] {(float) seriesIdx, (float) 2*seriesIdx}, 0.0f));*/
            rend.setSeriesStroke(seriesIdx, new BasicStroke(thickness, BasicStroke.CAP_ROUND,
                    BasicStroke.JOIN_ROUND, 1.0f, new float[] { dashedLength, spaceLength }, 0.0f));
        }
        // add the series to the data set
        chartData.addSeries(xySeries);
        seriesIdx++;
    }

    // turn off shapes displayed at each data point to make a smooth curve
    rend.setBaseShapesVisible(false);

    // Create the line chart
    NumberAxis xAxis = new NumberAxis();
    xAxis.setAutoRangeIncludesZero(false);
    if (chart.getXAxis() != null) {
        Axis xAxisSpec = chart.getXAxis();
        xAxis.setLabel(xAxisSpec.getLabel());
        if (!Double.isNaN(xAxisSpec.getRangeMin()) && !Double.isNaN(xAxisSpec.getRangeMax())) {
            xAxis.setRange(xAxisSpec.getRangeMin(), xAxisSpec.getRangeMax());
        }
    }
    NumberAxis yAxis = new NumberAxis();
    if (chart.getYAxis() != null) {
        Axis yAxisSpec = chart.getYAxis();
        yAxis.setLabel(chart.getYAxis().getLabel());
        if (!Double.isNaN(yAxisSpec.getRangeMin()) && !Double.isNaN(yAxisSpec.getRangeMax())) {
            xAxis.setRange(yAxisSpec.getRangeMin(), yAxisSpec.getRangeMax());
        }
    }
    XYPlot plot = new XYPlot((XYDataset) chartData, xAxis, yAxis, rend);
    plot.setDomainGridlinesVisible(false);
    plot.setRangeGridlinesVisible(false);

    JFreeChart renderedChart = new JFreeChart(chart.getTitle(), JFreeChart.DEFAULT_TITLE_FONT, plot, false);
    renderedChart.setBackgroundPaint(Color.WHITE);
    if (chart.hasLegend()) {
        LegendTitle legend = new LegendTitle(plot, new ColumnArrangement(), new ColumnArrangement());
        legend.setFrame(BlockBorder.NONE);
        legend.setPosition(RectangleEdge.BOTTOM);
        renderedChart.addLegend(legend);
    }

    return renderedChart;
}