yAxis.setPreferredSize(new Dimension(100, 50));
xAxis.setStartMargin(100);
final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.Y);
line.setForeground(Color.white);
final SimpleXYDataset d = new SimpleXYDataset(line);
d.setMaxCapacity(1000);
d.setXData(line.getXData());
d.setYData(line.getYData());
final XYMarkerLine marker = new XYMarkerLine(xAxis, 60);
marker.setForeground(Color.yellow);
XYPlotContents contents = frame.getContents();
contents.add(marker);
final XYMarkerLine marker2 = new XYMarkerLine(yAxis, .5);
marker2.setForeground(Color.red);
contents.add(marker2);
frame.addPlotLine(line);
yAxis.setStart(0);
yAxis.setEnd(10);
xAxis.setStart(-1.2);
xAxis.setEnd(1.2);
frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0} <b>Y:</b> {1,date,HH:mm:ss}</html>"));
frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>Δx:</b> {0} <b>Δy:</b> {1,date,HH:mm:ss}</html>"));
timer.schedule(new TimerTask() {
int x = 0;
@Override
public void run() {
x++;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
long now = System.currentTimeMillis();
yAxis.setStart(now / 1000 * 1000 - 9000);
yAxis.setEnd(now / 1000 * 1000 + 1000);
double y2 = now;
double x2 = Math.sin(y2 / 2000.0);
d.add(x2, y2);
marker.setValue(x2);
marker2.setValue(y2);
}
});
}