JFreeChart的鼠标移动实时监听横纵坐标信息,效果有了,但是用了update(Graphics g)图表一直闪

publicvoidchartMouseMoved(ChartMouseEventchartMouseEvent){point=chartMouseEvent.getTr... public void chartMouseMoved(ChartMouseEvent chartMouseEvent) {
point = chartMouseEvent.getTrigger().getPoint();
mouseX = chartMouseEvent.getTrigger().getX();
mouseY = chartMouseEvent.getTrigger().getY();
Point2D point2D = this.chartPanel.translateScreenToJava2D(new Point(mouseX, mouseY));
ChartRenderingInfo info = this.chartPanel.getChartRenderingInfo();
rectangle2D = chartPanel.getScreenDataArea();
yValue = xyplot.getRangeAxis().java2DToValue(point2D.getY(), info.getPlotInfo().getDataArea(), RectangleEdge.RIGHT);
xValue = xyplot.getDomainAxis().java2DToValue(point2D.getX(), info.getPlotInfo().getDataArea(), RectangleEdge.BOTTOM);
refreshAxis(mouseY, mouseX);
}
public void refreshAxis(int mouseY, int mouseX) {
Graphics g = this.getGraphics();
update(g);
int recW = (int) (rectangle2D.getX() + rectangle2D.getWidth());
int recX = (int) rectangle2D.getX();
int recY = (int) rectangle2D.getY();
int recH = (int) (rectangle2D.getY() + rectangle2D.getHeight());
if (mouseX < recW && mouseX > recX && mouseY < recH && mouseY > recY) {
g.drawLine(recX, mouseY, recW, mouseY);
g.drawLine(mouseX, recY, mouseX, recH);
}
}

@Override
public void update(Graphics g) {
if (g.getClip() == null) {
paint(g);
int recX = (int) rectangle2D.getX();
int recY = (int) rectangle2D.getY();
int recH = (int) (rectangle2D.getY() + rectangle2D.getHeight());
int recW = (int) (rectangle2D.getX() + rectangle2D.getWidth());
if (mouseX < recW && mouseX > recX && mouseY < recH && mouseY > recY) {
g.drawString(String.valueOf((int)(yValue)), mouseX + 20, mouseY + 1);
g.drawString(dateFormat1.format(new Date((long) xValue)), mouseX + 20,mouseY + 12);
}
}
}
这个事鼠标监听的代码,JFreeChart显示的那部分因为有点大没有给出来,找个高手帮帮忙,解决了另外追加100分。。。。
展开
 我来答
amount79
2012-01-13 · 贡献了超过217个回答
知道答主
回答量:217
采纳率:0%
帮助的人:110万
展开全部
自己建立一个windows工程。在消息相应的那个switch中加入下面的case case WM_LBUTTONDOWN: char p[128]; sprintf(p,"x坐标:%d y坐标:%d",LOWORD(
追问
我已经实现了效果,但是用了update()只是屏幕会闪,你说得这个我没看明白
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式