Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
145
Set Different Values for slice and legend in Pie Chart
posted

Hello,
Que 1:

In Pie chart, legend and slice of pie chart displayed same value. How can i provide different value. Like
- for legend I want to set label and
- for slice I want to display percentage.

 For example I want to display different plan types like commercial ,PDP ,MPDP in legend and want display ratio of plan  types on slice of pie chart like commercial-25%, PDP-50%, MPDP 25%.
How can i implement that?
->Please refer below snippet.


public void pieChart(int pieno)
{
int total=0;
if(parseData.get(0).get(index).size() > 0)
{

ArrayList percent= new ArrayList();
ArrayList percent1= new ArrayList();
tv.setText(title+" - "+parseData.get(0).get(index).get(pieno).get(pieno).get(0).get(0));
List yaxis= new ArrayList();
for(int j=0;j<parseData.get(0).get(index).get(pieno).get(pieno).get(1).size();j++)
{
if(parseData.get(0).get(index).get(pieno).get(pieno).get(1).get(j).equalsIgnoreCase(""))
{
yaxis.add(0.0);
percent.add(0);
}
else
{
double ydata=Double.parseDouble(parseData.get(0).get(index).get(pieno).get(pieno).get(1).get(j));
int val=(int)ydata;
total+=val;
percent.add(val);
yaxis.add(ydata);

}
}

for(int i=0;i<percent.size();i++)
{
Integer hundred = 100;
Log.e("val>>", String.valueOf(percent.get(i)));
Log.e("val>>", String.valueOf( (float)percent.get(i)/(float)total+""));
float val=((float)percent.get(i)/(float) total ) * (float)hundred;
int newVal=Math.round(val);
if(newVal == 0)
{
percent1.add(xAxisData.get(i)+" - "+"0%");
}
else
{
percent1.add(xAxisData.get(i)+" - "+String.valueOf(newVal)+"%");
}
}
testData2 = new clsmyDataSample(percent1,yaxis);




FrameLayout frame = new FrameLayout(context);


frame.setBackgroundResource(R.drawable.customborderchart);


view.setDataSource(testData2);
view.setLabelMemberPath("label");
view.setTextSize(8);
view.setLabelsPosition(LabelsPosition.BESTFIT);
view.setLabelExtent(5.0);
view.setValueMemberPath("Value");
view.setAllowSliceExplosion(true);
view.setExplodedRadius(0.2);
view.setRadiusFactor(0.7);
// view.setPadding(0, 0, 0, 25);
view.setLeaderLineType(LeaderLineType.ARC);
//view.setLongClickable(true);


view.setOnSliceClickListener(new OnSliceClickListener() {
public void onSliceClick(PieChartView view, SliceClickEvent event) {
event.setIsExploded(!event.getIsExploded());
event.setIsSelected(!event.getIsSelected());
}
});

}

  • 28750
    Offline posted

    Hello Kosta,

    Thank you for your post.

    To set the Legend labels to be different than the labels that exist in the PieChartView, I would recommend that you use the setLegendLabelMemberPath method of the PieChartView. By default, the legend will pull its label path from the PieChartView's LabelMemberPath property if this is not set, which is likely why you are currently seeing the same values in the Legend as you are seeing in the PieChartView.

    By setting the LegendLabelMemberPath this way, this will ensure that you see a different label for the legend as in the slices of the pie chart, and you can set the pie chart's LabelMemberPath to the property on your data item that represents the percentage and set the LegendLabelMemberPath to the property that represents the plan type in your case.

    I hope this helps you. Please let me know if you have any other questions or concerns on this matter.

    Sincerely,
    Andrew
    Associate Developer
    Infragistics Inc.
    www.infragistics.com/support