探讨 Jfreechart的节点上点击鼠标显示数据!!!!!!

gyl086 2008-01-18 04:20:44
楼里的各位大哥大姐,现在俺有一个想法,不知道能不能得到赐教.问题如下:
现在我用jfreechart做了折线图,如果数据多的时候显示到节点上,会都挤到一起,看不清楚,我现在想,在得到图形的时候不在节点上显示数据,而是当把鼠标放到某个节点上的时候,显示此节点对应的数据,不知道我这个想法是不是有道理?如果有,有没有哪位大哥大姐给点实例代码,感谢感谢啊!
...全文
1162 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
s19810310 2011-09-26
  • 打赏
  • 举报
回复
我也在解决这个问题,还没解决
xxbwxp 2011-02-16
  • 打赏
  • 举报
回复
真是藏龙卧虎之地
阿米尔 2010-12-01
  • 打赏
  • 举报
回复
楼主这个问题你解决了没啊?我做项目也遇到了这问题
输出的是图片,怎么让它在鼠标放上去显示数据啊?
解决了,拜托指教一下啊
先谢谢了
我QQ:1021938637(隐身在线)
阿米尔 2010-12-01
  • 打赏
  • 举报
回复
楼主这个问题你解决了没啊?我做项目也遇到了这问题
输出的是图片,怎么让它在鼠标放上去显示数据啊?
解决了,拜托指教一下啊
先谢谢了
我QQ:1021938637(隐身在线)
HUNTER927 2009-07-23
  • 打赏
  • 举报
回复
感谢一下
cocaine0924 2009-04-30
  • 打赏
  • 举报
回复
刚才试了一下nuskwill说的是真确的
感谢一下
henry1451 2008-02-24
  • 打赏
  • 举报
回复
jfreechart有这个功能的啊,可以将生成的图片以servlet形式返回客户端显示的.
gyl086 2008-02-24
  • 打赏
  • 举报
回复
楼上你好,感谢你给的代码,不过我是想在页面上实现我的想法,不是在applet上.您看能实现吗?
denghan 2008-01-24
  • 打赏
  • 举报
回复
在代码里设置图片的宽度,比如按数据量动态设置宽度。

另外,貌似jfreechart不能实现鼠标点上去显示数据。因为它生成的图片是png,jpeg,bmp等静态的图片。最新版的能不能做成flash,不知道。
gyl086 2008-01-24
  • 打赏
  • 举报
回复
nuskwill 大哥你好啊,怎么这几天不来光顾了呀,请指点啊
nuskwill 2008-01-24
  • 打赏
  • 举报
回复
不好意思 现在才来 。
你在4楼的代码应该可以实现啊。哦,对了,你用的版本是不是是1.0.6的?

给你一个例子,你试试吧:




package gg;

import java.awt.Color;
import java.awt.Dimension;
import java.text.SimpleDateFormat;
import javax.swing.JPanel;
import org.jfree.chart.*;
import org.jfree.chart.axis.DateAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.time.*;
import org.jfree.data.xy.XYDataset;
import org.jfree.ui.*;

public class TimeSeriesDemo1 extends ApplicationFrame
{

public TimeSeriesDemo1(String s)
{
super(s);
XYDataset xydataset = createDataset();
JFreeChart jfreechart = createChart(xydataset);
ChartPanel chartpanel = new ChartPanel(jfreechart, false);
chartpanel.setPreferredSize(new Dimension(500, 270));
chartpanel.setMouseZoomable(true, false);
setContentPane(chartpanel);
}

private static JFreeChart createChart(XYDataset xydataset)
{
JFreeChart jfreechart = ChartFactory.createTimeSeriesChart("Legal & General Unit Trust Prices", "Date", "Price Per Unit", xydataset, true, true, true);
jfreechart.setBackgroundPaint(Color.white);
XYPlot xyplot = (XYPlot)jfreechart.getPlot();
xyplot.setBackgroundPaint(Color.lightGray);
xyplot.setDomainGridlinePaint(Color.white);
xyplot.setRangeGridlinePaint(Color.white);
xyplot.setAxisOffset(new RectangleInsets(5D, 5D, 5D, 5D));
xyplot.setDomainCrosshairVisible(true);
xyplot.setRangeCrosshairVisible(true);
org.jfree.chart.renderer.xy.XYItemRenderer xyitemrenderer = xyplot.getRenderer();
if(xyitemrenderer instanceof XYLineAndShapeRenderer)
{
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)xyitemrenderer;
xylineandshaperenderer.setBaseShapesVisible(true);
xylineandshaperenderer.setBaseShapesFilled(true);
}
DateAxis dateaxis = (DateAxis)xyplot.getDomainAxis();
dateaxis.setDateFormatOverride(new SimpleDateFormat("MMM-yyyy"));
return jfreechart;
}

