- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 JFreeChart - XYLineChart 上绘制图像时遇到困难。主要问题是注释的 x 和 y 坐标是实时动态更新的。因此,在我的代码中添加注释并清除注释以绘制新注释会导致闪烁,这对用户来说很烦人。
我已经使用图形检查了 JAVA 上使用 update() 、 Paint () 或 repaint() 方法的一些闪烁问题的示例,但似乎无法在 JFreeChart 上实现。
您是否有任何想法如何消除闪烁或使用 JFreeChart 上的一个 bufferedImage 而不是注释的解决方法?
更具体地说,这里是绘制的线条和图像:
因此,这个十字线(作为缓冲图像)应该随着 x 轴和 y 轴的更新值在绘图线上上下移动。但不幸的是,这种运动会导致闪烁。
这是我绘制图像的代码部分 - 我猜我无法提供 SSCCE,因为有超过 15 个类和 5k 的书面代码:
// After a button clicked on panel
SomeButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
// The chart and XYPlot is already drawn at this point
// Reading the image
try {
myPicture = ImageIO
.read(new File("\\\\Users2\\blabla\\Data\\MyPictures\\x.png"));
} catch (IOException e) {
e.printStackTrace();
}
// Setting up a timer
timer2 = new java.util.Timer();
Object source = event.getSource();
if (source == SomeButton) {
// Setting up a task
task2 = new java.util.TimerTask() {
@Override
public void run() {
double x1;
double y1;
try {
// Getting different x and y values from a microcontroller instantaneously
if (microContConnected()) {
x1 = microCont.getX();
y1 = microCont.getY();
// creating the annotation
XYImageAnnotation ImageAnn = new XYImageAnnotation(x1, y1, myPicture);
// Here is the drawing and clearing made !
plot.addAnnotation(ImageAnn);
pause(50);
plot.clearAnnotations();
}
} catch (SerialPortException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
};
timer2.scheduleAtFixedRate(task2, 50, 50);
}
}
});
最佳答案
看来我自己找到了解决方案;我没有将图像添加到绘图中,而是使用渲染器,并且在使用新坐标添加和删除图片之间没有暂停功能。添加和删除的顺序也是相反的。我必须说,以这种方式工作让我感到惊讶。没有留下任何闪烁;它像剪切图形或双缓冲一样平滑。 :) 这是新代码:
// renderer
final XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer();
// Reading the image
try {
myPicture = ImageIO.read(new File("\\\\Users2\\blabla\\Data\\MyPictures\\x.png"));
} catch (IOException e) {
e.printStackTrace();
}
// Setting up a timer
timer2 = new java.util.Timer();
Object source = event.getSource();
if (source == someButton) {
task2 = new java.util.TimerTask() {
@Override
public void run() {
if (check == true) {
if (microContConnected()) {
x1 = microCont.getX();
y1 = microCont.getY();
renderer.removeAnnotations();
XYImageAnnotation img2 = new XYImageAnnotation(
x1, y1, myPicture);
renderer.addAnnotation(img2,
Layer.FOREGROUND);
}
}
}
};
timer2.scheduleAtFixedRate(task2, 50, 50);
}
关于java - 使用计时器在 JFreeChart 上闪烁 XYImageAnnotation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13844489/
我在 JFreeChart - XYLineChart 上绘制图像时遇到困难。主要问题是注释的 x 和 y 坐标是实时动态更新的。因此,在我的代码中添加注释并清除注释以绘制新注释会导致闪烁,这对用户来
我有一个带有 2 个子图 (XYPlot) 的 JFreeChart。 我有 XYImageAnnotation,我想将其变成按钮,但我找不到监听鼠标点击任何注释的方法。 你知道有什么方法可以做到这一
我是一名优秀的程序员,十分优秀!