报表问题求救!

shantang1984 2009-07-20 06:20:49
我们项目中用的报表工具是ireport + jasperreport
现在我想实现这样的一个柱状图:


现在唯一没有实现的是,上图每个柱的数值没出来,不知道怎么设,没有看到相应的接口!

jfreechart是可以设的!

BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseOutlinePaint(Color.BLACK);
//设置 Wall 的颜色
renderer.setWallPaint(Color.gray);
//设置每种水果代表的柱的颜色
renderer.setSeriesPaint(0, new Color(0, 0, 255));
renderer.setSeriesPaint(1, new Color(0, 100, 255));
renderer.setSeriesPaint(2, Color.GREEN);
//设置每个地区所包含的平行柱的之间距离
renderer.setItemMargin(0.1);
//显示每个柱的数值,并修改该数值的字体属性
renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
renderer.setItemLabelsVisible(true);

plot.setRenderer(renderer);

但是jasperreport该怎么设,按理说
它是调用jfreechart来画图的,但我却没找到相应的接口进行设值!

请各位大侠帮一下忙!分不够可以加!
...全文
662 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
hzj86 2011-08-13
  • 打赏
  • 举报
回复
只是显示在柱形上端,而不是上面,而且数值样式设置太大的话也看不了。
levin_china 2011-01-06
  • 打赏
  • 举报
回复
柱子太短了,还是会不显示的。有人知道怎么解决吗?
jdb861202 2010-11-29
  • 打赏
  • 举报
回复
请问没有用java代码写,直接在ireport里怎么设置?
zc837353080 2010-08-27
  • 打赏
  • 举报
回复
这个问题很有价值啊.......
jl6250 2010-01-18
  • 打赏
  • 举报
回复
<bar3DPlot isShowLabels="true">设过后还是出不来结果啊
shantang1984 2009-07-23
  • 打赏
  • 举报
回复
现在又有个新问题
如上加了tickLabelMask="##%"属性,只能是边上的Y轴的格式变化了

我怎么把中间每个柱的数值也改变成相同的格式呢?!

没找到对应的属性!高手赐教!
shantang1984 2009-07-23
  • 打赏
  • 举报
回复
看了官方的 http://jasperreports.sourceforge.net/xsd/jasperreport.xsd

而且我找到了设置 成百分比的方式显示

<valueAxisFormat>
<axisFormat tickLabelMask="##%">
<labelFont/>
<tickLabelFont/>
</axisFormat>
</valueAxisFormat>

加给以上代码加上 tickLabelMask="##%" 属性

当然也可以用ireport直接找到对应的属性进行设置
shantang1984 2009-07-23
  • 打赏
  • 举报
回复
解决了,原来我设的是对的,在测试画面上,值全是1,然后几个图在一块,显示有点不正常了。
实际画面一切OK了
barPlot 设置 isShowLabels="true"

散分!
money8899 2009-07-23
  • 打赏
  • 举报
回复
每天回帖即可获得10分
shantang1984 2009-07-23
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 laorer 的回复:]
plot 中应该有个 ShowLabels
[/Quote]

这个我设为true了,每个柱上面就显示一小 "-",不知道是什么原因
wyj1983 2009-07-21
  • 打赏
  • 举报
回复
//这儿是坐标上的字体,自己试试....
JFreeChart chart = ChartFactory.createBarChart3D("隐患质量柱状图", // chart title
"问题类别", // domain axis label
"次数", // range axis label
dataset, // data
PlotOrientation.VERTICAL, // PlotOrientation.VERTICAL 让平行柱垂直显示,而 PlotOrientation.HORIZONTAL 则让平行柱水平显示
true, // include legend
true, // tooltips
false // urls
);

chart.setBackgroundPaint(Color.WHITE);
CategoryPlot plot = chart.getCategoryPlot();
CategoryAxis domainAxis = plot.getDomainAxis();
domainAxis.setCategoryMargin(0.15);
domainAxis.setMaximumCategoryLabelLines(3);
domainAxis.setMaximumCategoryLabelWidthRatio(3);
plot.setDomainAxis(domainAxis);
// 图示在图表中的显示位置

