MpAndroidChart Piechart图例底部中心切割问题
我已附上我的使用情况表的屏幕截图。在红色框中显示图例,它们在饼图中剪切。 下面是我的代码:MpAndroidChart Piechart图例底部中心切割问题,android,mpandroidchart,Android,Mpandroidchart,我已附上我的使用情况表的屏幕截图。在红色框中显示图例,它们在饼图中剪切。 下面是我的代码: pieChart.setUsePercentValues(false); pieChart.getDescription().setEnabled(false); pieChart.setDragDecelerationFrictionCoef(0.95f); pieChart.setDrawHoleEnabled(true); pieChart.setHoleColor(Color.WHITE); pi
pieChart.setUsePercentValues(false);
pieChart.getDescription().setEnabled(false);
pieChart.setDragDecelerationFrictionCoef(0.95f);
pieChart.setDrawHoleEnabled(true);
pieChart.setHoleColor(Color.WHITE);
pieChart.setTransparentCircleColor(Color.WHITE);
pieChart.setTransparentCircleAlpha(110);
pieChart.setHoleRadius(55f);
pieChart.setTransparentCircleRadius(57f);
pieChart.setDrawCenterText(true);
pieChart.setRotationAngle(0);
// enable rotation of the chart by touch
pieChart.setRotationEnabled(true);
pieChart.setHighlightPerTapEnabled(true);
// add a selection listener
pieChart.setOnChartValueSelectedListener(this);
pieChart.animateY(1400, Easing.EasingOption.EaseInOutQuad);
Legend l = pieChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.BOTTOM);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.CENTER);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
l.setForm(Legend.LegendForm.CIRCLE);
l.setXEntrySpace(7f);
l.setYEntrySpace(0f);
l.setYOffset(0f);
l.setWordWrapEnabled(true);
l.setDrawInside(false);
l.getCalculatedLineSizes();
// entry label styling
pieChart.setEntryLabelColor(Color.WHITE);
pieChart.setEntryLabelTextSize(12f);
有人知道答案吗?请帮助我解决此问题。提前感谢。
更新:
下面是显示图表的xml文件
发行
-每当我填充图形时,图形图例都会从底部自动裁剪。若我把相同的图例放在中间,那个么它工作正常,但问题只发生在底部
很可能是图表偏移量有问题。试试这个,应该能解决你的问题
pieChart.setExtraOffsets(0, 0, 0, 25);
此函数用于设置附加到图表的额外偏移量(围绕图表视图)
自动计算的偏移量。参数是(左、上、右、下)。
使用这些值查看哪些偏移量适合您的需要。尝试将填充或边距设置为PieChart,或者将图例水平对齐。我通过在正常列表视图中添加标题解决了此问题
ListView list = (ListView) findViewById(R.id.list_chart);
list.setAdapter(new ChartTextLegendAdapter(this, values, colors));
并将标题隐藏在图例中
这是我的布局XML
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@color/background_color">
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="300dp" />
<ListView
android:id="@+id/list_chart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/chart1" />
</RelativeLayout>
希望这也能解决您的问题。您是否尝试过使用xml属性
android:translationY=“-10dp”
进行自定义
或者view.setExtraOffsets(…)代码>
您可以相应地管理dp
更新
l.setYOffset(10f)代码>通过使用此代码,我的饼图会向上或向下移动。但我的图例仍在其位置。他们不动了。谢谢你的回答。谢谢你的回答。您好,值中应该包含什么以及如何获取这些值?你能给我发更多的代码吗?我已经在bundle中传递了这些值,这与你在图表中获取它们的方式完全相同,请检查上的更新post@GrishmaUkani发送电子邮件
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@color/background_color">
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/chart1"
android:layout_width="match_parent"
android:layout_height="300dp" />
<ListView
android:id="@+id/list_chart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/chart1" />
</RelativeLayout>
for (int c : ColorTemplate.PASTEL_COLORS)
colors.add(c);
for (int c : ColorTemplate.LIBERTY_COLORS)
colors.add(c);
for (int c : ColorTemplate.COLORFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.JOYFUL_COLORS)
colors.add(c);
for (int c : ColorTemplate.VORDIPLOM_COLORS)
colors.add(c);
colors.add(ColorTemplate.getHoloBlue());
values.DetailAmount = getIntent().getStringArrayListExtra("amount");
values.DetailId = getIntent().getIntegerArrayListExtra("id");
values.DetailName = getIntent().getStringArrayListExtra("names");
values.DetailEnglishName = getIntent().getStringArrayListExtra("enames");
month_name = getIntent().getStringExtra("month_name");