gpt4 book ai didi

android - MPAndroid 图表饼图标签被切断

转载 作者:太空宇宙 更新时间:2023-11-03 11:03:00 27 4
gpt4 key购买 nike

我一直在想办法修改 MPAndroid 图表库中的饼图,使其不切断标签。我尝试使用 chart.setExtraOffsets()chart.setPadding() 修改视口(viewport)。以及尝试使用视口(viewport)处理程序来让这个饼图适合 View 。

enter image description here

 public void setupInventoryChart(PieChart chart) {
chart.setUsePercentValues(false);
chart.setDescription("");

chart.setDragDecelerationFrictionCoef(0.95f);

mtf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Regular.ttf");
chart.setCenterTextTypeface(mtf);

chart.setDrawHoleEnabled(true);
//chart.setHoleColorTransparent(false);

chart.setTransparentCircleColor(Color.WHITE);
// chart.setTransparentCircleAlpha(110);

chart.setHoleRadius(58f);
chart.setTransparentCircleRadius(61f);

chart.setDrawCenterText(true);

chart.setRotationAngle(0);
chart.setRotationEnabled(true); // enable rotation of the chart by touch

// mChart.setUnit(" €");
// mChart.setDrawUnitsInChart(true);

// add a selection listener
chart.setOnChartValueSelectedListener(this);

chart.setExtraOffsets(0.5f, 0.5f, 0.5f, 0.8f);

//chart.animateY(1500, Easing.EasingOption.EaseInOutQuad);
// mChart.spin(2000, 0, 360);

Legend l = chart.getLegend();
l.setEnabled(false);
// l.setPosition(Legend.LegendPosition.RIGHT_OF_CHART);
// l.setXEntrySpace(7f);
// l.setYEntrySpace(5f);
// l.setYOffset(0f);
// l.setTextColor(Color.BLACK);

setInventoryData(chart);

}

private void setInventoryData(PieChart chart) {

//This defines the order of how the data is shown.
InventoryType[] inventoryStatusOrder = new InventoryType[] {
InventoryType.ACTIVE_POSTINGS, InventoryType.SOLD, InventoryType.NEEDS_ATTENTION, InventoryType.URGENT};

int count = inventoryStatusOrder.length;

String[] parties = new String[count];
for (int i = 0 ; i < parties.length ; i++) {
parties[i] = inventoryStatusOrder[i].getValue();
}

ArrayList<Entry> yVals1 = new ArrayList<Entry>(); //yVals1 is value of each label.
ArrayList<String> xVals = new ArrayList<String>(); //xVals is the labels

// IMPORTANT: In a PieChart, num of values (Entry) should have the same
// xIndex (even if from different DataSets), since no values can be
// drawn above each other.
int total = 0;
int[] colorPositions = new int[count];
for (int i = 0 ; i < count ; i++) {
int item = mInventoryStatus.getCountByType(inventoryStatusOrder[i]);
if (item != 0) {
xVals.add(parties[i % parties.length]);
yVals1.add(new Entry(item, i));
total += item;
colorPositions[i] = 1;
}
}

PieDataSet dataSet = new PieDataSet(yVals1, "");
dataSet.setSliceSpace(3f);
dataSet.setSelectionShift(5f);

int[] dashboardColors = getResources().getIntArray(R.array.dashboard_color); //there are 5 orange colors.
ArrayList<Integer> colors = new ArrayList();
for (int i = 0 ; i < count ; i++) {
if(colorPositions[i] != 0)
colors.add(dashboardColors[i]); //In this case, it will use the first color again.
}

int[] temp = new int[colors.size()];
for(int i = 0; i < colors.size(); i++) {
temp[i] = colors.get(i);
}

dataSet.setColors(temp);

dataSet.setValueLinePart1OffsetPercentage(80.f);
dataSet.setValueLinePart1Length(0.4f);
dataSet.setValueLinePart2Length(0.4f);
dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);
//dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);


PieData data = new PieData(xVals, dataSet);
data.setValueFormatter(new IntValueFormatter(false, false));
data.setValueTextSize(15f);
data.setValueTextColor(Color.BLACK);
data.setValueTypeface(mtf);

chart.setData(data);

// undo all highlights
chart.highlightValues(null);

mBoldTf = Typeface.createFromAsset(getActivity().getAssets(),"OpenSans-Bold.ttf");
chart.setCenterText(generateCenterSpannableText(mInventoryStatus.getVins() + "\nUnique\nVINs"));
chart.setCenterTextColor(Color.BLACK);
chart.setCenterTextSize(16f);
chart.setCenterTextTypeface(mBoldTf);

chart.invalidate();
chart.animateXY(900, 900);
}

最佳答案

我遇到了同样的问题。我使用下面的代码行解决了这个问题。

piecPieChart.setExtraBottomOffset(20f); 
piecPieChart.setExtraLeftOffset(20f);
piecPieChart.setExtraRightOffset(20f);

希望对大家有帮助。

关于android - MPAndroid 图表饼图标签被切断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38134170/

27 4 0
文章推荐: mysql - SQL查询加速
文章推荐: python - 使用 WSGI 提供 html 时出错
文章推荐: c# - 选择子句为空
文章推荐: PHP递归导航
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com