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(-1.2);
yAxis.setEnd(1.2);
xAxis.setStart(0);
xAxis.setEnd(10);
final MessageFormat f = new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} <b>Y:</b> {1}</html>");
frame.getLocationDisplay().setFormat(new Format() {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
Object[] args = (Object[]) obj;
double d = ((Number) args[0]).doubleValue();
Object[] args2 = new Object[] { d + start, args[1] };
return f.format(args2, toAppendTo, pos);
}
@Override
public Object parseObject(String source, ParsePosition pos) {
throw new UnsupportedOperationException();
}
});
frame.getSlopeLineDisplay().setFormat(new MessageFormat("<html><b>Δx:</b> {0,date,HH:mm:ss} <b>Δy:</b> {1}</html>"));
for(int x = 0; x < 900; x++) {
double x2 = x / 10.0;
double y2 = Math.sin(x2 / 10.0);
d.add(x2, y2);
}
timer.schedule(new TimerTask() {
int x = 0;
@Override
public void run() {
x++;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
long now = System.currentTimeMillis() - start;
xAxis.setStart(now / 1000 * 1000 - 9000);
xAxis.setEnd(now / 1000 * 1000 + 1000);
double x2 = now;
double y2 = Math.sin(x2 / 2000.0);
d.add(x2, y2);
marker.setValue(x2);
marker2.setValue(y2);
}
});
}
}, 100, 100);