private static XYDataset createDataset()
{
TimeSeries timeseries = new TimeSeries("L&G European Index Trust", org.jfree.data.time.Month.class);
timeseries.add(new Month(2, 2001), 181.80000000000001D);
timeseries.add(new Month(3, 2001), 167.30000000000001D);
timeseries.add(new Month(4, 2001), 153.80000000000001D);
timeseries.add(new Month(5, 2001), 167.59999999999999D);
timeseries.add(new Month(6, 2001), 158.80000000000001D);
timeseries.add(new Month(7, 2001), 148.30000000000001D);
timeseries.add(new Month(8, 2001), 153.90000000000001D);
timeseries.add(new Month(9, 2001), 142.69999999999999D);
timeseries.add(new Month(10, 2001), 123.2D);
timeseries.add(new Month(11, 2001), 131.80000000000001D);
timeseries.add(new Month(12, 2001), 139.59999999999999D);
timeseries.add(new Month(1, 2002), 142.90000000000001D);
timeseries.add(new Month(2, 2002), 138.69999999999999D);
timeseries.add(new Month(3, 2002), 137.30000000000001D);
timeseries.add(new Month(4, 2002), 143.90000000000001D);
timeseries.add(new Month(5, 2002), 139.80000000000001D);
timeseries.add(new Month(6, 2002), 137D);
timeseries.add(new Month(7, 2002), 132.80000000000001D);
TimeSeries timeseries1 = new TimeSeries("L&G UK Index Trust", org.jfree.data.time.Month.class);
timeseries1.add(new Month(2, 2001), 129.59999999999999D);
timeseries1.add(new Month(3, 2001), 123.2D);
timeseries1.add(new Month(4, 2001), 117.2D);
timeseries1.add(new Month(5, 2001), 124.09999999999999D);
timeseries1.add(new Month(6, 2001), 122.59999999999999D);
timeseries1.add(new Month(7, 2001), 119.2D);
timeseries1.add(new Month(8, 2001), 116.5D);
timeseries1.add(new Month(9, 2001), 112.7D);
timeseries1.add(new Month(10, 2001), 101.5D);
timeseries1.add(new Month(11, 2001), 106.09999999999999D);
timeseries1.add(new Month(12, 2001), 110.3D);
timeseries1.add(new Month(1, 2002), 111.7D);
timeseries1.add(new Month(2, 2002), 111D);
timeseries1.add(new Month(3, 2002), 109.59999999999999D);
timeseries1.add(new Month(4, 2002), 113.2D);
timeseries1.add(new Month(5, 2002), 111.59999999999999D);
timeseries1.add(new Month(6, 2002), 108.8D);
timeseries1.add(new Month(7, 2002), 101.59999999999999D);
TimeSeriesCollection timeseriescollection = new TimeSeriesCollection();
timeseriescollection.addSeries(timeseries);
timeseriescollection.addSeries(timeseries1);
return timeseriescollection;
}

public static JPanel createDemoPanel()
{
JFreeChart jfreechart = createChart(createDataset());
return new ChartPanel(jfreechart);
}

public static void main(String args[])
{
TimeSeriesDemo1 timeseriesdemo1 = new TimeSeriesDemo1("Time Series Demo 1");
timeseriesdemo1.pack();
RefineryUtilities.centerFrameOnScreen(timeseriesdemo1);
timeseriesdemo1.setVisible(true);
}
}

gyl086 2008-01-18
  • 打赏
  • 举报
回复
楼上的朋友你好,我的代码是这样写的,我是做的时间线
JFreeChart chart=ChartFactory.createTimeSeriesChart("图形","日期","数据",dataset,true,true,true)
XYPlot plot = (XYPlot) chart.getPlot();
XYItemRenderer xyitem = plot.getRenderer();
xyitem.setBaseItemLabelsVisible(true);
你看是不是能如您所说的那样呢?或者应该怎么修改呢?谢谢了啊!
nuskwill 2008-01-18
  • 打赏
  • 举报
回复
突然想起来 你应该在创建CHART时,倒数第二个参数设置为TURE才能 鼠标移上去显示数据
比如:ChartFactory.createXYLineChart("XY Series", "X", "Y", dataset, PlotOrientation.VERTICAL, true, true, false);
nuskwill 2008-01-18
  • 打赏
  • 举报
回复
createXYLineChart,或createLineChart时默认就不在节点上显示数据,只是鼠标移上去才显示的啊。我做的时候就是这样,你还是去看看API,肯定是你哪里设置了,具体的方法我也记不清了!要不你把你的代码发上来看看。。
zhangli0803 2008-01-18
  • 打赏
  • 举报
回复
帮顶!

81,094

社区成员

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

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