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

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

Introduction

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

Prototype

public XYSplineRenderer() 

Source Link

Document

Creates a new instance with the precision attribute defaulting to 5 and no fill of the area 'under' the spline.

Usage

From source file:graficos.Grafico1.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed

    ChartPanel panel;/*from w  ww  . j a v a 2 s .  c  om*/
    JFreeChart chart = null;

    if (l.isSelected()) {
        //Grafico de Linea
        int ban = 1; //para validar que la tabla no esta vacia o que tenga solo caracteres numericos

        XYSplineRenderer renderer = new XYSplineRenderer();// renderizador
        XYSeriesCollection dataset = new XYSeriesCollection();// variable para almacenar los datos que le enviamos para hacer el ploteo

        //Ejes x , y
        ValueAxis x = new NumberAxis();
        ValueAxis y = new NumberAxis();

        XYSeries serie = new XYSeries("Datos");//almacena conjunto de datos que vamos a graficar
        //Le paso por parametro el nombre que recibe la serie

        XYPlot plot;

        // Hago el recorrido del JTable datos y lo agrego a la serie 
        try {
            for (int fila = 0; fila < 5; fila++) {
                GraficoLinea.removeAll();

                serie.add(Float.parseFloat(String.valueOf(datos.getValueAt(fila, 0))),
                        Float.parseFloat(String.valueOf(datos.getValueAt(fila, 1))));
            }
        } catch (Exception e) {
            ban = 0;
            JOptionPane.showMessageDialog(this, e.toString());
        }

        if (ban == 1) {
            // Pasos claves para hacer el grafico de linea
            // Agrego al dataset la serie de datos.
            dataset.addSeries(serie);
            //Nombres de los ejes
            x.setLabel("Eje X");
            y.setLabel("Eje Y");
            //Ploteo pasando por parametr , el data set, los ejes y el renderer.
            plot = new XYPlot(dataset, x, y, renderer);

            chart = new JFreeChart(plot);
            chart.setTitle("Grafico de Lineas");

        }

    } else {
        if (b.isSelected()) {
            //Grafico de Barra
            DefaultCategoryDataset data = new DefaultCategoryDataset();
            // este esta hecho con datos que yo invente..

            String producto1 = "Sopa Quick";
            String producto2 = "Yerba Mate";

            String dia1 = "Dia 1";
            String dia2 = "Dia 2";
            String dia3 = "Dia 3";
            String dia4 = "Dia 4";
            String dia5 = "Dia 5";

            data.addValue(14, dia1, producto1);
            data.addValue(17, dia2, producto1);
            data.addValue(19, dia3, producto1);
            data.addValue(27, dia4, producto1);
            data.addValue(30, dia5, producto1);

            data.addValue(1, dia1, producto2);
            data.addValue(4, dia2, producto2);
            data.addValue(9, dia3, producto2);
            data.addValue(16, dia4, producto2);
            data.addValue(33, dia5, producto2);

            chart = ChartFactory.createBarChart("Grafico de Barra", "Dia", "Cantidad", data,
                    PlotOrientation.VERTICAL, true, true, true);

            CategoryPlot plot = (CategoryPlot) chart.getPlot();
            plot.setDomainGridlinesVisible(true);
        } else {

            //Grafico de Torta
            DefaultPieDataset data = new DefaultPieDataset();
            data.setValue("Categoria1", 20);
            data.setValue("Categoria2", 400);
            data.setValue("Categoria3", 60);

            chart = ChartFactory.createPieChart3D("Grafico de Torta", data, true, true, true);

        }

    }

    panel = new ChartPanel(chart);
    panel.setBounds(5, 10, 410, 400);

    if (b.isSelected()) {//Barra
        GraficoBarra.add(panel);
        GraficoBarra.repaint();
    } else {
        if (l.isSelected()) {//Linea
            GraficoLinea.add(panel);
            GraficoLinea.repaint();
        } else {
            //Torta
            GraficoTorta.add(panel);
            GraficoTorta.repaint();
        }

    }

}

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);//from  w w w .j  a  va  2 s  .  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:loci.slim2.process.interactive.ui.DefaultDecayGraph.java

