Your example looks wrong. The code that you have will only affect the last point, since the value of numPoints is fixed. We changed it to
Dataset1.setDataPoint(numPoints-1, 10.0 * numPoints, 20 + 20 * (0.5 - Math.random()));
Dataset2.setDataPoint(numPoints-1, 10.0 * numPoints, 30 + 15 * (0.5 - Math.random()));
Dataset3.setDataPoint(numPoints-1, 10.0 * numPoints, 50 + 20 * (0.5 - Math.random()));
for (i=0; i < numPoints; i++)
{
if ((i % 5) == 0)
Dataset3.setValidData(i, false);
}
Dataset4.setDataPoint(numPoints-1, 10.0 * numPoints, 40 + 20 * (0.5 - Math.random()));
and it showed breaks in the line as we expect.