jfreechart的数据点显示

xrjabc 2007-04-16 11:02:49
小弟我要实现在一个jsp页面上画出两个曲线图,每个图都是以时间为x轴,多纵轴.并且要在鼠标指向各个数据点的时候显示其坐标.
写了一个方法
public void drawMoreZheXian(ArrayList TimeSeriesLIst, ArrayList showList,
ArrayList colorList, String[] groupArr,
String[] titleArr, String zmStr,
JspWriter out, int width, int height,
String[] colorArr, int bgcolor) {
CombinedDomainXYPlot plot = new CombinedDomainXYPlot(new DateAxis(zmStr));
if (groupArr != null && groupArr.length >= 1) {

for (int i = 0; i < groupArr.length; i++) {
//String[] numArr = groupArr[i].split(",");
// 循环把各组值放到 collection中
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries( (TimeSeries) TimeSeriesLIst.get(i));

// 生产工具提示信息的ArrayList
ArrayList[] tooltips = new ArrayList[showList.size()];
for (int k = 0; k < showList.size(); k++) {
tooltips[k] = getCurveSeries( (String[]) showList.get(k));
}

////////////////////////井数
NumberAxis rangeAxis1 = new NumberAxis(titleArr[i]);

CustomXYToolTipGenerator ttg1 = new CustomXYToolTipGenerator();
//加入各条曲线的工具提示条
ttg1.addToolTipSeries(tooltips[i]);



//生成曲线的透视层
StandardXYItemRenderer renderer1 = new StandardXYItemRenderer(
StandardXYItemRenderer.SHAPES_AND_LINES,
ttg1, null);
rangeAxis1.setAutoRangeIncludesZero(false);
rangeAxis1.setAutoRangeStickyZero(false);
//设置小数位数
rangeAxis1.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
XYPlot subplot1 = new XYPlot(dataset, null, rangeAxis1, renderer1);
subplot1.setBackgroundPaint(new GradientPaint(0, 100,
new Color(0xccccff), 130, 240, new Color(0xeffcd0), true));
plot.setDomainGridlinePaint(Color.white);
plot.setRangeGridlinePaint(Color.white);
plot.setAxisOffset(new RectangleInsets(5.0, 5.0, 5.0, 5.0));
plot.add(subplot1, 1);
plot.setBackgroundPaint(new Color(bgcolor));
if (colorList != null && colorList.size() > 0) {
renderer1.setSeriesPaint(0, (Color) colorList.get(i));
}

rangeAxis1.setAutoRange(true);

JFreeChart chart = new JFreeChart("",
JFreeChart.DEFAULT_TITLE_FONT, plot, false);
chart.setBackgroundPaint(new Color(bgcolor));

plot.setDomainCrosshairVisible(false);
plot.setRangeCrosshairVisible(false);

DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setTickUnit(new DateTickUnit(DateTickUnit.DAY, 1,
new SimpleDateFormat("MM-dd")));
XYItemRenderer xyitemrenderer = plot.getRenderer();
if (xyitemrenderer instanceof XYLineAndShapeRenderer) {
XYLineAndShapeRenderer xylineandshaperenderer = (XYLineAndShapeRenderer)
xyitemrenderer;
xylineandshaperenderer.setBaseShapesVisible(true);
xylineandshaperenderer.setBaseShapesFilled(true);
}
FileOutputStream fos_jpg = null;
String[] imgUrl = null;
ChartRenderingInfo info = null;
try {
imgUrl = ImgScgz.getImgUrl();
fos_jpg = new FileOutputStream(imgUrl[0]);
info = new ChartRenderingInfo();
ChartUtilities.writeChartAsJPEG(fos_jpg, 100, chart, width, height, info); //图形的大小

}
catch (Exception e) {
e.printStackTrace();
}
finally {
try {
fos_jpg.close();
}
catch (Exception e) {}
}
try {
out.print("<img src=" + imgUrl[1] + " border=0 usemap=#mapName>");
out.print(ChartUtilities.getImageMap("mapName", info));
}
catch (Exception e) {}

}
}
然后在jsp中调用两次这个方法,只是传递的参数不一致,但是只能显示前一个图的数据点,后一个似乎还是用的前一个的tooltips


请教高手是怎么回事?
...全文
636 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
coyprightbao 2007-04-18
  • 打赏
  • 举报
回复
http://www.7points.net/blog/user1/major/archives/2006/440.html
这个地方说得比较详细,希望能有你要找的,我也在弄这个!
coyprightbao 2007-04-18
  • 打赏
  • 举报
回复
不好意思啊,我不能回答你的问题,是来请教问题的!

“要在鼠标指向各个数据点的时候显示其坐标.”

这个怎么实现的呀!是那个toolTips吗?
xrjabc 2007-04-16
  • 打赏
  • 举报
回复
方法getCurveSeries内容
public ArrayList getCurveSeries(String[] str) {
//所对应的工具提示
ArrayList toolTips = new ArrayList();
for (int i = 0; i < str.length; i++) {
toolTips.add(str[i]);
}
return toolTips;
}
xrjabc 2007-04-16
  • 打赏
  • 举报
回复
这问题困扰好久了,请高手帮忙
xrjabc 2007-04-16
  • 打赏
  • 举报
回复
没人愿意看看吗? 就算很简单,也请告诉我,谢谢!

62,614

社区成员

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

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