3 android text kotlin pie-chart mpandroidchart
我尝试在 MPAndroidChart 的 PieChart 中管理文本。但是当我的文本是 True = 2, False = 3 , Not = 95 等困难情况时,在这种情况下,我的饼图布局非常糟糕。这是我的代码:-
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
}
Run Code Online (Sandbox Code Playgroud)
结果是这样的:-
在我的饼图中,这里的数据格式不正确。帮我解决这个问题
Mis*_*pov 10
你需要这条线,所以你的标签将在图表之外:
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
Run Code Online (Sandbox Code Playgroud)
和价值将在外面。您还可以像这样控制位置、线长和颜色:
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);
Run Code Online (Sandbox Code Playgroud)
这是结果:
| 归档时间: |
|
| 查看次数: |
2643 次 |
| 最近记录: |