/**
 * Creates the chart//  w w w.ja v  a  2  s. c o m
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @return the chart
 */
JFreeChart createCombinedChart(final int bins, final double timeInc) {

    // create empty chart data sets
    decayDataset = new XYSeriesCollection();
    residualDataset = new XYSeriesCollection();

    // make a common horizontal axis for both sub-plots
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertically combined plot
    final CombinedDomainXYPlot parent = new CombinedDomainXYPlot(timeAxis);

    // create decay sub-plot
    NumberAxis photonAxis;
    if (logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }
    final XYSplineRenderer decayRenderer = new XYSplineRenderer();
    decayRenderer.setSeriesShapesVisible(0, false);
    decayRenderer.setSeriesShapesVisible(1, false);
    decayRenderer.setSeriesLinesVisible(2, false);
    decayRenderer.setSeriesShape(2, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    decayRenderer.setSeriesPaint(0, PROMPT_COLOR);
    decayRenderer.setSeriesPaint(1, FITTED_COLOR);
    decayRenderer.setSeriesPaint(2, DECAY_COLOR);

    decaySubPlot = new XYPlot(decayDataset, null, photonAxis, decayRenderer);
    decaySubPlot.setDomainCrosshairVisible(true);
    decaySubPlot.setRangeCrosshairVisible(true);

    // add decay sub-plot to parent
    parent.add(decaySubPlot, DECAY_WEIGHT);

    // create residual sub-plot
    final NumberAxis residualAxis = new NumberAxis(RESIDUAL_AXIS_LABEL);
    final XYSplineRenderer residualRenderer = new XYSplineRenderer();
    residualRenderer.setSeriesPaint(0, RESIDUAL_COLOR);
    residualRenderer.setSeriesLinesVisible(0, false);
    residualRenderer.setSeriesShape(0, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    final XYPlot residualSubPlot = new XYPlot(residualDataset, null, residualAxis, residualRenderer);
    residualSubPlot.setDomainCrosshairVisible(true);
    residualSubPlot.setRangeCrosshairVisible(true);
    residualSubPlot.setFixedLegendItems(null);

    // add residual sub-plot to parent
    parent.add(residualSubPlot, RESIDUAL_WEIGHT);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, parent, true);
    chart.removeLegend();

    return chart;
}

From source file:loci.slim.ui.DecayGraph.java

/**
 * Creates the chart// w w w. j  a v a  2s . c  o  m
 *
 * @param bins number of bins
 * @param timeInc time increment per bin
 * @return the chart
 */
JFreeChart createCombinedChart(final int bins, final double timeInc) {

    // create empty chart data sets
    _decayDataset = new XYSeriesCollection();
    _residualDataset = new XYSeriesCollection();

    // make a common horizontal axis for both sub-plots
    final NumberAxis timeAxis = new NumberAxis(TIME_AXIS_LABEL);
    timeAxis.setLabel(UNITS_LABEL);
    timeAxis.setRange(0.0, (bins - 1) * timeInc);

    // make a vertically combined plot
    final CombinedDomainXYPlot parent = new CombinedDomainXYPlot(timeAxis);

    // create decay sub-plot
    NumberAxis photonAxis;
    if (_logarithmic) {
        photonAxis = new LogarithmicAxis(PHOTON_AXIS_LABEL);
    } else {
        photonAxis = new NumberAxis(PHOTON_AXIS_LABEL);
    }
    final XYSplineRenderer decayRenderer = new XYSplineRenderer();
    decayRenderer.setSeriesShapesVisible(0, false);
    decayRenderer.setSeriesShapesVisible(1, false);
    decayRenderer.setSeriesLinesVisible(2, false);
    decayRenderer.setSeriesShape(2, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    decayRenderer.setSeriesPaint(0, PROMPT_COLOR);
    decayRenderer.setSeriesPaint(1, FITTED_COLOR);
    decayRenderer.setSeriesPaint(2, DECAY_COLOR);

    _decaySubPlot = new XYPlot(_decayDataset, null, photonAxis, decayRenderer);
    _decaySubPlot.setDomainCrosshairVisible(true);
    _decaySubPlot.setRangeCrosshairVisible(true);

    // add decay sub-plot to parent
    parent.add(_decaySubPlot, DECAY_WEIGHT);

    // create residual sub-plot
    final NumberAxis residualAxis = new NumberAxis(RESIDUAL_AXIS_LABEL);
    final XYSplineRenderer residualRenderer = new XYSplineRenderer();
    residualRenderer.setSeriesPaint(0, RESIDUAL_COLOR);
    residualRenderer.setSeriesLinesVisible(0, false);
    residualRenderer.setSeriesShape(0, new Ellipse2D.Float(-1.0f, -1.0f, 2.0f, 2.0f));

    final XYPlot residualSubPlot = new XYPlot(_residualDataset, null, residualAxis, residualRenderer);
    residualSubPlot.setDomainCrosshairVisible(true);
    residualSubPlot.setRangeCrosshairVisible(true);
    residualSubPlot.setFixedLegendItems(null);

    // add residual sub-plot to parent
    parent.add(residualSubPlot, RESIDUAL_WEIGHT);

    // now make the top level JFreeChart
    final JFreeChart chart = new JFreeChart(null, JFreeChart.DEFAULT_TITLE_FONT, parent, true);
    chart.removeLegend();

    return chart;
}

From source file:udea.edu.com.co.grafico.Graficas.java

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    ChartPanel panel;/*from   www  .j a v  a  2 s. c  om*/
    JFreeChart chart = null;
    //GRAFICO DE LINEAS
    int validar = 1;
    XYSplineRenderer renderer = new XYSplineRenderer();
    XYSeriesCollection dataset = new XYSeriesCollection();

    ValueAxis x = new NumberAxis();
    ValueAxis y = new NumberAxis();

    XYSeries serie = new XYSeries("Datos");

    XYPlot plot;
    lineas.removeAll();
    try {
        if (columnaX != null && columnaY != null) {
            B0 = Calculos.calcularBetaCero(columnaX, columnaY);
            B1 = Calculos.calcularBetaUno(columnaX, columnaY);
            double r = Calculos.calcularR(columnaX, columnaY);
            double[][] resultados = Calculos.calcularYkEnFuncionDeXk(columnaX, B0, B1);
            for (int i = 0; i < resultados.length; i++) {
                serie.add(resultados[1][i], resultados[0][i]);
            }

            B0 = Calculos.roundDouble(B0, 4);
            B1 = Calculos.roundDouble(B1, 4);
            r = Calculos.roundDouble(r, 4);
            double rCuadrado = Calculos.roundDouble(pow(r, 2), 4);

            this.textBeta0.setText(String.valueOf(B0));
            this.textBeta1.setText(String.valueOf(B1));
            this.textErreXY.setText(String.valueOf(r));
            this.textErre2.setText(String.valueOf(rCuadrado));

            this.labelYk1.setVisible(true);
            this.textYk.setVisible(true);
            this.btnCalcularYk.setVisible(true);
        }
    } catch (Exception ex) {
        validar = 0;
    }
    if (validar == 1) {
        dataset.addSeries(serie);
        x.setLabel("Eje X");
        y.setLabel("Eje Y");
        plot = new XYPlot(dataset, x, y, renderer);
        chart = new JFreeChart(plot);
        chart.setTitle("Y = " + String.format("%.3f", B0) + " + " + String.format("%.3f", B1) + "X");
    } else {
        JOptionPane.showMessageDialog(this, "Debe llenar la tabla con datos numericos");
    }
    panel = new ChartPanel(chart);
    panel.setBounds(5, 10, 410, 350);
    lineas.add(panel);
    lineas.repaint();
}

From source file:org.ala.spatial.web.services.GDMWSController.java

public static void generateCharts123(String outputdir) {
    try {/*from w  w w.ja  va  2 s  . c  o 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:charts.Chart.java

public static JFreeChart MultipleSplineLineChart(XYDataset[] datasets, String title, String x_axis_label,
        String y_axis_label, boolean showlegend, float maxvalue, float minvalue, boolean showchart) {

    ValueAxis domainAxis = new NumberAxis(x_axis_label);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);/*from  w ww.j  ava  2 s .  c  om*/
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }

    //define o grafo combinado, determinando o label do eixo x.
    CombinedDomainXYPlot parent = new CombinedDomainXYPlot(domainAxis);

    for (int i = 0; i < datasets.length; i++) {
        XYSplineRenderer renderer = new XYSplineRenderer();
        renderer.setBaseStroke(new BasicStroke(2.0f));
        renderer.setBaseSeriesVisibleInLegend(showlegend);
        renderer.setShapesVisible(true);
        XYPlot subplot = new XYPlot(datasets[i], domainAxis, rangeAxis, renderer);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);
        parent.add(subplot, 1);
    }
    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    if (showchart) {
        JFrame chartwindow = new JFrame(title);
        chartwindow.setContentPane(jpanel);
        chartwindow.pack();
        RefineryUtilities.centerFrameOnScreen(chartwindow);
        chartwindow.setVisible(true);
    }
    return jfreechart;
}

