MPAndroidChart icon indicating copy to clipboard operation
MPAndroidChart copied to clipboard

Pie Chart label text outside slice overlaps with value line.

Open anshchauhan opened this issue 10 years ago • 9 comments

Hi,

While working with a pie charts I found out that if you are drawing labels(only) outside the slices the text of labels overlaps with the value line. I just commented this dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); in https://github.com/PhilJay/MPAndroidChart/blob/master/MPChartExample/src/com/xxmassdeveloper/mpchartexample/PiePolylineChartActivity.java:

screenshot_20160805-040515

Please let me know if there is a setting for setting label text offset. As a workaround I've set offset in drawValues to labelRadius/2 instead of 5.f but I guess that will might mess other things up.

anshchauhan avatar Aug 04 '16 22:08 anshchauhan

This still appears to be broke on 3.0.0-beta1

Also once moving to outside slice value text color only shows white.

screen shot 2016-10-17 at 11 24 46 am

data.setValueTextColor(Color.BLACK); dataSet.setValueLinePart1OffsetPercentage(90.f); dataSet.setValueLinePart1Length(1f); dataSet.setValueLinePart2Length(.2f); dataSet.setValueTextColor(Color.BLACK); dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);

dylan33p avatar Oct 17 '16 15:10 dylan33p

@anshchauhan How did you draw the text outside the slices. Is it using the line dataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE) ?? I didn't see setYValuePosition() method in mpandroidchart library.Is this because am using an older library?? Currently i am using mpandroidchartlibrary-2-2-4.jar for building piechart.

MyGitUserAcc avatar Dec 12 '16 08:12 MyGitUserAcc

How to show the data with a line outside piechart using MPchart com.github.PhilJay:MPAndroidChart:v2.0.9 , can anyone help me with this sample

I need the values to be outside the pie chart with a line .

gokulrajkc avatar Feb 01 '17 10:02 gokulrajkc

@gokulrajkc Use the below code ` pieEntryList = new ArrayList(); for (int i = 0; i < yList.size(); i++){ PieEntry newPEntry = new PieEntry(yList.get(i).getAmount(), yList.get(i).getName() + " " + Math.round(yList.get(i).getAmount())); pieEntryList.add(newPEntry); } // create pieDataSet dataSet = new PieDataSet(pieEntryList, chart); // dataSet.setSliceSpace(3f); dataSet.setSelectionShift(5f); dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); dataSet.setValueLinePart1OffsetPercentage(80.f); dataSet.setValueLinePart1Length(0.2f); dataSet.setValueLinePart2Length(0.4f);

        PieData data = new PieData(dataSet);
        data.setDrawValues(false);
        pchart.setData(data);
        pchart.setEntryLabelColor(Color.BLACK);
        pchart.setEntryLabelTextSize(7f);
        pchart.setEntryLabelTypeface(tf);

        // undo all highlights
        pchart.highlightValues(null);
        // refresh/update pie chart
        pchartRepOne.invalidate();`

Where dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); dataSet.setValueLinePart1OffsetPercentage(80.f); dataSet.setValueLinePart1Length(0.2f); dataSet.setValueLinePart2Length(0.4f); solves your problem.You can change the line size by using the above codes. This code suits for the latest mpandroidchart library. com.github.PhilJay:MPAndroidChart:v3.0.1 I think there is no provision for the same in com.github.PhilJay:MPAndroidChart:v2.0.9.Use the latest library, its far better than the older libraries.

MyGitUserAcc avatar Feb 02 '17 07:02 MyGitUserAcc

How to remove the bright whiter translucent circle in the pie chart?

shubhamtunwal97 avatar Feb 21 '18 18:02 shubhamtunwal97

I am just trying to set text near line but unable to add. Please tell any one how to set label near line in Pie Chart.

  mChart.setOnChartValueSelectedListener(this);
    //   mChart.setTouchEnabled(false);
    mChart.setUsePercentValues(true);
    mChart.getDescription().setEnabled(false);
    mChart.setExtraOffsets(5, 10, 5, 5);
    mChart.setDragDecelerationFrictionCoef(0.95f);
    mChart.setDrawHoleEnabled(true);
    mChart.setHoleColor(Color.WHITE);
    mChart.setTransparentCircleColor(Color.WHITE);
    mChart.setTransparentCircleAlpha(110);
    mChart.setHoleRadius(80f);
    mChart.setTransparentCircleRadius(61f);
    mChart.setRotationAngle(0);
    // enable rotation of the chart by touch
    mChart.setRotationEnabled(true);
    mChart.setHighlightPerTapEnabled(true);

float mult = range; ArrayList entries = new ArrayList(); for (int i = 0; i < count; i++) { entries.add(new PieEntry(40f, globalViewDetailsDataArrayList.get(i).getItemDisplayName(), globalViewDetailsDataArrayList.get(i))); // divide from the num. of count } PieDataSet dataSet = new PieDataSet(entries, ""); dataSet.setDrawIcons(false); dataSet.setIconsOffset(new MPPointF(0, 40)); dataSet.setSelectionShift(5f); dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); dataSet.setValueLinePart1OffsetPercentage(80.f); dataSet.setValueLinePart1Length(0.4f); dataSet.setValueLinePart2Length(0.5f);

    ArrayList<Integer> colors = new ArrayList<Integer>();
    for (int i = 0; i < globalViewDetailsDataArrayList.size(); i++) {
        colors.add(Color.parseColor(globalViewDetailsDataArrayList.get(i).getColor()));//red
    }
    dataSet.setColors(colors);

    PieData data = new PieData(dataSet);
    data.setValueFormatter(new PercentFormatter());
    data.setValueTextSize(11f);
    data.setValueTextColor(Color.BLACK);
    dataSet.setDrawValues(false);
    mChart.setData(data);
    mChart.setEntryLabelColor(Color.BLACK);
    mChart.setEntryLabelTextSize(7f);
         mChart.highlightValues(null);
        mChart.invalidate();

mChart.spin(20000, 0, 360, Easing.EasingOption.EaseInOutBounce); // mChart.animateY(14000, Easing.EasingOption.EaseInOutQuad); Legend l = mChart.getLegend(); l.setEnabled(true); l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); l.setOrientation(Legend.LegendOrientation.VERTICAL); l.setDrawInside(true); l.setXEntrySpace(7f); l.setYEntrySpace(0f); l.setYOffset(0f); mChart.setEntryLabelColor(Color.WHITE); mChart.setEntryLabelTextSize(12f);

Rishabhsaxena2011 avatar Sep 28 '18 07:09 Rishabhsaxena2011

This still appears to be broke on 3.0.0-beta1

Also once moving to outside slice value text color only shows white.

screen shot 2016-10-17 at 11 24 46 am

data.setValueTextColor(Color.BLACK); dataSet.setValueLinePart1OffsetPercentage(90.f); dataSet.setValueLinePart1Length(1f); dataSet.setValueLinePart2Length(.2f); dataSet.setValueTextColor(Color.BLACK); dataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE);

I faced the same issue and this line of code fixed it for me

pieChart.setEntryLabelColor(Color.YELLOW);

neocodegh avatar Jun 01 '20 16:06 neocodegh

How to remove the line when we position of label in outside slice ?

anmol-max avatar Oct 22 '21 06:10 anmol-max

use match parent in pie chart that's all

nitish-gloify avatar Jul 08 '22 11:07 nitish-gloify