This is a migrated thread and some comments may be shown as answers.

Pie and Doughnut series problem in fragment

5 Answers 147 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jay
Top achievements
Rank 1
Jay asked on 25 Jul 2014, 06:36 AM
not able to load data in pie series

5 Answers, 1 is accepted

Sort by
0
Jay
Top achievements
Rank 1
answered on 25 Jul 2014, 06:38 AM
here is my example code

public RadPieChartView pieChartView()
    {RadPieChartView doughnutchartView=null;

        try
        {
             initData();
            
            
            doughnutchartView = new RadPieChartView(getActivity());

            DoughnutSeries doughnutSeries = new DoughnutSeries(getActivity());

            doughnutSeries.setValueBinding(new DataPointBinding()
            {
                @Override
                public Object getValue(Object o)
                {
                    return ((MonthResults) o).getResult();
                }
            });
            doughnutSeries.setData(this.monthResults);

            doughnutchartView.getSeries().add(doughnutSeries);
            
            
        } catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return doughnutchartView;

    }



private void initData() {
        
    
        
        monthResults = new ArrayList<MonthResults>();
        monthResults.add(new MonthResults("Jan", 25,10));
        monthResults.add(new MonthResults("Feb", 30,10));
        monthResults.add(new MonthResults("Mar", 40,20));
        
//        monthResults.add(new MonthResults("Mar", 15));
//        monthResults.add(new MonthResults("Apr", 17));
//        monthResults.add(new MonthResults("May", 21));
//        monthResults.add(new MonthResults("Jun", 28));
//        monthResults.add(new MonthResults("Jul", 32));
//        monthResults.add(new MonthResults("Aug", 48));
//        monthResults.add(new MonthResults("Sep", 51));
//        monthResults.add(new MonthResults("Oct", 42));
//        monthResults.add(new MonthResults("Nov", 57));
//        monthResults.add(new MonthResults("Dec", 60));

    }

    public class MonthResults {
        private String month;
        private double result,resultY;

        public double getResultY() {
            return resultY;
        }





        public void setResultY(double resultY) {
            this.resultY = resultY;
        }





        public MonthResults(String month, double i,double d) {
            this.setMonth(month);
            this.setResult(i);
            this.setResultY(d);
        }

        
        


        public double getResult() {
            return result;
        }





        public void setResult(double result) {
            this.result = result;
        }





        public String getMonth() {
            return month;
        }


        public void setMonth(String month) {
            this.month = month;
        }


        }
0
Antony Jekov
Telerik team
answered on 25 Jul 2014, 08:49 AM
Hello Jay,

Thank you for contacting the Android team.

I reviewed your sample code and I didn't find anything wrong with it. I got a doughnut chart with 3 values visible on my screen.

The android platform might sometimes prove to be tricky when debugging. I recommend you to go from the bottom up. First make sure you get the wanted result in the most simple way possible:
public class MainActivity extends ActionBarActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(pieChartView());
    }
 
    public RadPieChartView pieChartView() {
        RadPieChartView doughnutchartView = null;
 
        try {
            initData();
 
 
            doughnutchartView = new RadPieChartView(this);
 
            DoughnutSeries doughnutSeries = new DoughnutSeries(this);
 
            doughnutSeries.setValueBinding(new DataPointBinding() {
                @Override
                public Object getValue(Object o) {
                    return ((MonthResults) o).getResult();
                }
            });
            doughnutSeries.setData(this.monthResults);
 
            doughnutchartView.getSeries().add(doughnutSeries);
 
 
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return doughnutchartView;
 
    }
 
    List<MonthResults> monthResults;
 
    private void initData() {
        monthResults = new ArrayList<MonthResults>();
        monthResults.add(new MonthResults("Jan", 25, 10));
        monthResults.add(new MonthResults("Feb", 30, 10));
        monthResults.add(new MonthResults("Mar", 40, 20));
 
//        monthResults.add(new MonthResults("Mar", 15));
//        monthResults.add(new MonthResults("Apr", 17));
//        monthResults.add(new MonthResults("May", 21));
//        monthResults.add(new MonthResults("Jun", 28));
//        monthResults.add(new MonthResults("Jul", 32));
//        monthResults.add(new MonthResults("Aug", 48));
//        monthResults.add(new MonthResults("Sep", 51));
//        monthResults.add(new MonthResults("Oct", 42));
//        monthResults.add(new MonthResults("Nov", 57));
//        monthResults.add(new MonthResults("Dec", 60));
    }
 
    public class MonthResults {
        private String month;
        private double result, resultY;
 
        public double getResultY() {
            return resultY;
        }
 
 
        public void setResultY(double resultY) {
            this.resultY = resultY;
        }
 
 
        public MonthResults(String month, double i, double d) {
            this.setMonth(month);
            this.setResult(i);
            this.setResultY(d);
        }
 
 
        public double getResult() {
            return result;
        }
 
 
        public void setResult(double result) {
            this.result = result;
        }
 
 
        public String getMonth() {
            return month;
        }
 
 
        public void setMonth(String month) {
            this.month = month;
        }
 
 
    }
}
Here is your code inside a simple activity without any use of xml or fragments. I am just calling the setContentView(pieChartView()); so that I can make sure this code works.

It apparently does on my side, so I would go from there and check first the xml and the way the chart is being added to the layout, then the way the fragment is being set and added to the context. Somewhere there lies the issue.

If you are creating the chart in the code rather that the xml layout, you might want to specify the layout parameters of the chart when adding it to the layout. The chart needs to be set to MATCH_PARENT for both width and height and the parent must not depend on the chart to know its size.

I would be happy to help you out further if you need me to, but I will need to see some more of your code, since the snippet you sent me is perfectly fine.

Let me know how this goes.

Thank you for your time and all best! 

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jay
Top achievements
Rank 1
answered on 25 Jul 2014, 11:11 AM
Thank u for the reply

i am using Fragment so it only load in  View onCreateView method not in its child view like RelativeLayout or any sub View class

@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        View view=null;
        
        view =inflater.inflate(R.layout.fragment_main, null);
        view=pieChartView();
        return view;
        
        
    }

please help me out

Regards,
Jay
0
Antony Jekov
Telerik team
answered on 28 Jul 2014, 07:49 AM
Hello Jay,

You need to create a new fragment and to add it to your activity like this:
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
        getSupportFragmentManager().beginTransaction().add(R.id.container, new MyFragment()).commit();
    }
Then you need to return the view you wish to display in this fragment, in your case this would be the chart itself. Use this in your fragment:
@Override
        public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
            return pieChartView();
        }

This works as expected on my side. If you have any additional struggles I recommend you check out the fragments section in the Android documentation - Fragment class 

I hope this helps. Please feel free to add to this ticket, should you have any additional struggles.

Thank you for your time and all best!

Regards,
Antony Jekov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Jay
Top achievements
Rank 1
answered on 29 Jul 2014, 05:07 AM
thank u so much ,
it helps me a lot
Tags
Chart
Asked by
Jay
Top achievements
Rank 1
Answers by
Jay
Top achievements
Rank 1
Antony Jekov
Telerik team
Share this question
or