先给出我测试类的代码 该类的编码已经设置为GBK了
package com.test.jfreechart;import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;public class JFreeChartTest {
public static void main(String[] args) {
// 定义数据集
DefaultPieDataset dpd = new DefaultPieDataset(); // 往数据集里面加入数据
dpd.setValue("管理人员", 25);
dpd.setValue("市场人员", 20);
dpd.setValue("开发人员", 45);
dpd.setValue("其他人员", 10); // 用工厂类创建饼图
JFreeChart chart = ChartFactory.createPieChart("公司人员结构图", dpd, true,
true, false); // 在Swing中显示该饼图
ChartFrame chartFrame = new ChartFrame("公司人员结构图", chart); chartFrame.pack(); chartFrame.setVisible(true);
}
}
运行结果:
package com.test.jfreechart;import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartFrame;
import org.jfree.chart.JFreeChart;
import org.jfree.data.general.DefaultPieDataset;public class JFreeChartTest {
public static void main(String[] args) {
// 定义数据集
DefaultPieDataset dpd = new DefaultPieDataset(); // 往数据集里面加入数据
dpd.setValue("管理人员", 25);
dpd.setValue("市场人员", 20);
dpd.setValue("开发人员", 45);
dpd.setValue("其他人员", 10); // 用工厂类创建饼图
JFreeChart chart = ChartFactory.createPieChart("公司人员结构图", dpd, true,
true, false); // 在Swing中显示该饼图
ChartFrame chartFrame = new ChartFrame("公司人员结构图", chart); chartFrame.pack(); chartFrame.setVisible(true);
}
}
运行结果:
解决方案 »
- hibernate 配置文件问题请教一下
- 将map封装到json对象报net.sf.json.JSONException: java.lang.reflect.InvocationTargetExcep
- 如何记录用户的操作
- mysql,oracle之间同步表数据
- 急!!!!!!!!!!!!Linux下部署DNS和sendmail的问题??????????
- 问一个hibernate关联插入数据的问题 急
- getsource和getservletrequest
- 請教大蝦,如何用jacob將office 2007中的文件打開,另存
- 跪求大神,java调用C#WebService中文乱码?
- jboss的 http://localhost:8080/web-console/ 左边框部分出不来,是何原因?
- put请求中,如何添加参数(数据)
- applet或swt的东西可以放到webapp中吗
图片在这里 上面的img是不小心放错的
//设置字体大小,形状
Font font = new Font("宋体", Font.BOLD, 16);
TextTitle title = new TextTitle("JFreeChart时间曲线序列图", font);
//副标题
TextTitle subtitle =
new TextTitle("副标题", new Font("黑体", Font.BOLD, 12));
chart.addSubtitle(subtitle);
chart.setTitle(title); //标题例子是现状图,可以参考下
1.Title (标题)
2.polt (实际的统计图)
3.Legend (图例)
假如要修改字体,或者颜色
我们就要修改它的plot部分
OK,修改颜色:
JFreeChart chart = chart.createPieChart("标题",data,true,false,false)
PiePlot plot= (PiePlot)chart.getPlot();
plot.setSectionPaint(0,new Color(255,255, 237) );
plot.setSectionPaint(1,new Color(255 ,215, 0 ) );
plot.setSectionPaint(2,new Color(238, 92 ,66 ) );
其中,0,1,2分别代表第1个块,第2个块,第3个块......new Color(255,255, 237) 为颜色对象修改字体:
plot.setLabelFont(new Font("微软雅黑",Font.BOLD,18));
你再看一遍他的视频jfreechart就知道了