achartengine意图不会开始

时间:2013-10-07 12:47:23

标签: android graph charts achartengine

我正在开发一个使用chartengine lib绘制用户数据的应用程序。 我有一个标签应用程序,我的图表绘图可以在任何地方工作,但不是从加载到标签的活动。 我想知道为什么以及是否有人可以帮助我?

这有效:

public class DataActivity extends Activity {
static final int SERIES_NR = 3;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.data_form);
    XYMultipleSeriesRenderer renderer = getTruitonBarRenderer();
    myChartSettings(renderer);
    Intent i = ChartFactory.getBarChartIntent(DataActivity.this, getTruitonBarDataset(), renderer, Type.DEFAULT);
    startActivity(i);   




}


 private XYMultipleSeriesDataset getTruitonBarDataset() {
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        final int nr = 11;
        Random r = new Random();
        ArrayList<String> legendTitles = new ArrayList<String>();
        legendTitles.add("Sales");
        legendTitles.add("Expenses");
        legendTitles.add("age");
        for (int i = 0; i < SERIES_NR; i++) {
            CategorySeries series = new CategorySeries(legendTitles.get(i));
            for (int k = 0; k < nr; k++) {
                series.add(k+ r.nextInt() % 100);
            }
            dataset.addSeries(series.toXYSeries());
        }
        return dataset;
    }

    public XYMultipleSeriesRenderer getTruitonBarRenderer() {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        renderer.setAxisTitleTextSize(16);
        renderer.setChartTitleTextSize(20);
        renderer.setLabelsTextSize(15);
        renderer.setLegendTextSize(15);
        renderer.setMargins(new int[] { 30, 40, 15, 0 });
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(Color.BLUE);
        renderer.addSeriesRenderer(r);

        r = new SimpleSeriesRenderer();
        r.setColor(Color.RED);
        renderer.addSeriesRenderer(r);

        r = new SimpleSeriesRenderer();
        r.setColor(Color.CYAN);
        renderer.addSeriesRenderer(r);

        return renderer;
    }

    private void myChartSettings(XYMultipleSeriesRenderer renderer) {
        renderer.setChartTitle("achart engine by mahdi tajik");
        renderer.setXAxisMin(0.5);
        renderer.setXAxisMax(10.5);
        renderer.setYAxisMin(0);
        renderer.setYAxisMax(210);
        renderer.addXTextLabel(1, "2010");
        renderer.addXTextLabel(2, "2011");
        renderer.addXTextLabel(3, "2012");
        renderer.addXTextLabel(4, "2013");
        renderer.addXTextLabel(5, "2013");
        renderer.addXTextLabel(6, "2013");
        renderer.addXTextLabel(7, "2012");
        renderer.addXTextLabel(8, "20123");
        renderer.addXTextLabel(9, "201223");
        renderer.addXTextLabel(10, "2022213");
        renderer.addXTextLabel(11, "20122223");
        renderer.setYLabelsAlign(Align.RIGHT);
        renderer.setBarSpacing(0.5);
        renderer.setXTitle("Years");
        renderer.setYTitle("Performance");
        renderer.setShowGrid(true);
        renderer.setGridColor(Color.GRAY);
        renderer.setXLabels(0); // sets the number of integer labels to appear
    }


}

但这不起作用:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.static_form);

    initilizeUi();
}

private void plotWeekStatics(){
    XYMultipleSeriesRenderer renderer = getTruitonBarRenderer();
    myChartSettings(renderer);
    Intent i = ChartFactory.getBarChartIntent(StaticActivity.this, getTruitonBarDataset(), renderer, Type.DEFAULT);
    startActivity(i);   

}
 private XYMultipleSeriesDataset getTruitonBarDataset() {
        XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
        final int nr = 11;
        Random r = new Random();
        ArrayList<String> legendTitles = new ArrayList<String>();
        legendTitles.add("Sales");
        legendTitles.add("Expenses");
        legendTitles.add("age");
        for (int i = 0; i < SERIES_NR; i++) {
            CategorySeries series = new CategorySeries(legendTitles.get(i));
            for (int k = 0; k < nr; k++) {
                series.add(k+ r.nextInt() % 100);
            }
            dataset.addSeries(series.toXYSeries());
        }
        return dataset;
    }

    public XYMultipleSeriesRenderer getTruitonBarRenderer() {
        XYMultipleSeriesRenderer renderer = new XYMultipleSeriesRenderer();
        renderer.setAxisTitleTextSize(16);
        renderer.setChartTitleTextSize(20);
        renderer.setLabelsTextSize(15);
        renderer.setLegendTextSize(15);
        renderer.setMargins(new int[] { 30, 40, 15, 0 });
        SimpleSeriesRenderer r = new SimpleSeriesRenderer();
        r.setColor(Color.BLUE);
        renderer.addSeriesRenderer(r);

        r = new SimpleSeriesRenderer();
        r.setColor(Color.RED);
        renderer.addSeriesRenderer(r);

        r = new SimpleSeriesRenderer();
        r.setColor(Color.CYAN);
        renderer.addSeriesRenderer(r);

        return renderer;
    }

    private void myChartSettings(XYMultipleSeriesRenderer renderer) {
        renderer.setChartTitle("achart engine by mahdi tajik");
        renderer.setXAxisMin(0.5);
        renderer.setXAxisMax(10.5);
        renderer.setYAxisMin(0);
        renderer.setYAxisMax(210);
        renderer.addXTextLabel(1, "2010");
        renderer.addXTextLabel(2, "2011");
        renderer.addXTextLabel(3, "2012");
        renderer.addXTextLabel(4, "2013");
        renderer.addXTextLabel(5, "2013");
        renderer.addXTextLabel(6, "2013");
        renderer.addXTextLabel(7, "2012");
        renderer.addXTextLabel(8, "20123");
        renderer.addXTextLabel(9, "201223");
        renderer.addXTextLabel(10, "2022213");
        renderer.addXTextLabel(11, "20122223");
        renderer.setYLabelsAlign(Align.RIGHT);
        renderer.setBarSpacing(0.5);
        renderer.setXTitle("Years");
        renderer.setYTitle("Performance");
        renderer.setShowGrid(true);
        renderer.setGridColor(Color.GRAY);
        renderer.setXLabels(0); // sets the number of integer labels to appear
    }

为什么相同的代码在一个活动中起作用而在另一个活动中起作用 我必须说,在第二个代码示例中,它会加载到tabactivity。

1 个答案:

答案 0 :(得分:1)

我终于解决了这个问题。 问题是我不会在清单文件中定义这样的achartactivity:

<activity android:name="org.achartengine.GraphicalActivity"/>

并添加此我的应用程序正常工作。 :)