Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPAndroidChart - Legend labels are being cut off

I am using MPAndroidChart library. Anybody has this problem? When I put the labels in BOTTOM position, these are cut.

Thank you

enter image description here

like image 704
rafaelasguerra Avatar asked Jan 08 '15 18:01

rafaelasguerra


People also ask

How to display legend labels in listview in Android chart?

When you have a look at the Legend class you will notice that it has member variables for colors and labels. You can retrieve those arrays ( getColors (), getLegendLabels ()) and use them to be displayed in the ListView. Show activity on this post. Please look for the given answer MPAndroidChart - Legend labels are being cut off.

How do I create a legend for my chart?

By default, all chart types support legends and will automatically generate and draw a legend after setting data for the chart. The Legend usually consists of multiple entries each represented by a label an a form/shape.

How many entries does the legend automatically generate?

The number of entries the automatically generated legend contains depends on the number of different colors (across all DataSet objects) as well as on the DataSet labels. The labels of the Legend depend on the labels set for the used DataSet objects in the chart.

How do I change the size of the labels on charts?

Option 1 - Increase height of chart control until all the labels fit in (make sure label texts are not too long else the height wont be able to fit in your screen size) Option 2 - try changing the XLabelAngle property to see if a different angle works better Option 3 - Change the size property of the chart to see if your labels fit it Regards,


2 Answers

This seems to be a new feature since June (2015):

chart.getLegend().setWordWrapEnabled(true); 

Javadoc:

/**  * Should the legend word wrap? / this is currently supported only for:  * BelowChartLeft, BelowChartRight, BelowChartCenter. / note that word  * wrapping a legend takes a toll on performance. / you may want to set  * maxSizePercent when word wrapping, to set the point where the text wraps.  * / default: false  *   * @param enabled  */ public void setWordWrapEnabled(boolean enabled) {     mWordWrapEnabled = enabled; } 
like image 74
Aksel Willgert Avatar answered Oct 04 '22 04:10

Aksel Willgert


They are cut because your text is too long and the library does not support "wrapping" of the labels to a new line.

You will either have to shorten your legend labels or implement the desired functionality yourself.

UPDATE:

Word wrapping for the Legend is now supported.

chart.getLegend().setWordWrapEnabled(true); 
like image 35
Philipp Jahoda Avatar answered Oct 04 '22 06:10

Philipp Jahoda