android pie so文件,android - 百分比如何在Android中使用Mpchartandroid在Piechart中显示右侧 - SO中文参考 - www.soinside.com...

百分比如何在Android中使用Mpchartandroid在Piechart中显示右侧

问题描述 投票:0回答:1

您好,在下面的代码中,我实现了带有随机百分比的饼图,它想显示从饼图中得到的百分比,它们要显示为颜色,文本和百分比。谁能帮我解决这个问题。Insteads of 0 1 2 want to show percentagespublic final String[] parties = new String[] {"Completed","In Completed", "Scheduled"};

private void setData() {

ArrayList entries = new ArrayList<>();

// NOTE: The order of the entries when being added to the entries array determines their position around the center of

// the chart.

for (int i = 0; i < 3 ; i++) {

entries.add(new PieEntry((float) ((Math.random() * 10) + 10 / 5),

parties[i % parties.length].concat(":".concat(String.valueOf(i))),

getActivity().getResources().getDrawable(R.drawable.share)));

}

PieDataSet dataSet2 = new PieDataSet(entries, "");

dataSet2.setDrawIcons(false);

dataSet2.setSliceSpace(3f);

dataSet2.setIconsOffset(new MPPointF(0, 40));

dataSet2.setSelectionShift(5f);

// add a lot of colors

// ArrayList colors = new ArrayList<>();

//

// for (int c : ColorTemplate.VORDIPLOM_COLORS)

// colors.add(c);

//

// for (int c : ColorTemplate.JOYFUL_COLORS)

// colors.add(c);

//

// for (int c : ColorTemplate.COLORFUL_COLORS)

// colors.add(c);

//

// colors.add(ColorTemplate.getHoloBlue());

int endColor3 = ContextCompat.getColor(getContext(), android.R.color.holo_green_dark);

int endColor4 = ContextCompat.getColor(getContext(), android.R.color.holo_red_dark);

int endColor5 = ContextCompat.getColor(getContext(), android.R.color.holo_orange_dark);

List gradientFills = new ArrayList<>();

gradientFills.add(new Fill(endColor3, endColor3));

gradientFills.add(new Fill(endColor4, endColor4));

gradientFills.add(new Fill(endColor5, endColor5));

dataSet2.setColors(endColor3,endColor5,endColor4);

//dataSet.setSelectionShift(0f);

PieData data2 = new PieData(dataSet2);

data2.setValueFormatter(new PercentFormatter(chart2));

data2.setValueTextSize(12f);

data2.setValueTextColor(Color.WHITE);

// data2.setValueTypeface(tfLight);

chart2.setData(data2);

// undo all highlights

chart2.highlightValues(null);

chart2.invalidate();

}

android

pie-chart

1个回答

热门问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值