Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Piechart legend cutting issue. #3521

Open
GrishmaPromact opened this issue Oct 25, 2017 · 19 comments
Open

Piechart legend cutting issue. #3521

GrishmaPromact opened this issue Oct 25, 2017 · 19 comments

Comments

@GrishmaPromact
Copy link

GrishmaPromact commented Oct 25, 2017

I have attached the screenshot of my usage chart. In red box display the legends and they are cutting in pie chart.
Below is my code:

   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);

plz help me to solve this issue.
Thanks in advance.
device-2017-10-25-182740

@tutysathish
Copy link

Did you find any solution ?

@GrishmaPromact
Copy link
Author

GrishmaPromact commented Nov 27, 2017

@tutysathish No till now. :(

@rferbesa
Copy link

I have exactly the same problem, both with this library and with the iOS one, so I thought that it wasn't a bug but a miss configuration of the legend. I hope you find a solution.

@GrishmaPromact
Copy link
Author

@rferbesa I don't have any solution. If you have any solution then please suggest me. Thanks.

@EdwardQuixote
Copy link

@GrishmaPromact @tutysathish @rferbesa
Hi,
I found a solution.
Call the following method on your PieChart:
piecPieChart.setExtraBottomOffset(20f);

The method takes a float value, which represents the offset of the Chart's viewport from the Bottom.

@engr-erum
Copy link

Hi how u set your legend / labels vertically ? ? pls share

@GrishmaPromact
Copy link
Author

@engr-erum I didn't find any solution.

@Sonali-Sharma-1
Copy link

Thanks alot for this post @GrishmaPromact , I spent half day searching for legends to be vertically aligned. After i did these changes, i faced the same issue of cutting legend as this
screenshot 2019-01-27 at 4 19 52 pm

@aviraj
Copy link

aviraj commented Feb 6, 2019

Set the following,
l.setYOffset(10f);

Increase the value as per requirement

@Sonali-Sharma-1
Copy link

Thanks , it worked @aviraj

@GrishmaPromact
Copy link
Author

GrishmaPromact commented Feb 28, 2019

customizing with xml attribute android:translationY="-10dp"
OR view.setExtraOffsets(...);
you can manage dp accordingly.
l.setYOffset(10f);
yay... worked.

@jinshenglongsw
Copy link

thanks,i have this problem,too.

@androidDev-1
Copy link

androidDev-1 commented Mar 18, 2019

My legend isn't showing my 6th entry . I have written this code -
public void makePieChart() {
ArrayList yValues = new ArrayList<>();
// yValues.add(new PieEntry(goodCount, "good"));

    yValues.add(new PieEntry(avgCount, EXPLAIN_TREATMENT));
    yValues.add(new PieEntry(avgCount, WAITING_TIME));
    yValues.add(new PieEntry(avgCount, RECEPTIONIST_POLITE));
    yValues.add(new PieEntry(avgCount, DENTIST_FRIENDLY));
    yValues.add(new PieEntry(avgCount, CLINIC_CHAMBER_CLEAN_HYGENIC));
    yValues.add(new PieEntry(avgCount, BILLS_NOT_GIVEN));

// yValues.add(new PieEntry(poorCount, "Poor"));

    PieDataSet dataSet = new PieDataSet(yValues, "");

    dataSet.setSliceSpace(6f);
    dataSet.setSelectionShift(6f);
    dataSet.setColors(ColorTemplate.COLORFUL_COLORS);
    pieChart.animateY(500);
    Legend l = pieChart.getLegend();
    PieData data = new PieData(dataSet);
    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(10f);
    l.setYEntrySpace(0f);
    l.setYOffset(30f);
    l.setWordWrapEnabled(true);
    l.setDrawInside(false);
    l.getCalculatedLineSizes();
    data.setValueTextSize(40f);
    data.setValueTextColor(Color.BLACK);
    pieChart.setData(data);
    pieChart.highlightValues(null);
    pieChart.invalidate();

}

here is the screenshot of my UI -
Screenshot_20190318_120246

@GrishmaPromact
Copy link
Author

As, you are facing horizontal legends cutting. Set X offset for horizontally cutting legend.
Set the following,
l.setXOffset(10f);

Increase the value as per your requirement

@androidDev-1
Copy link

As, you are facing horizontal legends cutting. Set X offset for horizontally cutting legend.
Set the following,
l.setXOffset(10f);

Increase the value as per your requirement

@GrishmaPromact yeah that solved my cutting issue. But can u tell, why i am unable to see my 6th entry in legend?

@GrishmaPromact
Copy link
Author

@anant-dev pieChart.setEntryLabelTextSize(12f);
you can reduce the text size and also decrease the Yoffset to 30f to 20f and check. I am not sure.

@androidDev-1
Copy link

androidDev-1 commented Mar 18, 2019

@anant-dev pieChart.setEntryLabelTextSize(12f);
you can reduce the text size and also decrease the Yoffset to 30f to 20f and check. I am not sure.

@GrishmaPromact I tried setting textSize using above method , doesnt seem to work
@PhilJay Can you help ?

@jordanhbuiltbyhq
Copy link

This issue is easily reproducible in the example app. In PieChartActivity comment out these two lines to move the legend underneath the pie chart

l.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP);
l.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);

and you'll see Party D is clipped
Screenshot_1559408563

This issue also occurred in the iOS repo, which I reported and they fixed.

A workaround that worked for both libraries is to mess with the legend's yOffset and the pie chart's extraBottomOffset until it works for your legend. Would be good to fix this issue for android!

@jagadishnallappa
Copy link

jagadishnallappa commented May 17, 2021

Sorry, I might be late by years. But we should also make sure we do the following before we set data and invalidate it.

legend().setWordWrapEnabled(true);
// Should you wish to set the size
legend().setTextSize(getResources().getDimension(R.dimen.text_sub_heading));
// Should you wish to set the form size 
legend().setFormSize(CHART_LEGEND_FORM_SIZE);

// and then

chart.invalidate();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests