我在AChartEngine中有一个简单的TimeChart,一切正常,但我不知道如何添加第二个系列。我的每次尝试都是由ANR结束的。你有任何想法如何添加另一个系列?这是我的代码:
编辑:我改变了代码,我尝试添加第二行,但我有ANR:public class TestgrafActivity extends Activity {
private XYMultipleSeriesDataset mDataset;
private XYMultipleSeriesRenderer mRenderer;
List<double[]> values = new ArrayList<double[]>();
private GraphicalView mChartView;
private TimeSeries time_series,time_series2;
private LinearLayout layout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
layout = (LinearLayout) findViewById(R.id.chart);
time_series = new TimeSeries("Temperature");
for (int i = 0; i < 50; i++){
long value = new Date().getTime();
time_series.add(new Date(value+(i*1000)), new Random().nextInt(25));
}
time_series2 = new TimeSeries("Temperature2");
for (int i = 0; i < 50; i++){
long value = new Date().getTime();
time_series2.add(new Date(value+(i*1000)), new Random().nextInt(40));
}
mDataset = new XYMultipleSeriesDataset();
mDataset.addSeries(time_series);
mDataset.addSeries(time_series2);
XYSeriesRenderer r = new XYSeriesRenderer();
r.setColor(Color.GREEN);
r.setPointStyle(PointStyle.CIRCLE);
r.setFillPoints(true);
r.setLineWidth(3);
r.setDisplayChartValues(true);
XYSeriesRenderer r2 = new XYSeriesRenderer();
r2.setColor(Color.RED);
r2.setPointStyle(PointStyle.CIRCLE);
r2.setFillPoints(true);
r2.setLineWidth(3);
r2.setDisplayChartValues(true);
mRenderer = new XYMultipleSeriesRenderer();
mRenderer.addSeriesRenderer(r);
mRenderer.addSeriesRenderer(r2);
mRenderer.setAxisTitleTextSize(16);
mRenderer.setChartTitleTextSize(20);
mRenderer.setLabelsTextSize(15);
mRenderer.setLegendTextSize(15);
mRenderer.setPointSize(3f);
mRenderer.setPanEnabled(true, true);
mRenderer.setZoomEnabled(true, true);
mRenderer.addSeriesRenderer(r2);
mRenderer.setClickEnabled(true);
mRenderer.setSelectableBuffer(20);
mRenderer.setPanEnabled(true);
mRenderer.setChartTitle("Temperature");
mRenderer.setXTitle("Time");
mRenderer.setYTitle("Degrees C");
mRenderer.setZoomButtonsVisible(true);
mRenderer.setZoomEnabled(true);
mRenderer.setXLabels(12);
mRenderer.setYLabels(10);
mRenderer.setShowGrid(true);
mRenderer.setXLabelsAlign(Align.RIGHT);
mRenderer.setYLabelsAlign(Align.RIGHT);
mChartView = ChartFactory.getTimeChartView(this, mDataset, mRenderer,
"HH:mm:ss");
layout.addView(mChartView);
}
}
答案 0 :(得分:1)
此代码中只有一个系列。您尝试添加另一个系列的代码在哪里?
一般方法是:
mDataset.addSeries(0, time_series);
mRenderer.addSeriesRenderer(0, time_renderer);
//...
//...
mDataset.addSeries(1, some_other_series);
mRenderer.addSeriesRenderer(1, some_other_renderer);
//...
//...