JFreeChart是操作图表最顶级的对象,可以进行如下的个性化的设置
- 标题&子标题
- 边框
- 背景颜色
- 背景图片
- 说明
- 渲染提示(待后续补充)
设置图表的标题&子标题
JFreeChart chart= ChartFactory.createPieChart(
null,//标题
dataset,
true,//显示legend
true,//生成tooltips
false//不成生成URLs
);
//设置标题的字体
Font font=new Font("宋体",Font.PLAIN,50);
TextTitle title=new TextTitle("饼图",font);
//设置标题
chart.setTitle(title);
//设置标题的位置
title.setPosition(RectangleEdge.TOP);
//设置标题的颜色
title.setPaint(Color.red);
//设置子标题
TextTitle subTitle=new TextTitle("饼图子标题",new Font("宋体",Font.PLAIN,20));
chart.addSubtitle(subTitle);
subTitle.setPosition(RectangleEdge.BOTTOM);
subTitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
设置边框
chart.setBorderVisible(true);
chart.setBorderPaint(Color.red);
设置背景颜色
chart.setBackgroundPaint(Color.lightGray);
设置背景图片
Image image= ImageIO.read(new File("E:\\jfreechart\\bg.png"));
chart.setBackgroundImage(image);
设置说明
//获取Legend
LegendTitle legendTitle=chart.getLegend();
Font legendFont=new Font("Arial",Font.PLAIN,24);
//设置字体
legendTitle.setItemFont(legendFont);
//设置颜色
legendTitle.setItemPaint(Color.blue);
legendTitle.setBackgroundPaint(Color.lightGray);
//设置对齐方法
legendTitle.setHorizontalAlignment(HorizontalAlignment.RIGHT);
//设置边距
legendTitle.setMargin(new RectangleInsets(10,10,10,10));
legendTitle.setPadding(new RectangleInsets(10,10,10,10));

网友评论