本文介绍了在MPAndroidChart的某些情况PieChart中管理文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在MPAndroidChart的PieChart中管理文本.但是当我的文本很困难时,例如True = 2,False = 3,不是= 95,在这种情况下,我的饼图布局非常糟糕.这是我的代码:-
I try to manage text in PieChart of MPAndroidChart. But when my text is difficult situation like True = 2, False = 3 , Not = 95, in this situation my pie chart layout is very bad.Here is my code :-
fun setupPieChartView() {
mPie = findViewById(R.id.piechart)
mPie?.setUsePercentValues(true)
val desc: Description = Description()
desc.text = "PieChart"
mPie?.description = desc
val legend: Legend? = mPie?.legend
legend?.horizontalAlignment = Legend.LegendHorizontalAlignment.LEFT
val value = Arrays.asList(trueAns.toFloat(), wrongAns.toFloat(), noAns.toFloat())
val label = Arrays.asList("True", "false", "Not")
val entry = ArrayList<PieEntry>()
for (i in value.indices) {
entry.add(PieEntry(value.get(i), label.get(i)))
}
val dataSet = PieDataSet(entry, "Result")
dataSet.setColors(Color.GREEN, Color.RED, Color.GRAY);
dataSet.setDrawValues(true)
val pieData = PieData(dataSet)
pieData.setValueFormatter(PercentFormatter())
pieData.setValueTextSize(10f)
pieData.setValueTextColor(Color.WHITE)
mPie?.data = pieData
}
结果是这样的:-
在我的饼图中,数据的格式设置不正确.帮帮我吧
here in my Pie-Chart data is not set in good format . Help me for this
推荐答案
您需要此行,因此您的标签将位于图形之外:
You need this line, so your labels will be outside graph:
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
价值将在外部.您还可以像这样控制位置,行长和颜色:
And value will be outside . You can also control position, line length and coloring like this:
pieData.setValueTextColor(Color.BLACK);
dataSet.setValueLinePart1OffsetPercentage(10.f);
dataSet.setValueLinePart1Length(0.43f);
dataSet.setValueLinePart2Length(.1f);
dataSet.setValueTextColor(Color.BLACK);
dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
mPie.setEntryLabelColor(Color.BLUE);
这是结果:
这篇关于在MPAndroidChart的某些情况PieChart中管理文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!