0

Here is the code that I am using. I have removed the code that generates other information displayed in the row and have provided only the code related to the creation and addition of the pie chart. If I remove the line "layout.addView(mChartView);" then the table is produced and it show all the other information, but of course , it does not show the pie chart.

    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);

This code snippet is located in the onCreate event of the view.

Thank you for trying to help.

  • 1
    Have you tried to search anything to related this? – Praveenkumar Aug 28 '12 at 10:45
  • First create a table. Then create a row within that table. Next create a cell within that row, and finally draw your pie chart using aChartEngine. Seriously though -- first: try. second: if you do not succeed, post what you have tried and what its results were when you ask for help. Skipping the first step is really not an option at stackoverflow. – mah Aug 28 '12 at 10:48
  • Thank you, I have searched for answers to this in stackoverflow and elsewhere with no success. I can create a pie graph and display it on a view that is not a problem. This issue arises when I try and add the pie graph view to a table row during the inflation process. I will try and add some code now so you can see what I am doing. – Brian Oldfield Aug 28 '12 at 23:51

2 Answers2

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.

0

I suggest you try with a simpler approach first. Try with a LinearLayout and see if that is working and only afterwards try with a TableLayout. For embedding an AChartEngine inside a LinearLayout, see this.

Community
  • 1
  • 1
Dan D.
  • 32,246
  • 5
  • 63
  • 79
  • Dan, Thank you. Yes I have tried that and Yes the charts are always displayed in a Liniarlayout. In fact for several views in my android app the charts all display well and the aChartEngine is superb. It is just the insertion of a chart into a row of a table that is giving me trouble. I think it may have to do with the context variable but I am not sure. – Brian Oldfield Aug 29 '12 at 06:43