饼图:
class BChart{
public static void main(String[] args){
PieDataset dataset = getDataSet();//设置数据源
JFreeChart chart = ChartFactory.createPieChart3D(
"时延分布统计图", // chart title
dataset,// data
true,// include legend
true,
false
);
PiePlot3D plot=(PiePlot3D)chart.getPlot();
// 图片中显示百分比:默认方式
//plot.setLabelGenerator(new StandardPieSectionLabelGenerator(StandardPieToolTipGenerator.DEFAULT_TOOLTIP_FORMAT));
// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位
plot.setLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})", NumberFormat.getNumberInstance(), new DecimalFormat("0.00%")));
// 图例显示百分比:自定义方式, {0} 表示选项, {1} 表示数值, {2} 表示所占比例
plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0}={1}({2})"));
// 设置背景色为白色
chart.setBackgroundPaint(Color.white);
// 指定图片的透明度(0.0-1.0)
plot.setForegroundAlpha(1.0f);
// 指定显示的饼图上圆形(false)还椭圆形(true)
plot.setCircular(true);
// 设置图标题的字体
Font font = new Font(" 黑体",Font.CENTER_BASELINE,20);
TextTitle title = new TextTitle(" 时延分布统计图");
title.setFont(font);
chart.setTitle(title);
FileOutputStream fos_jpg = null;
try {
fos_jpg=new FileOutputStream("D://时延分布统计图.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,640,480,null);
fos_jpg.close();
} catch (Exception e) {
}
}
private static PieDataset getDataSet()//数据源构造
{
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("login.jsp",50);
dataset.setValue("reg.jsp",60);
return dataset;
}
}
曲线:
class ZChart{
public static void main(String[] args)
{
JFreeChart chart = ChartFactory.createXYLineChart("固定uri时延分布图", "历次访问点",
"时延/ms", createDataSet(special), PlotOrientation.VERTICAL, true,
true, false);
FileOutputStream fos_jpg = null;
try {
fos_jpg=new FileOutputStream("D://mao.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,640,480,null);
fos_jpg.close();
} catch (Exception e) {
}
}
private static XYSeriesCollection createDataSet() {//数据源构造方法
XYSeriesCollection seriesCollection = new XYSeriesCollection();
XYSeries series1 = new XYSeries("login.jsp");
seriesCollection.addSeries(series1);
series1.add(1, 75);
series1.add(2, 41);
series1.add(3, 39);
series1.add(4, 33);
series1.add(5, 25);
series1.add(6, 36);
seriesCollection.addSeries(series1);
return seriesCollection;
}
}