Or how to show area's data belong to some value like given image
12 Answers, 1 is accepted
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.
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
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.
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());
}
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.
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
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
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.
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
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.
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​
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