应以非常快的方式(10ms)将三个信号绘制为图形中的线。大多数情况下,图表显示三个斜坡没有任何错误。有时在这些坡道上有尖峰。这就是我创造的:
事实证明,大部分时间坡道看起来都很好。有时似乎存在竞争条件,并且斜坡上有尖峰。这些尖峰来自哪里?
private void initDataset() {
mData0 = new TimeSeries(graphName1);
... // add more grapNames
mDatasets = new XYMultipleSeriesDataset();
mDatasets.addSeries(mData0);
... // add mData1 and mData2
}
private void initRenderer(Context context) {
mRenderer0 = new XYSeriesRenderer();
... //setAttributes for example: setColor()
mMultiRenderer = new XYMultipleSeriesRenderer();
... // setAttributes for example: setXTitle()
mMultiRenderer.addSeriesRenderer(mRenderer0);
}
// the code in the other addPointAndRepaint1-2 is the same
public void addPointAndRepaint(PointXY p) {
addPoint(p, mData2);
repaint();
}
private synchronized void addPoint(PointXY p, TimeSeries mData) {
mData.add(p.getX(), p.getY());
// move XAxis boundaries if plot would exceed the right border
if (p.getX() >= mXAxisMax) {
mXAxisMin = mXAxisMin + (p.getX() - mLastXvalue);
mMultiRenderer.setXAxisMin(mXAxisMin);
mXAxisMax = mXAxisMax + (p.getX() - mLastXvalue);
mMultiRenderer.setXAxisMax(mXAxisMax);
}
mLastXvalue = p.getX();
}
} // end addPoint
我用线程尝试了它,它绘制线性上升线。但即便如此,也有尖峰。
@Override
public void onStart() {
super.onStart();
Thread thread = new Thread() {
long initTimestamp = System.currentTimeMillis();
public void run() {
for (int i = 0; i < 10000; ++i) {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (runB) {
t += 0.1;
t = (System.currentTimeMillis()- initTimestamp)/1000.0;
simVal+=0.1;
if (simVal>9)
simVal=-6;
PointXY p0 = new PointXY(t , simVal-2);
PointXY p1 = new PointXY(t+0.02, simVal-1);
PointXY p2 = new PointXY(t+0.04, simVal);
mLineGraph.addPointAndRepaint(p0);
mLineGraph.addPointAndRepaint1(p1);
mLineGraph.addPointAndRepaint2(p2);
} } } };
thread.start();
}
我该怎么办?故障在哪里?
每一行都应该是一致的信号输出。