final LinearXYAxis xAxis = (LinearXYAxis) frame.getXAxis();
final XYAxis yAxis = frame.getYAxis();
xAxis.setTickMarkCalculator(new TimeTickMarkCalculator());
xAxis.setFormat(new DateNumberFormat(new SimpleDateFormat("yyyy-MM-dd\nHH:mm:ss.SSS")));
final LinearXYPlotLine line = new LinearXYPlotLine(xAxis, yAxis, XYDimension.X);
line.setForeground(Color.white);
final CompressingXYDataset d = new CompressingXYDataset(line, new DefaultCompressor());
d.setTruncationPoint(0);
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);
frame.getLocationDisplay().setFormat(new MessageFormat("<html><b>X:</b> {0,date,HH:mm:ss} <b>Y:</b> {1}</html>"));
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;
long startTime = System.currentTimeMillis();
@Override
public void run() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
long now = System.currentTimeMillis();
xAxis.setStart(now / 1000 * 1000 - 9000);
xAxis.setEnd(now / 1000 * 1000 + 1000);
d.setTruncationPoint(xAxis.getStart());
for(int i = 0; i < 10; i++) {
double x2 = now + i;
double y2 = Math.sin(x2 / 2000.0);
d.add(x2, y2);
marker.setValue(x2);
marker2.setValue(y2);
x++;
if(x % 100 == 0) {
System.out.println("Dataset size: " + d.getPointCount());
System.out.println("Points per pixel: " + d.getPointCount() / (double) xAxis.getWidth());
System.out.println("Points per second: " + 1000 * x / (double) (now - startTime));
}
}
}
});
}
}, 10, 10);
line.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
d.setCompressionOffset(xAxis.getStart());
d.setCompressionScale((xAxis.getEnd() - xAxis.getStart()) / xAxis.getWidth());
}