1

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

这有效:

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
    }

为什么相同的代码在一个活动中不能在另一个活动中工作我必须说在第二个代码示例中它加载到一个选项卡活动。

4

1 回答 1

1

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

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

添加这个我的应用程序可以正常工作。:)

于 2013-11-18T12:32:35.480 回答