LegendTitle legend = (LegendTitle) chart.getLegend();
legend.setPosition(RectangleEdge.TOP); //示意图位置
// legend.setPosition(RectangleEdge.RIGHT);
legend.setLegendItemGraphicEdge(RectangleEdge.LEFT);

ValueAxis rangeAxis = plot.getRangeAxis();

//设置最高的一个 Item 与图片顶端的距离
rangeAxis.setUpperMargin(0.15);

//设置最低的一个 Item 与图片底端的距离
rangeAxis.setLowerMargin(0.15);
plot.setRangeAxis(rangeAxis);

BarRenderer3D renderer = new BarRenderer3D();
renderer.setBaseOutlinePaint(Color.blue);

//设置 Wall 的颜色
renderer.setWallPaint(Color.darkGray);

renderer.setSeriesPaint(0, Color.red);
renderer.setSeriesPaint(1, Color.GREEN);
renderer.setSeriesPaint(2, Color.orange);

//设置每个地区所包含的平行柱的之间距离
renderer.setItemMargin(0.03);

//显示每个柱的数值(名称),并修改该数值的字体属性
renderer.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());

renderer.setItemLabelFont(new Font("黑体",Font.PLAIN,12));
renderer.setItemLabelsVisible(true);
ItemLabelPosition itemLabelPosition = new ItemLabelPosition();
renderer.setPositiveItemLabelPosition(itemLabelPosition);
plot.setRenderer(renderer);

//设置柱的透明度
plot.setForegroundAlpha(1f);

//设置专业、数量的显示位置
// plot.setDrawSharedDomainAxis(true);
plot.setDomainAxisLocation(AxisLocation.BOTTOM_OR_LEFT);
plot.setRangeAxisLocation(AxisLocation.BOTTOM_OR_LEFT);


String filename = ServletUtilities.saveChartAsPNG(chart, 1220, 490, null, session);
String graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename;
sjyjia105 2009-07-21
  • 打赏
  • 举报
回复
共同讨论 qq群30226591 欢迎加入 一起壮大
laorer 2009-07-21
  • 打赏
  • 举报
回复
plot 中应该有个 ShowLabels
dzq1201030 2009-07-20
  • 打赏
  • 举报
回复
这个很容易
LZ可以看下我写过的代码
public ActionForward outCatgory(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaActionForm searchForm = (DynaActionForm) form;
int a = ub.find1("2009");
int b = ub.find2("2009");
int c = ub.find3("2009");
int d = ub.find4("2009");
FileOutputStream fos_jpg;

try {
fos_jpg = new FileOutputStream("e:\\柱状图分布.jpg");
DefaultCategoryDataset dataset = new DefaultCategoryDataset();

dataset.addValue(a, "注册人数", "一季度");
dataset.addValue(b, "注册人数", "二季度");
dataset.addValue(c, "注册人数", "三季度");
dataset.addValue(d, "注册人数", "四季度");
JFreeChart chart = ChartFactory.createBarChart3D("产量图", "时间", "人数",
dataset, PlotOrientation.VERTICAL, true, true, true);

chart.getTitle().setFont(new Font("宋体", Font.BOLD, 12));// 标题中文

CategoryPlot categoryplot = (CategoryPlot) chart.getPlot();

CategoryAxis domainAxis = categoryplot.getDomainAxis();

NumberAxis numberaxis = (NumberAxis) categoryplot.getRangeAxis();

domainAxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 11)); // 横轴坐标中文

domainAxis.setLabelFont(new Font("宋体", Font.PLAIN, 12)); // 横轴标题中文

numberaxis.setTickLabelFont(new Font("sans-serif", Font.PLAIN, 12)); // 竖轴坐标中文

numberaxis.setLabelFont(new Font("黑体", Font.PLAIN, 12)); // 竖轴标题中文

chart.getLegend().setItemFont(new Font("宋体", Font.PLAIN, 12)); // 底部中文

ChartUtilities.writeChartAsJPEG(fos_jpg, 1.0f, chart, 640, 480,
null); // 图片形式画出来
fos_jpg.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

return null;
}

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