饼图值重叠并被裁剪MPAndroidChart

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

我正在使用MPAndroidChart库在我的应用程序中绘制饼图,但是如果某个值比其他值大一些,则所有其他值及其标签将重叠。我也遇到一些标签问题,如果标签的长度较长,其中的一些文本将被剪切。我已经看到了一些应用程序(下面给出了示例),如果这些应用程序提供的数据场景与我所拥有的相同,它们会动态地调整饼图的大小。

<com.github.mikephil.charting.charts.PieChart
android:id="@+id/main_dashboard_pie_chart"
android:layout_width="match_parent"
android:layout_height="400dp">

我的Java代码

pieDataSet.setColors(colors);
pieDataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
pieDataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
pieDataSet.setValueTextColor(Color.BLACK);
pieDataSet.setSliceSpace(2);
pieDataSet.setValueLinePart1OffsetPercentage(10); //starting of the line from center of the chart offset
pieDataSet.setValueLinePart1Length(0.6f);
pieDataSet.setValueLinePart2Length(0.5f);

PieData pieData = new PieData(pieDataSet);
pieData.setValueTextSize(13);
pieData.setValueFormatter(new PercentFormatter());

pieChart.setUsePercentValues(true);
pieChart.setData(pieData);
pieChart.setTransparentCircleRadius(45);
pieChart.setHoleRadius(40);
pieChart.setUsePercentValues(true);
pieChart.setCenterText("Expenses");
pieChart.setEntryLabelTextSize(10);
pieChart.animateY(1000, Easing.EasingOption.EaseInOutCubic);
pieChart.getDescription().setEnabled(false);
pieChart.setEntryLabelColor(Color.BLACK);
pieChart.setEntryLabelTextSize(13);
pieChart.setExtraBottomOffset(50f);
pieChart.setExtraTopOffset(50f);
pieChart.setExtraLeftOffset(50f);
pieChart.setExtraRightOffset(50f);
Legend l = pieChart.getLegend();
l.setDrawInside(false);
l.setEnabled(false);

this is what I want to achieve Currenlty I am having this problem

android pie-chart mpandroidchart
1个回答
0
投票

使用此库来解决问题https://github.com/huzipiaopiao/MPAndroidChartFix

以XML定义图表,如下所示。

  <com.teaanddogdog.mpandroidchartutil.PieChartFixCover
            android:id="@+id/pie_chart"
            android:layout_width="450dp"
            android:layout_height="450dp"
            app:mp_chart_out_value_place_mode="AVG"
            app:mp_chart_auto_adapt_text_size="true"
            />

并且您可以像访问MPANdroidChart一样以Java代码对其进行访问,并且可以修改所有属性。如果对您有帮助,请不要忘了提问和回答。所有重叠的问题都将自动为您处理。谢谢。

© www.soinside.com 2019 - 2024. All rights reserved.