package com.ordobill.webapp.report;
import java.awt.Color;
import java.awt.Paint;
import java.awt.RenderingHints;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartRenderingInfo;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.entity.StandardEntityCollection;
import org.jfree.chart.plot.FastScatterPlot;
import com.ordobill.webapp.beans.Report;
public class FastScatterPlotDemo {
public static JFreeChart chatTest(Report reportBean) {
/*System.out.println(reportBean.getSampleCount());
System.out.println("표준편차-->"+reportBean.getStdDeviation());
System.out.println(reportBean.getConfidenceLevel95st());
System.out.println(reportBean.getConfidenceLevel95ed());*/
float[][] data = populateData(reportBean);
//System.out.println("demo main input->"+title);
final NumberAxis domainAxis = new NumberAxis("X");
domainAxis.setAutoRangeIncludesZero(false);
final NumberAxis rangeAxis = new NumberAxis("Y");
rangeAxis.setAutoRangeIncludesZero(false);
final FastScatterPlot plot = new FastScatterPlot(data, domainAxis, rangeAxis);
/*Paint paint = Color.;
plot.setPaint(paint);*/
final JFreeChart chart = new JFreeChart("Fast Scatter Plot", plot);
// chart.setLegend(null);
// force aliasing of the rendered content..
chart.getRenderingHints().put
(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
//파일 경로 및 이름 설정
/*String image = "C:/C1.JPEG";
String image2 = "c1.png";
//String image2 = ServletUtilities.saveChartAsPNG(chart, 300, 200,);
try {
ChartUtilities.saveChartAsJPEG(new File(image),chart,400,200,info);
ChartUtilities.saveChartAsPNG(new File(image2),chart, 300, 200);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}*/
ChartFrame frame = new ChartFrame("BarChart", chart);
frame.pack();
frame.setVisible(true);
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. *
// ****************************************************************************
/**
* Populates the data array with random values.
*/
public static float[][] populateData(Report reportBean) {
float[][] data = new float[2][reportBean.getSampleCount()];
for (int i = 0; i < data[0].length; i++) {
data[0][i] = (float) i;
//data[1][i] = reportBean.getIterationArr()[i]*100f;
data[1][i] = (float)((reportBean.getIterationArr()[i]*100f)-reportBean.getSampleAve());
//data[1][i] = 100000 + (float) Math.random();
}
/*for (int i=0;i < data[0].length;i++) {
System.out.println(((float)reportBean.getIterationArr()[i]*100f)-reportBean.getSampleAve());
data[0][i] = reportBean.getIterationArr()[i]*100f;
data[1][i] = (float)((reportBean.getIterationArr()[i]*100f)-reportBean.getSampleAve());
//System.out.println(reportBean.getIterationArr()[i]*100f);
}*/
//System.out.println(data[0].length);
return data;
}
}