gpt4 book ai didi

android - 使用 MPAndroidChart 的饼图对齐问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:24:23 25 4
gpt4 key购买 nike

在我的应用程序中使用饼图。使用以下库
api 'com.github.PhilJay:MPAndroidChart:v3.0.3'

但是我遇到了对齐问题。附上截图,请看一下:

graph_1 graph_2

代码:

public static void chartDetails(PieChart mChart, Typeface tf) {
mChart.animateXY(1400, 1400);
mChart.getDescription().setEnabled(false);
mChart.setCenterTextTypeface(tf);
mChart.setCenterText("");
mChart.setCenterTextSize(10f);
mChart.setCenterTextTypeface(tf);
// radius of the center hole in percent of maximum radius
mChart.setHoleRadius(45f);
mChart.setTransparentCircleRadius(50f);
Legend l = mChart.getLegend();
l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
l.setOrientation(Legend.LegendOrientation.VERTICAL);
l.setDrawInside(false);
mChart.setTouchEnabled(true);
}

最佳答案

您可以使用外部值,以便为小块数据保持清晰的数据集名称。

例如,您可以实现类似的目标:

Outside values

这是代码。此代码应该在覆盖 PieChart 时使用。如果您不覆盖它,您应该调整此代码以直接与您的 PieChart 一起使用,例如 mChart.setData(); 而不是 setData();

PieDataSet dataSet = new PieDataSet(entries, null);
dataSet.setSliceSpace(3f);
dataSet.setIconsOffset(new MPPointF(0, 40));
dataSet.setSelectionShift(5f);

// Outside values
dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
dataSet.setValueLinePart1OffsetPercentage(100f); /** When valuePosition is OutsideSlice, indicates offset as percentage out of the slice size */
dataSet.setValueLinePart1Length(0.6f); /** When valuePosition is OutsideSlice, indicates length of first half of the line */
dataSet.setValueLinePart2Length(0.6f); /** When valuePosition is OutsideSlice, indicates length of second half of the line */
setExtraOffsets(0.f, 5.f, 0.f, 5.f); // Ofsets of the view chart to prevent outside values being cropped /** Sets extra offsets (around the chart view) to be appended to the auto-calculated offsets.*/

PieData data = new PieData(dataSet);
data.setValueTextSize(10f);
data.setValueTextColor(Color.BLACK);
setData(data);

关于android - 使用 MPAndroidChart 的饼图对齐问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50907258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com