Refresh Jchart Issue

A discussion forum for JFreeChart (a 2D chart library for the Java platform).
Locked
petersh
Posts: 1
Joined: Sun May 27, 2018 10:40 am
antibot: No, of course not.

Refresh Jchart Issue

Post by petersh » Tue Jun 12, 2018 1:26 am

I have recently started using JFreechart recently
I am adding a point to the series in Jfreechart (scatter chart) and then putting the thread to sleep for 3 seconds. I want to simultaneously show the point on the jfreechart. The above logic is in a loop, so i want a delay of 3 secs before plotting the next point.

The problem i am facing is, the point is not displayed on the chart immediately, only once the entire loop is executed all the points are shown.
I have also called revalidate and refresh but its not working.

Can anyone please please help me...I am not able to find the solution.

Below is my code :-

do {
double valX1,valY1;
valX1 = fRandom.nextGaussian();
valY1 = fRandom.nextGaussian();
double valX = Math.round(valX1 * 100.0) / 100.0;
double valY = Math.round(valY1 * 100.0) / 100.0;


double ptx1 = ((valX - xc) * tankRange)/1000;
double pty1 = ((valY - yc) * tankRange)/1000;

ptx=Math.round(ptx1 * 100.0) / 100.0;
pty=Math.round(pty1 * 100.0) / 100.0;

if ((ptx >= -(Et.getTurretWd()/2) && ptx <= Et.getTurretWd()/2) && (pty >= -(Et.getTurretHt()/2) && pty <= (Et.getTurretHt()/2))){
hitCnt++;
series.add(ptx, pty);
chartPanel.repaint();
chartPanel.revalidate();
isHit = true;
//insert into rounds table with flag as 'H' and exit the loop
try {
String strqry1 = "Insert into RoundDet (ShootId,TankID,HitMiss, XCoord, YCoord, Createddate, Modifieddate) values (" + shootid + "," + Ot.Tankid + ", 'H' ," + ptx + "," + pty + ",'" + sqlDate + "' ,'" + sqlDate +"')";
System.out.println(strqry1);
stmt.execute(strqry1);

} catch (SQLException e) {
e.printStackTrace();
} finally {
}
break;

} else {
series1.add(ptx, pty);
chartPanel.repaint();
chartPanel.revalidate();

}

Thanks, Peter
Lay ma giam gia Lazada tai MHR

John Matthews
Posts: 513
Joined: Wed Sep 12, 2007 3:18 pm

Re: Refresh Jchart Issue

Post by John Matthews » Tue Jun 12, 2018 3:08 am

You may be blocking the event dispatch thread. Instead, pace the animation using a javax.swing.Timer, as shown here, or a javax.swing.SwingWorker, as shown here.

Locked