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

How to show NameField or Label on Android pie series or doughnut series

12 Answers 119 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 29 Jul 2014, 06:10 AM
please help me out for doughnut series like how to show field area name or label .
Or how to show area's data belong to some value like given image

12 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 30 Jul 2014, 08:04 AM
Hi Jay,

Thanks for the question.
You need to use RadLegendView and to customize it as required.
Please write again if you need further assistance.

Regards,
Victor
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 30 Jul 2014, 09:26 AM
hi,

thank u for the reply but i am using RadLegendView for bar chart and line chart . i need to use legend or piedatapoint for doughnut and pie chart .

can you please provide me some example or text help

regards,
jay
 
0
Victor
Telerik team
answered on 04 Aug 2014, 11:57 AM
Hi Jay,

Thanks for the question. In order to customize the legend title of the pie slices you can create your own pie series by inheriting from the PieSeries class. Then you have to override the getLegendTitle() method and return approriate information for each data point.

For example:

public class CustomPieSeries extends PieSeries {
    public CustomPieSeries(Context context) {
        super(context);
    }
    @Override
    protected String getLegendTitle(PieDataPoint point) {
        return ((DataObject)point.getDataItem()).getName();
    }
}

This example assumes that the data you provide to your chart is a collection of DataObject instances and that each DataObject has a getName() method.

Please write again if you have more questions.

Regards,
Victor
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 04 Aug 2014, 12:38 PM
I tried as per above post but still its showing some catch

please help for it , here is the code

DataPoint.java


public class DashboardConverter extends PieSeries {
    public DashboardConverter(Context context) {
        super(context);
    }
    @Override
    protected String getLegendTitle(PieDataPoint point) {
        return ((DataPoint)point.getDataItem()).getDataItem().toString();
    }
}



MonthResults.java

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

}



mainactivity




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

            PieDataPoint dataPoint  = new PieDataPoint();
            
        
            dataPoint.setLabel(monthResults);
            
            DashboardConverter dashboardConverter  = new DashboardConverter(getBaseContext());
            dashboardConverter.getLegendTitle(dataPoint);
            
            
            
            doughnutchartView.getSeries().add(doughnutSeries);
        doughnutchartView.addView(dashboardConverter);
            

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

    }



onCreate(){
 setContentView(pieChartView());
}
0
Victor
Telerik team
answered on 04 Aug 2014, 01:32 PM
Hi Jay,

Thanks for writing.
In your case you must inherit from DoughnutSeries instead of PieSeries.
Then your code will look like this:
public RadPieChartView pieChartView()
    {
         
        initData();
             
        DashboardConverter doughnutSeries = new DashboardConverter(this);
 
            doughnutSeries.setValueBinding(new DataPointBinding()
            {
                @Override
                public Object getValue(Object o)
                {
                    return ((MonthResults) o).getResult();
                }
            });
        doughnutSeries.setData(this.monthResults);
 
    RadPieChartView doughnutchartView = new RadPieChartView(this);
        doughnutchartView.getSeries().add(doughnutSeries);
        return doughnutchartView;
    }

And your DashboardConverter will look like this:
public class DashboardConverter extends DoughnutSeries {
    public DashboardConverter(Context context) {
        super(context);
    }
    @Override
    protected String getLegendTitle(PieDataPoint point) {
        return ((MonthResults)point.getDataItem()).toString();
    }
}


Regards,
Victor
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 05 Aug 2014, 04:26 AM
HI victor,

i have used same code as u have given but still on the screen there is no any legend or data points

here i have attached the screen shot
please let me know the solution

regards,
jay
0
Jay
Top achievements
Rank 1
answered on 05 Aug 2014, 04:59 AM
hi ,

its done , thank you for the help.
my mistake i didnt add legentview

here is the complete code


public RadPieChartView pieChartView() {

        initData();

        DashboardConverter doughnutSeries = new DashboardConverter(this);

        RadPieChartView doughnutchartView = new RadPieChartView(this);
        RadLegendView legendView = new RadLegendView(this);
        legendView.setLegendProvider(doughnutchartView);

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(460,
                100);
        params.setMargins(10, 10, 10, 10);
        legendView.setLayoutParams(params);

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

        doughnutSeries.setShowLabels(true);
        doughnutchartView.addView(legendView);
        doughnutchartView.getSeries().add(doughnutSeries);
        return doughnutchartView;
    }


Regards,
jay
0
Victor
Telerik team
answered on 05 Aug 2014, 07:45 AM
Hello Jay,

It's great that everything works.
However, I suggest that you don't add the legend to the chart itself. Instead your should add it as a sibling in a parent panel. In the next version RadChartViewBase and its inheritors will no longer be view groups and your code will not work. We are doing this as a performance improvement and using the chart as a layout panel is not supported in the first place.

Please write again if need assistance with our controls.

Regards,
Victor
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 05 Aug 2014, 08:44 AM
hi,

can you please guide me how to add sibling in parent view. and i am planning to buy the license version so can u let me know when r u going to release updated RadChartViewBase.

Regards,
jay
0
Victor
Telerik team
answered on 07 Aug 2014, 08:45 AM
Hello Jay,

Adding the legend as a sibling means that you should not add the legend to the chart itself, but to the parent of the chart. For example if your chart is inside a RelativeLayout, you should add the legend to this RelativeLayout, not inside the chart.

The updated chart will be available for the next official release. It is scheduled for October.

Regards,
Victor
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
Santhosh
Top achievements
Rank 1
answered on 24 Sep 2015, 11:04 AM

hi,

 

i am using Doughnut and Pie chart and now this class is not working for new version

 

public class LegendView
{

    public class DoughnutSeriesLegend extends DoughnutSeries
    {
        public DoughnutSeriesLegend(Context context)
        {
            super(context);
        }

        @Override
        protected String getLegendTitle(PieDataPoint point)
        {
            return ((ChartData) point.getDataItem()).getCategory();
        }

    }
    
    
    public class PieSeriesLegend extends PieSeries
    {
        public PieSeriesLegend(Context context)
        {
            super(context);
        }

        @Override
        protected String getLegendTitle(PieDataPoint point)
        {
            return ((ChartData) point.getDataItem()).getCategory();
        }

    }

 

it shows error in constructor super(context);

 

can you please help me out how i can add legend to doughnut and pie chart series

 

Regards,

Santhosh​

0
Victor
Telerik team
answered on 29 Sep 2015, 08:37 AM
Hi Jay,

Thanks for writing.
You can simply remove the Context argument from your constructors. It is not necessary since the series are not longer views. We changed that quite a while ago. Now you have less code :).
Please write again if you need further assistance.

Regards,
Victor
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Chart
Asked by
Jay
Top achievements
Rank 1
Answers by
Victor
Telerik team
Jay
Top achievements
Rank 1
Santhosh
Top achievements
Rank 1
Share this question
or