You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Jetpack Compose中如何制作无标签重叠的完美饼图

如何编写如图所示的饼图代码?

饼图示例

我尝试过MPAndroidChart等多个库,但都无法解决标签重叠问题。

我目前使用MPAndroidChart的实现代码如下:

val ds = PieDataSet(entries, "")
ds.colors = Utils.colors.map { it.toArgb() }
ds.yValuePosition = PieDataSet.ValuePosition.OUTSIDE_SLICE
ds.xValuePosition = PieDataSet.ValuePosition.OUTSIDE_SLICE
ds.sliceSpace = 1.5f
ds.valueTextColor = Black33.toArgb()
ds.valueTextSize = 12f
ds.isUsingSliceColorAsValueLineColor = true
ds.valueLinePart1Length = 1f
ds.valueLinePart2Length = 1f
ds.valueLinePart1OffsetPercentage = 100f
ds.valueTypeface = opensans
ds.valueFormatter = object : ValueFormatter() {
    override fun getFormattedValue(value: Float): String {
        return "%.1f%%".format(value)
    }
}
chart.setEntryLabelTextSize(13f)
chart.setEntryLabelTypeface(nunito)
chart.minAngleForSlices = 25f
chart.isRotationEnabled = true
val d = PieData(ds)
chart.data = d
chart.invalidate()

我尝试通过设置minAngleForSlices来缓解问题,但这并非理想解决方案。


内容的提问来源于stack exchange,提问作者Kartik Sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 05:42:02