Android用のaChartEngineの0.7.0チャートライブラリを使用しています。折れ線グラフを左から右、右に描画し、最終的にビューの外に移動する方法と、チャートビューを左にスクロールする方法を教えてもらえますか?
私のコードは...
public class MainActivity extends Activity {
private GraphicalView view;
private static Thread thread;
private TimeSeries dataSet = new TimeSeries("Heart Beat Rate");
private XYSeriesRenderer renderer = new XYSeriesRenderer();
private XYMultipleSeriesDataset mDataset = new XYMultipleSeriesDataset();
private XYMultipleSeriesRenderer mRenderer = new XYMultipleSeriesRenderer();
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layout_eeg1 = (LinearLayout) findViewById(R.id.chart1);
view = getView(this);
layout_eeg1.addView(view,new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
thread = new Thread() {
public void run() {
for (int i = 0; i < 200; i++) {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
Point p = getDataFromReciver(i);
addNewPoint(p);
view.repaint();
}
}
};
thread.start();
}
private static Point getDataFromReciver(int x) {
return new Point(x, randomData());
}
private static int randomData() {
Random random = new Random();
return random.nextInt(180);
}
private int x;
private int y;
public void Point( int x, int y) {
this.x = x;
this.y = y;
}
private int getX() {
return x;
}
private int getY() {
return y;
}
public MainActivity() {
mDataset.removeSeries(dataSet);
mDataset.addSeries(dataSet);
renderer.setColor(Color.GREEN);
renderer.setLineWidth(2);
double xmax = mRenderer.getXAxisMax();
mRenderer.setXAxisMin(xmax - 5);
//renderer.setPointStyle(PointStyle.SQUARE);
//renderer.setFillPoints(true);
mRenderer.setShowAxes(false);
mRenderer.setShowGridX(false); // X grid helps identify values
mRenderer.setShowLabels(false); // See the values
mRenderer.setXTitle("Milisecond #");
mRenderer.setYTitle("HeartBeat");
mRenderer.removeSeriesRenderer(renderer);
mRenderer.addSeriesRenderer(renderer);
}
private GraphicalView getView(Context context) {
view = ChartFactory.getLineChartView(context, mDataset, mRenderer);
return view;
}
private void addNewPoint(Point p) {
dataSet.add(p.x, p.y);
}
}