  // written by: Nick Tse
  // assisted by: Justin Phalon


package minoritygame;


import org.jfree.chart.*;
import org.jfree.data.category.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.function.Function2D;
import org.jfree.data.function.NormalDistributionFunction2D;
import org.jfree.data.general.DatasetUtilities;
import org.jfree.data.xy.XYDataset;

public class Graphs{
	public void CreateGraph(String Title, String Xlab, String Ylab, DefaultCategoryDataset dataset, String type)
        {
            JFreeChart chart;
            if (type.contentEquals("bar"))
            {
                chart = ChartFactory.createBarChart
                (Title,Xlab,Ylab, dataset,
                PlotOrientation.VERTICAL, false, true, false);
            }
            else
            {
                chart = ChartFactory.createLineChart
                (Title,Xlab,Ylab, dataset,
                PlotOrientation.VERTICAL, false, true, false);
            }

            ChartFrame frame = new ChartFrame(type + " Chart",chart);
	    frame.setVisible(true);
	    frame.setSize(600,350);
	}

        public XYDataset CreateNormalDataset(double mean, double std, double start, double finish, int samples)
        {
            Function2D normal = new NormalDistributionFunction2D(mean, std);
            XYDataset dataset = DatasetUtilities.sampleFunction2D(normal, start, finish, samples, "Normal");
            return dataset;
        }

        public void NormalDistributionGraph(String Title, String Xlab, String Ylab, XYDataset dataset)
        {
            JFreeChart chart = ChartFactory.createXYLineChart
            (Title,Xlab,Ylab, dataset,
            PlotOrientation.VERTICAL, true, true, false);
            ChartFrame frame = new ChartFrame("Normal Distribution Chart",chart);
	    frame.setVisible(true);
	    frame.setSize(600,350);
        }


}