package com.shu.sockets;
import java.awt.Font;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;
import com.shu.model.ExcelData;
import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class MyTest {
public static void main(String[] args) {
try {
Workbook book=Workbook.getWorkbook(new File("E:\\my.xls"));
Sheet[] sheets=book.getSheets();
List<ExcelData> list=new ArrayList<ExcelData>();
for(Sheet she : sheets){
//
ExcelData ed=null;
for(int i=0;i<she.getColumns();i++){
ed=new ExcelData();
Cell[] cells=she.getColumn(i);
ed.setColName(cells[0].getContents());
ed.setColValue(Double.valueOf(cells[1].getContents()));
list.add(ed);
}
//Style of the theme
StandardChartTheme standardChartTheme = new StandardChartTheme("CN");
//Style of the font
standardChartTheme.setExtraLargeFont(new Font(" ", Font.BOLD, 20));
//font of the list
standardChartTheme.setRegularFont(new Font(" ", Font.PLAIN, 15));
//style of tye x rax
standardChartTheme.setLargeFont(new Font(" ", Font.PLAIN, 15));
//style of the applicaion
ChartFactory.setChartTheme(standardChartTheme);
DefaultCategoryDataset data=new DefaultCategoryDataset();
for(ExcelData cel : list){
data.addValue(cel.getColValue(),"", cel.getColName());
}
JFreeChart jfc2=ChartFactory.createLineChart(she.getName()," "," ", data,PlotOrientation.VERTICAL,true,true,false);
ChartUtilities.writeChartAsJPEG(new FileOutputStream("E://"+she.getName()+".jpg"), jfc2,list.size()*40,400);
}
book.close();
System.out.println("done~");
} catch (BiffException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}