日期:2014-05-18  浏览次数:20680 次

jfreechar使用中两个问题
目前在做报表时,发现两个问题,不知道哪位高手有解决方法: 我用的jfreechart1.0.8版本
1.就是我在做时间曲线图,设置了在曲线上显示数据值.现在确显示了,但是有个问题,就是最后一个显示的数据值溢出部分图形界面显示不出来了。
JFreeChart chart = ChartFactory.createTimeSeriesChart(chartTitle, xTitle, "原值总值", lineDataset, true, true, false);
//设置曲线显示各数据点的值
XYItemRenderer xyitem = plot.getRenderer();  
xyitem.setBaseItemLabelsVisible(true);  
xyitem.setBasePositiveItemLabelPosition(new ItemLabelPosition(ItemLabelAnchor.OUTSIDE12, TextAnchor.CENTER_LEFT));
xyitem.setBaseItemLabelGenerator(new StandardXYItemLabelGenerator());
xyitem.setBaseItemLabelFont(new Font("Dialog", 1, 8));
plot.setRenderer(xyitem);

2.就是在上面建立chart对象时,我已经设置了显示tooltips了,为什么在图形中 鼠标移到上面去时 还是没有 tooltip了.

------解决方案--------------------
帮顶
------解决方案--------------------
楼主的第一个问题,没看懂
第二个问题提供你个建议:xyitem.setBaseToolTipGenerator(new StandardXYToolTipGenerator("{0}({1}) = {2}", new SimpleDateFormat("HH:mm"), new DecimalFormat("#,##0")));只是个例子,建议看一下API

------解决方案--------------------
图书出售,
JAVA2核心技术卷I:基础知识(原书第7版)
详细说明:http://product.dangdang.com/product.aspx?product_id=9167161 原价:88

JAVA2核心技术,卷II:高级特性(原书第7版)
详细说明:http://product.dangdang.com/product.aspx?product_id=9155128 原价:108

Java Web开发详解:XML+XSLT+Servlet+JSP深入剖析与实例应用(附光盘)
详细说明:http://product.dangdang.com/product.aspx?product_id=9167911 原价:99

Effective Java中文版
详细说明:http://product.dangdang.com/product.aspx?product_id=707050 原价:39

Java与XSLT 
详细说明:http://product.dangdang.com/product.aspx?product_id=725436 原价:55

Java网络编程(第3版)——O’Reilly Java系列 
详细说明:http://product.dangdang.com/product.aspx?product_id=9062293 原价:85

JUnit in Action 中文版——Java人的工具箱系列 
详细说明:http://product.dangdang.com/product.aspx?product_id=8935882 原价:39

Spring专业开发指南
详细说明:http://product.dangdang.com/product.aspx?product_id=9202403 原价:80

Spring 2.0技术手册(附光盘)
详细说明:http://product.dangdang.com/product.aspx?product_id=9303590 原价:49.8

深入浅出Hibernate
详细说明:http://product.dangdang.com/product.aspx?product_id=8991354 原价:59

Struts 2 权威指南:基于WebWork核心的MVC开发(附光盘)
详细说明:http://product.dangdang.com/product.aspx?product_id=20029121&mode=new 原价:79

Oracle高级编程
详细说明:http://product.dangdang.com/product.aspx?product_id=9296670 原价:69

SQL Server 2005宝典(附盘) 
详细说明:http://product.dangdang.com/product.aspx?product_id=9247242 原价:79

以上书籍完好无损,均以4.5折出售,如需邮寄,邮费自付。QQ:492717188 tel:13450830512 谢谢!
------解决方案--------------------
第一个问题 就是我画出的一条时间曲线,然后设置了显示了在曲线上显示数据值,结果其他的都没问题,现在就是最后一个点的数据值显示超出了图形的显示去区域 被截断了一些,不不知道怎么设置才不会出现这样的情况.
第二个问题按照你的做法做了还是没有显示tooltip. 对了 我是在web中使用jfreechart的,使用 String filename = ServletUtilities.saveChartAsPNG(chart, 700, 400, null, session);
String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
输出不过还是显示不了tooltip.
------解决方案--------------------
第一个问题:你可以通过setRange方法设置X轴的跨度
第二个问题:在你生成图形的时候修改一个参数就可以了,比如:

JFreeChart chart = ChartFactory.createTimeSeriesChart(reportTitle, // Chart title
"",// Xaxis title
ReportConstants.REPORT_LINE_YTITLE,// Yaxis title
dataset, // dataset
false, // 
true,// 
false// 

);
倒数第二个参数'true' 就是表示是否显示tooltip的,如果你设为false就不会显示