你好谢谢你的回答。但是我已经有两个系列了。我有一个系列可以生成我的动态图。我试着向你展示我的代码。
public class TraceActivity extends Activity implements Observer
{
private GraphicalView view;
private DynamicGraph dynamicGraph = new DynamicGraph();
private static Thread thread;
private dynamicValue value; //get from observable
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_patient);
/* Thread for the graphs */
thread = new Thread()
{
public void run()
{
for (int i = 0; i < 1000; i++)
{
try
{
Thread.sleep(1000);
}
catch (InterruptedException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
dynamicGraph.setRange();
Point point = getDataFromReceiver(i, value);
// here I try to add the vertical line
dynamicGraph.addNewLine(30, 0);
dynamicGraph.addNewLine(30, 100); // this line is painted at 31,100)
dynamicGraph.addNewPoint(point);
View.repaint();
}
}
};
thread.start();
}
public Point getDataFromReceiver(int x, int parameter)
{
return new Point(x, parameter);
}
@Override
protected void onStart()
{
super.onStart();
runOnUiThread(new ShowView(dynamicgraph.getView(this)));
}
private class ShowView implements Runnable
{
GraphicalView graphView;
public ShowTocoView(GraphicalView graphicalView)
{
graphView = graphicalView;
}
@Override
public void run()
{
if (View == null)
{
LinearLayout layout = (LinearLayout) findViewById(R.id.View);
View = graphView;
layout.addView(View);
}
else
{
View.repaint();
}
}
}
public class DynamicGraph
{
/** The chart view that displays the data. */
private GraphicalView view;
private TimeSeries Data = new TimeSeries("Toco");
private TimeSeries verticalLine = new TimeSeries("");
/** The main dataset that includes all the series that go into a chart. */
private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
/** The main renderer that includes all the renderers customizing a chart. */
private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
/** The most recently created renderer, customizing the current series. */
private XYSeriesRenderer rendererData = new XYSeriesRenderer();
private XYSeriesRenderer rendererVerticalLine = new XYSeriesRenderer();
GraphBuilder graphBuilder = new GraphBuilder(mRenderer, 10);
public TocoGraph()
{
mDataset.addSeries(Data);
mDataset.addSeries(verticalLine);
// graphBuilder build the grid and set the XYSeriesRenderer
graphBuilder.setAndAddXYSeriesRenderer(rendererData, Color.BLACK, 2f);
graphBuilder.setAndAddXYSeriesRenderer(rendererVerticalLine,
Color.rgb(247, 131, 62), 2f);
}
public GraphicalView getView(Context context)
{
view = ChartFactory.getLineChartView(context, mDataset, mRenderer);
return view;
}
public void setRange()
{
graphBuilder.setRange(Data, 100, 0);
}
public void addNewPoint(Point p)
{
Data.add(p.getX(), p.getY());
}
public void addNewLine(int x, int y)
{
verticalLine.add(x, y);
} }
所以我没有理由,为什么垂直线不垂直。你有想法吗?