您的位置:首页 > 其它

JFreeChart当鼠标停留在热点提示自定义信息功能

2013-06-21 16:17 351 查看
当鼠标停留在数据点时,希望有提示信息显示,但是根据业务需要,我们需要自定义显示一下信息!具体功能实现如下:

首先我们要弄明白,Jfreechart鼠标提示信息显示主要是得到一个数据的map对象,该map中定义了热点的坐标及提示时显示的信息即title

html或jsp中代码:

<img src="Jfreechart生成的图片路径" width=800 height=400 border=0 usemap="mapKey" >"

mapKey 默认为JfreeChart生成的图片名:mapKey = ServletUtilities.saveChartAsPNG(chart, 800, 400, info,session);// 生成图片

知道该原理,只有得到map,然后把里面的提示信息修改为我们的自定义提示信息即可;

如何生成图表(略过) 网上一搜一大把

1、首先获取map数据:

JFreeChart chart = ChartFactory.createTimeSeriesChart(
"正常用量分析", // title
x_name, // x-axis label
"消耗热能 [单位:MJ]", // y-axis label
collection, // data
false, // create legend?
true, // generate tooltips?
false // generate URLs?
);


当你创建JFeeChart对象倒数第二个参数为true时,表示生成工具提示。

当把数据插入到数据集后,通过

String map_ = ChartUtilities.getImageMap(fileName,info);


获取到map提示信息的字符串表现形式,打印出来:

<map id="jfreechart-33716.png" name="jfreechart-33716.png">
<area shape="poly" coords="771,60,777,60,777,66,771,66,771,60,771,60" title="正常用量分析: (10-10-1 上午12:00, 10,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="699,90,705,90,705,96,699,96,699,90,699,90" title="正常用量分析: (10-9-1 上午12:00, 9,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="626,119,632,119,632,125,626,125,626,119,626,119" title="正常用量分析: (10-8-1 上午12:00, 8,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="552,149,558,149,558,155,552,155,552,149,552,149" title="正常用量分析: (10-7-1 上午12:00, 7,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="481,179,487,179,487,185,481,185,481,179,481,179" title="正常用量分析: (10-6-1 上午12:00, 6,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="407,208,413,208,413,214,407,214,407,208,407,208" title="正常用量分析: (10-5-1 上午12:00, 5,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="336,238,342,238,342,244,336,244,336,238,336,238" title="正常用量分析: (10-4-1 上午12:00, 4,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="263,268,269,268,269,274,263,274,263,268,263,268" title="正常用量分析: (10-3-1 上午12:00, 3,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="196,297,202,297,202,303,196,303,196,297,196,297" title="正常用量分析: (10-2-1 上午12:00, 2,000)" alt="" nohref="nohref"/>
<area shape="poly" coords="122,327,128,327,128,333,122,333,122,327,122,327" title="正常用量分析: (10-1-1 上午12:00, 1,000)" alt="" nohref="nohref"/>

</map>

提示信息是在title项,只要我们把title项改为我们需要的信息即可。

最后完成的效果:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: