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分。。。。 展开
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分。。。。 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询