package com.walkman.jfreechart;import java.awt.Color;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;public class PieChartPicture { public static void main(String[] args)
{
// 准备数据
DefaultPieDataset dataset = new DefaultPieDataset(); dataset.setValue("关键", 2);
dataset.setValue("严重", 10);
dataset.setValue("平均", 50);
dataset.setValue("较轻", 20); // 使用ChartFactory创建图表对象
JFreeChart chart = ChartFactory.createPieChart3D("某项目某月份缺陷严重程度分析图2",
dataset, true, true, false); // 设置图表样式
PiePlot3D plot = (PiePlot3D) chart.getPlot(); // 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})", NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%"))); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})"));
// 设置背景色为白色
chart.setBackgroundPaint(Color.white);
// 指定图片的透明度(0.0-1.0)
plot.setForegroundAlpha(1.0f);
// 指定显示的饼图上圆形(false)还椭圆形(true) plot.setCircular(false); // 将生成的图表文件输出到磁盘。
FileOutputStream fos_jpg = null; try {
fos_jpg = new FileOutputStream("D:\\某项目某月份缺陷严重程度分析图.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg, 1.0f, chart, 400, 250,
null);
fos_jpg.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
乱码问题该如何解决?
解决方案 »
- getBean找不到bean,如何解决!!!!
- flash实现在线照相功能,java servlet怎么写阿??
- 如何取得<%! %>与<% %>中声名的变量?
- 一个程序员的路要怎么走???
- Unable to compile class for JSP
- 请问jsp读取xml的效率问题
- 在Jbuilder7.0中可以用Struts架构吗?
- WEB应用中一些不常用效果----和大家共享
- 如何在 JSP 页面实现数据查询分页显示?急!!!!
- 请介绍一个支持jsp程序编写软件,jb5莫提!!!!
- java mail使用问题
- 在jsp页面里把textarea传入oracle数据库,中文乱码,怎么解决?
其中FONTFACE="宋体" FONTTITLE=20
这些设置了就可以了
你百度一大堆关于jfreechart乱码问题的
import java.awt.Color;
import java.awt.Font;
import java.io.FileOutputStream;
import java.text.DecimalFormat;
import java.text.NumberFormat;import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.labels.StandardPieSectionLabelGenerator;
import org.jfree.chart.plot.PiePlot3D;
import org.jfree.data.general.DefaultPieDataset;public class PieChartPicture { public static void main(String[] args)
{
Font font = new Font("宋体",Font.PLAIN,12) ;
// 准备数据
DefaultPieDataset dataset = new DefaultPieDataset();
dataset.setValue("关键", 2);
dataset.setValue("严重", 10);
dataset.setValue("平均", 50);
dataset.setValue("较轻", 20);
// 使用ChartFactory创建图表对象
//先给个主题,将字体设置好
StandardChartTheme s = new StandardChartTheme("a");
s.setRegularFont(font);
ChartFactory.setChartTheme(s);
JFreeChart chart = ChartFactory.createPieChart3D("某项目某月份缺陷严重程度分析图2",dataset, false, false, false);
//设置标题的字体
chart.getTitle().setFont(font);
// 设置图表样式
PiePlot3D plot = (PiePlot3D) chart.getPlot();
// 图片中显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位 plot.setLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})", NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%"))); plot.setLegendLabelGenerator(new StandardPieSectionLabelGenerator(
"{0}={1}({2})"));
// 设置背景色为白色
chart.setBackgroundPaint(Color.white);
// 指定图片的透明度(0.0-1.0)
plot.setForegroundAlpha(1.0f);
// 指定显示的饼图上圆形(false)还椭圆形(true)
plot.setCircular(false); // 将生成的图表文件输出到磁盘。
FileOutputStream fos_jpg = null; try {
fos_jpg = new FileOutputStream("D:\\a.jpg");
ChartUtilities.writeChartAsJPEG(fos_jpg, 1.0f, chart, 400, 250,
null);
fos_jpg.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}