cewofl 了解(2)

----------------------------------------
Cewolf生成图片和说明时,有两种方式,一种是以一幅图显示:
<cewolf:chart id="pieChart" title="Pie" type="pie">
<cewolf:gradientpaint>
<cewolf:point color="#FFFFFF" y="0" x="0"></cewolf:point>
<cewolf:point color="#DDDDFF" y="0" x="300"></cewolf:point>
</cewolf:gradientpaint>
<cewolf:data>
<cewolf:producer id="pieData"></cewolf:producer>
</cewolf:data>
</cewolf:chart>
<cewolf:img width="300" chartid="pieChart" renderer="/cewolf" height="300">
另外一种是分开显示
<cewolf:chart id="pieChart" title="Pie" type="pie" showlegend="false">
<cewolf:gradientpaint>
<cewolf:point color="#FFFFFF" y="0" x="0"></cewolf:point>
<cewolf:point color="#DDDDFF" y="0" x="300"></cewolf:point>
</cewolf:gradientpaint>
<cewolf:data>
<cewolf:producer id="pieData"></cewolf:producer>
</cewolf:data>
</cewolf:chart>
<cewolf:img width="300" chartid="pieChart" renderer="/cewolf" height="300">


<cewolf:legend id="pieChart" width="300" renderer="/cewolf" height="80"></cewolf:legend>

<cewolf:legend id="pieChart" width="300" renderer="/cewolf" height="80"></cewolf:legend>

-----------------------------------------------
其他说明:
//设置Legend的位置
//((JFreeChart) chart).getLegend().setPosition(RectangleEdge.RIGHT);
//设置最高的一个 Item 与图片顶端的距离
plot.getRangeAxis().setUpperMargin(0.15);
//设置最低的一个 Item 与图片底端的距离
plot.getRangeAxis().setLowerMargin(0.15);
//坐标轴字体
plot.getDomainAxis().setLabelFont(new Font("宋体", Font.PLAIN, 12));
//横轴每个分类的字体
plot.getDomainAxis().setTickLabelFont(new Font("宋体", Font.BOLD, 12));
if(labelPositionsUP_45)
plot.getDomainAxis().setCategoryLabelPositions(CategoryLabelPositions.UP_45);

//柱图列宽度((BarRenderer) plot.getRenderer()).setMaximumBarWidth(barWidth);

因为cewolf的tag中不能使用el,所以设置一个零时变量。

创建bean对象,用来修饰显示的图形。现在只支持pie和verticalBar3D的,分别是PieChartPostProcessor、CategoryChartPostProcessor。


------------------------------------------------------------
通过cewolf tag显示图形
部系" yaxislabel="金额" legendanchor="west">
id:必须,在整个页面中唯一
type:显示图形的类型,现在一般使用pie、verticalBar3D
xaxislabel,yaxislabel:X、Y轴的标题,不是必须
legendanchor:小图标(分类)显示的位置
还有一个showlegend属性,默认为 true,设置为false时,不显示小图标(分类)
指定数据来源,这里指向变量dp。
使用processor,控制图形的显示效果。这里可以设置一些颜色之类的属性。
显示图形,chartid指先前指定的id,renderer一般相同,指的是生成图片路径。Width、height就是图片高度和宽度。

在饼图中JFreeChart默认只显示选项和数值,没有显示各项所占比例。由于手头没有1.0版的JFreeChart Developer Guide(这可是要钱的,后来想想即使有,也未必能找到关于百分比这方面的说明),再加上DEMO中的饼图都没有显示百分比,无法参考。后来在网上找到了一个老版本的例子,其中能显示百分比。它是通过在PiePlot中设置的:

PiePlot pie;
pie.setPercentFormatString("#,###0.0#%");

但1.0版本中根本就找不到setPercentFormatString这方法,JFreeChart各版本之间改动比较大,很难兼容。还好它是开源的,把它的源码都搜索了一遍,认真读了一些源码,终于理出了头绪。

原来在1.0.0-rc1版中显示百分比已经调整到StandardPieItemLabelGenerator构造函数中了,StandardPieItemLabelGenerator有三个构造函数。StandardPieItemLabelGenerator()不显示各项所占比例。另外两个可以显示比例。代码如下:


plot.setLabelGenerator(new StandardPieItemLabelGenerator(StandardPieItemLabelGenerator.DEFAULT_TOOLTIP_FORMAT));
//或者采用下面自定义样式显示,{0}表示选项,{1}表示数值,{2}表示所占比例
plot.setLegendLabelGenerator(new StandardPieItemLabelGenerator("{0}: ({1}M, {2})"));

默认显示百分比是取整的,如果要让百分比保留二位小数,可以用第三个构造函数:
plot.setLabelGenerator(new StandardPieItemLabelGenerator(“{0}={1}({2})”,
NumberFormat.getNumberInstance(),
new DecimalFormat("0.00%")));
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值