package pkg;
import java.awt.Font;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PiePlot;
import org.jfree.data.general.DefaultPieDataset;
/**
* 生成饼状图(3D,不显示,只生成文件) 导入jar包
* jaxen-1.1.1.jar,jcommon-1.0.12.jar,jfreechart-1.0.9.jar
*
*/
public class Test{
public static void main(String[] args) {
// 设置数据集
DefaultPieDataset dataset = new DefaultPieDataset();
int a = 25;
int b = 35;
int c = 15;
int count = a + b + c;
dataset.setValue("超出实检上限总捆数" + "\n" + a + "根\n", a);
dataset.setValue("实检范围内总捆数" + "\n" + b + "根\n", b);
dataset.setValue("超出实检下限总捆数" + "\n" + c + "根\n", c);
// 通过工厂类生成JFreeChart对象
JFreeChart chart = ChartFactory.createPieChart3D("棒材异常磅单超重捆数信息图" + "\n"
+ a + "+" + b + "+" + c + "=" + count, dataset, true, false,
false);
PiePlot pieplot = (PiePlot) chart.getPlot();
pieplot.setLabelFont(new Font("宋体", 0, 12));
// 没有数据的时候显示的内容
pieplot.setNoDataMessage("无数据显示");
pieplot.setCircular(false);
pieplot.setLabelGap(0.02D);
FileOutputStream fos_jpg = null;
try {
try {
fos_jpg = new FileOutputStream("F:\\steelBar.jpg");
try {
ChartUtilities.writeChartAsJPEG(fos_jpg, chart, 1000, 400,
null);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} finally {
try {
fos_jpg.close();
} catch (Exception e) {
}
}
System.out.println("ok");
}
}
柳德才
13691193654
18942949207
QQ:422157370
liudecai_zan@126.com湖北-武汉-江夏-庙山