JFreeChart 折线图 热点问题, 急等 谢谢了。

xiaohanxue 2009-10-29 10:21:25
如题,我用jfreechart做折线图,明明已经添加了显示热点的代码,而且在jsp页面右键查看源文件时,也能看到map信息,但是鼠标放到折线上,就是没有信息出现。请各位高人给看看怎么回事儿吧。
我是在jsp里面直接形成图片的,我现在把jsp里面的代码贴出来:
XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
XYDataset xydataset = (XYDataset)xySeriesCollection;

xySeriesCollection.addSeries(xyseries1);
xySeriesCollection.addSeries(xyseries2);
xySeriesCollection.addSeries(xyseries3);
xySeriesCollection.addSeries(xyseries4);

JFreeChart chart = ChartFactory.createXYLineChart(
"正压力图表显示", // chart title
"井深(m)", // domain axis label
"正压力(N)", // range axis label
xydataset, // dataset
PlotOrientation.HORIZONTAL, // orientation
true, // include legend
true,
false
);

// set the background color for the chart...
Font font = new Font("SimSun",Font.BOLD,20);
Font font2 = new Font("SimSun",Font.BOLD,14);
TextTitle tt = chart.getTitle();
tt.setFont(font);
chart.setBackgroundPaint(new Color(0xCC, 0xFF, 0xCC));
LegendTitle legend = (LegendTitle) chart.getSubtitle(0);
legend.setPosition(RectangleEdge.BOTTOM);
legend.setItemFont(font2);

// get a reference to the plot for further customisation...
XYPlot plot = (XYPlot) chart.getPlot();
plot.setDomainAxisLocation(AxisLocation.TOP_OR_LEFT);
plot.setRangeAxisLocation(AxisLocation.TOP_OR_LEFT);
plot.getDomainAxis().setLabelFont(font2);
plot.getRangeAxis().setLabelFont(font2);
XYLineAndShapeRenderer xylinerenderer=(XYLineAndShapeRenderer)plot.getRenderer();
xylinerenderer.setSeriesPaint(0, new Color(255, 0 ,0));
xylinerenderer.setSeriesPaint(1, new Color(0 ,0, 255));
xylinerenderer.setSeriesPaint(2, new Color(255, 0 ,0));
xylinerenderer.setSeriesPaint(3, new Color(0 ,0, 255));


NumberAxis numAxis = (NumberAxis)plot.getDomainAxis();
numAxis.setTickUnit(new NumberTickUnit(2)); //0.5为一个间隔单位
plot.getRenderer().setSeriesStroke(2, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {6F, 6F}, 0.0F));
plot.getRenderer().setSeriesStroke(3, new BasicStroke(2.0F, 1, 1, 1.0F, new float[] {6F, 6F}, 0.0F));

StandardEntityCollection sec = new StandardEntityCollection();
ChartRenderingInfo info = new ChartRenderingInfo(sec);
filename2 = ServletUtilities.saveChartAsPNG(chart, 800, 390, info, request.getSession());
PrintWriter out2 = response.getWriter();
PrintWriter w = new PrintWriter(out2);//输出MAP信息
ChartUtilities.writeImageMap(w, "mapx", info, false);
w.flush();
graphURL = request.getContextPath() + "/servlet/DisplayChart?filename=" + filename2;

<td><div><img src="<%=graphURL%>" usemap="#mapx"></div></td>

在jsp页面右键查看源代码:
<map id="mapx" name="mapx">
<area shape="poly" coords="76,150,75,152,73,153,71,152,70,150,71,148,73,147,75,148,76,150,76,150" title="前次分析: (-0, 100)" alt="" nohref="nohref"/>
<area shape="poly" coords="77,159,76,161,74,162,72,161,71,159,72,157,74,156,76,157,77,159,77,159" title="前次分析: (-0.05, 110)" alt="" nohref="nohref"/>
<area shape="poly" coords="78,164,77,166,75,167,72,166,72,164,72,162,75,161,77,162,78,164,78,164" title="前次分析: (-0.1, 115)" alt="" nohref="nohref"/>
。。。。。。
</map>

<td><div><img src="/fpm/servlet/DisplayChart?filename=jfreechart-19796.png" usemap="#mapx"></div></td>

谢谢了。
...全文
295 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
cdrqingtian 2012-07-17
  • 打赏
  • 举报
回复
楼主怎么不把所有的代码贴出来,这样我就可以很轻松的复制了!
wcxtingfly 2010-05-29
  • 打赏
  • 举报
