MPAndroid图表饼图标签被切断

MPAndroid图表饼图标签被切断,第1张

概述Hey Guys所以我一直试图弄清楚如何修改MP Android图表库中的饼图以不切断标签,我尝试用chart.setExtraOffsets()和chart.setPadding()修改视口.以及尝试使用视图端口处理程序来使此饼图适合视图. public void setupInventoryChart(PieChart chart) { chart.setUsePercentV hey Guys所以我一直试图弄清楚如何修改MP Android图表库中的饼图以不切断标签,我尝试用chart.setExtraOffsets()和chart.setpadding()修改视口.以及尝试使用视图端口处理程序来使此饼图适合视图.

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.8f);        //chart.animateY(1500,Easing.EasingOption.EaseInOutQuad);        // mChart.spin(2000,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);

希望它会帮助某人.

总结

以上是内存溢出为你收集整理的MPAndroid图表饼图标签被切断全部内容,希望文章能够帮你解决MPAndroid图表饼图标签被切断所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1123821.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存