From source file:charts.Chart.java

public static JFreeChart MultipleStepChartOverlayed(XYDataset[] datasets1, XYDataset[] datasets2, String title,
        String x_axis_label, String y_axis_label, boolean showlegend, float maxvalue, float minvalue,
        boolean showchart) {

    ValueAxis domainAxis = new NumberAxis(x_axis_label);
    domainAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    ValueAxis rangeAxis = new NumberAxis(y_axis_label);
    rangeAxis.setStandardTickUnits(NumberAxis.createStandardTickUnits());

    if (minvalue == 0 && maxvalue == 0) {
        rangeAxis.setAutoRange(true);/* w w w . j a  v a  2s.  c om*/
    } else {
        rangeAxis.setRange(minvalue, maxvalue);
    }

    //define o grafo combinado, determinando o label do eixo x.
    CombinedDomainXYPlot parent = new CombinedDomainXYPlot(domainAxis);

    for (int i = 0; i < datasets1.length; i++) {
        XYItemRenderer renderer1 = new XYStepRenderer();
        renderer1.setBaseStroke(new BasicStroke(2.0f));
        renderer1.setBaseSeriesVisibleInLegend(showlegend);
        XYPlot subplot = new XYPlot(datasets1[i], domainAxis, rangeAxis, renderer1);
        subplot.setBackgroundPaint(Color.white);
        subplot.setRangeGridlinePaint(Color.black);
        subplot.setDomainGridlinesVisible(true);

        XYSplineRenderer renderer2 = new XYSplineRenderer();
        renderer2.setSeriesPaint(0, Color.LIGHT_GRAY);
        renderer2.setBaseStroke(new BasicStroke(2.0f));
        renderer2.setShapesVisible(true);
        renderer2.setBaseSeriesVisibleInLegend(false);
        subplot.setDataset(1, datasets2[i]);
        subplot.setRenderer(1, renderer2);
        parent.add(subplot, 1);
    }
    JFreeChart jfreechart = new JFreeChart(title, parent);
    JPanel jpanel = new ChartPanel(jfreechart);
    jpanel.setPreferredSize(new Dimension(defaultwidth, defaultheight));

    if (showchart) {
        JFrame chartwindow = new JFrame(title);
        chartwindow.setContentPane(jpanel);
        chartwindow.pack();
        RefineryUtilities.centerFrameOnScreen(chartwindow);
        chartwindow.setVisible(true);
    }
    return jfreechart;
}