0

我在 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);
}

}

4

1 回答 1

1

此代码中只有一个系列。您尝试添加另一个系列的代码在哪里?

一般的做法是这样的:

mDataset.addSeries(0, time_series);
mRenderer.addSeriesRenderer(0, time_renderer);
//...
//...
mDataset.addSeries(1, some_other_series);
mRenderer.addSeriesRenderer(1, some_other_renderer);
//...
//...
于 2012-05-16T10:21:10.783 回答