JFreeChart-XYLineChartに画像を描画するのに問題があります。主な問題は、注釈のx座標とy座標がリアルタイムで動的に更新されることです。そのため、私のコードでは、注釈を追加して新しい注釈を描画するためにクリアすると、ちらつきが発生し、ユーザーに迷惑をかけます。
グラフィックを使用してupdate()、paint()、またはrepaint()メソッドを使用してJAVAでのちらつきの問題の例をいくつか確認しましたが、JFreeChartでは実装できないようです。
ちらつきを取り除く方法や、注釈の代わりにJFreeChartで1つのbufferedImageを使用するための回避策について何かアイデアはありますか?
より具体的には、ここに描かれた線と画像があります:
したがって、この十字線(バッファリングされた画像として)は、x軸とy軸の更新された値でプロットラインを上下に移動する必要がありますが、この動きにより、残念ながらちらつきが発生します。
これが私が画像を描く私のコードの部分です-15以上のクラスと5kの書かれたコードがあるので私は推測するSSCCEを提供することはできません:
// 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);
}
}
});