JFreeChart的很多画图工作都是委派给Plot的,可以通过如下方式获取Plot的引用
获取Plot
Plot plot= chart.getPlot();
如果知道是哪个子类也可以转换为对应的子类
PiePlot plot1= (PiePlot)chart.getPlot();
设置字体
Font fontLabel=new Font("宋体",Font.PLAIN,24);
//设置字体
plot1.setLabelFont(fontLabel);
设置说明(Legend)的内容格式
/**
* A standard item label generator for plots that use data from a
* {@link PieDataset}.
* <p>
* For the label format, use {0} where the pie section key should be inserted,
* {1} for the absolute section value and {2} for the percent amount of the pie
* section, e.g. {@code "{0} = {1} ({2})"} will display as
* {@code apple = 120 (5%)}.
*/
plot1.setLegendLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})"));
设置标签生成内容格式
plot1.setLabelGenerator(new StandardPieSectionLabelGenerator("{0} = {1} ({2})"));
设置背景颜色
plot1.setBackgroundPaint(Color.CYAN);
pie2.png
网友评论