我正在使用MPcharts创建饼图。该图表是根据我从Web API获取的数据创建的。图表看起来不错,但图例在底部被切断。该图表有两个条目,但仅显示一个。它必须是图表底部的一个垂直列。只是尝试一下,我将其放在顶部,但确实看到了两个条目。
我已经尝试过自动换行,在图例和图表中添加了偏移量,并只是调整了图表的大小。这是我的代码:
val entries : MutableList<PieEntry> = ArrayList()
val mChart = com.github.mikephil.charting.charts.PieChart(context)
if(chart.data != null) {
for (i in chart.data!!.dataPoints) {
if (i.y != null)
entries.add(PieEntry(i.y!!, i.label))
}
mChart.centerText = chart.data!!.total.toString()
mChart.setCenterTextSize(52f)
val set = PieDataSet(entries, "")
set.resetColors()
set.label = null
set.colors = getColorSchemeArray(mTheme, context)
val data = PieData(set)
data.setDrawValues(false)
mChart.data = data
holder.mCardLayout.gravity = Gravity.CENTER_HORIZONTAL
set.sliceSpace = 3f
mChart.setDrawEntryLabels(false)
mChart.description.text = ""
mChart.setTransparentCircleAlpha(0)
holder.mCardLayout.addView(mChart)
/*val mChartSide = if(holder.mCardLayout.width *.65 < holder.mCardLayout.height *.375)
(holder.mCardLayout.width *.65).toInt()
else
(holder.mCardLayout.height *.375).toInt()*/
val mChartSide = (holder.mCardLayout.width *.65).toInt()
mChart.layoutParams.height = mChartSide
mChart.layoutParams.width = mChartSide
val mLegend = mChart.legend
mLegend.form = Legend.LegendForm.CIRCLE
mLegend.textSize = 20f
mLegend.orientation = Legend.LegendOrientation.VERTICAL
mLegend.isWordWrapEnabled = true
mLegend.maxSizePercent = 1f
mLegend.xEntrySpace = 15f
mLegend.yOffset = 5f
mLegend.horizontalAlignment = Legend.LegendHorizontalAlignment.CENTER
mLegend.verticalAlignment = Legend.LegendVerticalAlignment.BOTTOM
mChart.extraBottomOffset = 10f