/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.awt.Color;

import javax.swing.JPanel;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.xy.XYDataset;


/**
 *
 * @author Christophe HAVARD
 */
public class Courbe {

    private ChartPanel chartPanel;

	/**
     * Creates a new Courbe.
     *
     * @param frametitle  the frame title.
     * @param dataset the dataset to draw
     * @param chartTitle le titre parle de lui-meme
     * @param xlabel
     * @param ylabel
     */
    public Courbe(final String frameTitle, final XYDataset dataset, String chartTitle, String xlabel, String ylabel) {

        //super(frameTitle);
        final JFreeChart chart = createChart(dataset, chartTitle, xlabel, ylabel);
        chartPanel = new ChartPanel(chart);
        chartPanel.setPreferredSize(new java.awt.Dimension(600, 450));
        //setContentPane(chartPanel);
    }



    /**
     * Creates a chart.
     *
     * @param dataset  the data for the chart.
     *
     * @return a chart.
     */
    private JFreeChart createChart(final XYDataset dataset, final String title, final String xlabel, final String ylabel) {

        // create the chart...
        final JFreeChart chart = ChartFactory.createXYLineChart(
            title,      // chart title
            xlabel,                      // x axis label
            ylabel,                      // 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);
        return chart;

    }

    // ****************************************************************************
    // * JFREECHART DEVELOPER GUIDE                                               *
    // * The JFreeChart Developer Guide, written by David Gilbert, is available   *
    // * to purchase from Object Refinery Limited:                                *
    // *                                                                          *
    // * http://www.object-refinery.com/jfreechart/guide.html                     *
    // *                                                                          *
    // * Sales are used to provide funding for the JFreeChart project - please    *
    // * support us so that we can continue developing free software.             *
    // ****************************************************************************

    /**
     * Permet d'afficher la courbe dans le panel specifie
     *
     * @param panel Le panel dans lequel on veut afficher notre courbe
     * 
     */
    public void affiche(JPanel panel) {
        //this.pack();
        //RefineryUtilities.centerFrameOnScreen(this);
        panel.add(chartPanel);
        //this.setVisible(true);
    }

}
