java pieplot_Java PiePlot.setBackgroundAlpha方法代码示例

import org.jfree.chart.plot.PiePlot; //导入方法依赖的package包/类

public static JFreeChart createPieChart(DefaultPieDataset dataset, String title, boolean is3D) {

JFreeChart chart = null;

if (is3D) {

chart = ChartFactory.createPieChart3D(title, // 图表标题

dataset, // 数据集

true, // 是否显示图例

true, // 是否显示工具提示

true // 是否生成URL

);

} else {

chart = ChartFactory.createPieChart(title, // 图表标题

dataset, // 数据集

true, // 是否显示图例

true, // 是否显示工具提示

true // 是否生成URL

);

}

// 设置标题字体==为了防止中文乱码:必须设置字体

chart.setTitle(new TextTitle(title, new Font("黑体", Font.ITALIC, 22)));

// 设置图例的字体==为了防止中文乱码:必须设置字体

chart.getLegend().setItemFont(new Font("黑体", Font.BOLD, 12));

// 获取饼图的Plot对象(实际图表)

PiePlot plot = (PiePlot) chart.getPlot();

// 图形边框颜色

plot.setBaseSectionOutlinePaint(Color.GRAY);

// 图形边框粗细

plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f));

// 设置饼状图的绘制方向,可以按顺时针方向绘制,也可以按逆时针方向绘制

plot.setDirection(Rotation.ANTICLOCKWISE);

// 设置绘制角度(图形旋转角度)

plot.setStartAngle(70);

// 设置突出显示的数据块

// plot.setExplodePercent("One", 0.1D);

// 设置背景色透明度

plot.setBackgroundAlpha(0.7F);

// 设置前景色透明度

plot.setForegroundAlpha(0.65F);

// 设置区块标签的字体==为了防止中文乱码:必须设置字体

plot.setLabelFont(new Font("宋体", Font.PLAIN, 12));

// 扇区分离显示,对3D图不起效

if (is3D)

plot.setExplodePercent(dataset.getKey(3), 0.1D);

// 图例显示百分比:自定义方式,{0} 表示选项, {1} 表示数值, {2} 表示所占比例 ,小数点后两位

plot.setLabelGenerator(new StandardPieSectionLabelGenerator(

"{0}:{1}\r\n({2})", NumberFormat.getNumberInstance(),

new DecimalFormat("0.00%")));

// 图例显示百分比

// plot.setLegendLabelGenerator(new

// StandardPieSectionLabelGenerator("{0}={1}({2})"));

// 指定显示的饼图为:圆形(true) 还是椭圆形(false)

plot.setCircular(true);

// 没有数据的时候显示的内容

plot.setNoDataMessage("找不到可用数据...");

// 设置鼠标悬停提示

plot.setToolTipGenerator(new StandardPieToolTipGenerator());

// 设置热点链接

// plot.setURLGenerator(new StandardPieURLGenerator("detail.jsp"));

return chart;

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值