0

这是我正在使用的代码。我已经删除了生成行中显示的其他信息的代码,并且只提供了与创建和添加饼图相关的代码。如果我删除“layout.addView(mChartView);”行 然后生成表格并显示所有其他信息,但当然,它不显示饼图。

    TableLayout table = (TableLayout) findViewById(R.id.table);
    TableRow row = (TableRow) findViewById(R.id.tableRow);

    LayoutInflater inflater = getLayoutInflater();
    GlobalData global = ((GlobalData)getApplicationContext());
    for( int i = 0; i < global.getData(0).size(); i++){

        DataModel current = global.getData(0).get(i);

        row = (TableRow)inflater.inflate(R.layout.tablerow, table, false);
        row.setTag(i);
        row.setClickable(true);

        //pie chart
        RelativeLayout layout = (RelativeLayout) findViewById(R.id.chart);
        int[] values = {50, 100};
        CategorySeries series = new CategorySeries("Market share");
        int k = 0;
        for (int value : values) {
            series.add("Section " + ++k, value);
        }

        int[] colors = new int[] { Color.BLUE, Color.YELLOW };

        DefaultRenderer renderer = new DefaultRenderer();
        for (int color : colors) {
            SimpleSeriesRenderer r = new SimpleSeriesRenderer();
            r.setColor(color);
            renderer.addSeriesRenderer(r);
        }

        mChartView = ChartFactory.getPieChartView(null, series, renderer);
        layout.addView(mChartView);

        // Add the TableRow to the TableLayout
        table.addView(row);

此代码片段位于视图的 onCreate 事件中。

感谢您尝试提供帮助。

4

2 回答 2

1

I found the issue: (I do feel stupid); I had referenced the layout in the following manner

//pie chart
RelativeLayout layout = (RelativeLayout) findViewById(R.id.chart);

I should have

//pie chart
 RelativeLayout layout = (RelativeLayout)row.findViewById(R.id.chart);

When I added row.findViewByID it all works

Wood for the trees problem Sorry for wasting your valuable time.

于 2012-09-03T02:36:20.450 回答
0

我建议您先尝试一种更简单的方法。尝试使用 aLinearLayout并查看是否有效,然后再尝试使用 a TableLayout。要在 LinearLayout 中嵌入 AChartEngine,请参阅

于 2012-08-29T05:49:05.510 回答