回复
感谢LZ的代码
wcxtingfly 2010-05-29
  • 打赏
  • 举报
回复
不加ylinerenderer.setBaseShapesVisible(true)这句话 一样可以显示title啊。。。
studying_ 2009-10-30
  • 打赏
  • 举报
回复
给LZ顶起来先,希望你的问题能早日被解决撒。呵呵
xiaohanxue 2009-10-30
  • 打赏
  • 举报
回复
现在加了:ylinerenderer.setBaseShapesVisible(true);这句话,把每个节点显示出来后,点在节点上能够看到title的内容。
有哪位知道不显示节点时怎样才能出来title内容啊。我的折线点很密,如果显示节点的话太难看了。
大家帮忙啊。
xiaohanxue 2009-10-29
  • 打赏
  • 举报
回复
自己顶一下,等待大家解答。。。
xiaohanxue 2009-10-29
  • 打赏
  • 举报
回复
弄出来了。但是必须把节点标志显示出来才能看到title内容。有哪位知道不显示节点怎样才能出来啊?
xiaohanxue 2009-10-29
  • 打赏
  • 举报
回复
To 楼上:
我的xyseries1,xyseries2,xyseries3,xyseries4是在上面定义的,然后填充了数据。因为填充数据那段有点长,所以我没贴出来。
如果说是因为dataset的问题的话,jsp显示后,查看源文件时<map>....</map>都能显示,而且里面的数值也是正确的啊。
littlemonster 2009-10-29
  • 打赏
  • 举报
回复
1 下面这部分里,之所以你没显示,估计是xydataset的问题

JFreeChart chart = ChartFactory.createXYLineChart(
"正压力图表显示", // chart title
"井深(m)", // domain axis label
"正压力(N)", // range axis label
xydataset, // dataset
PlotOrientation.HORIZONTAL, // orientation
true, // include legend
true,
false
);

2 但是我找你的xydataset,下面的xyseries1,xyseries2,xyseries3,xyseries4在哪里定义的?

XYSeriesCollection xySeriesCollection = new XYSeriesCollection();
XYDataset xydataset = (XYDataset)xySeriesCollection;

xySeriesCollection.addSeries(xyseries1);
xySeriesCollection.addSeries(xyseries2);
xySeriesCollection.addSeries(xyseries3);
xySeriesCollection.addSeries(xyseries4);
================================================================
我下面把我写的大概列出来。。你参考一下. Good luck~
方法1 ----
public void createPlot(String tilte) {
setTitle(tilte);
final XYDataset dataset = createDataset();
final JFreeChart chart = createChart(dataset);
final ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setPreferredSize(new java.awt.Dimension(600, 270));
setContentPane(chartPanel);
}

方法2---
private XYDataset createDataset() {
final XYSeriesCollection dataset = new XYSeriesCollection();
ArrayList<List<Float>> modulelines = calLineData();

for (int i = 0; i < modulelines.size(); i++) {
final XYSeries series0 = new XYSeries((String) getPlotList().get(i));
ArrayList<Float> data = (ArrayList<Float>) modulelines.get(i);
for (int j = 0; j < data.size(); j++) {
series0.add((j + 1), data.get(j));// j-->conditions
}
dataset.addSeries(series0);
}
return dataset;
}

方法3---
private JFreeChart createChart(final XYDataset dataset) {

// create the chart...
final JFreeChart chart = ChartFactory.createXYLineChart("Module Plot",
"Experiments", // x axis label
"Expression value", // y axis label
dataset, // data
PlotOrientation.VERTICAL, true, // include legend
true, // tooltips
false // urls
);

// NOW DO SOME OPTIONAL CUSTOMISATION OF THE CHART...
chart.setBackgroundPaint(Color.white);

// get a reference to the plot for further customisation...
XYPlot plot = (XYPlot) chart.getPlot();
plot.setBackgroundPaint(Color.lightGray);
plot.setDomainGridlinePaint(Color.black);
plot.setRangeGridlinePaint(Color.white);

XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
r.setShapesVisible(false);

return chart;
}
xiaozejun 2009-10-29
  • 打赏
  • 举报
回复
这里面有你需要的例子 各种类型的都有 楼主可以下下来好好看一看:
http://download.csdn.net/source/1724387
xiaohanxue 2009-10-29
  • 打赏
  • 举报
回复
自己顶一下,等待大家解答。。。

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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