android - Pie chart does not have correct size inside a CardView -


i working on android application , using mpandroidchart lib in it. yet application developed using mpandroidchart version 2-0-8. , chart display fine shown below.

enter image description here

but today update lib version 2-1-1. haven't done changes code chart looks now.

enter image description here

here xml code chart.

 <com.github.mikephil.charting.charts.piechart                     android:id="@+id/chart"                     android:layout_width="match_parent"                     android:layout_height="wrap_content"                     android:layout_margintop="@dimen/top_bottommarginforchart"                     android:layout_marginleft="@dimen/top_bottommarginforchart"                     android:layout_marginright="30dp"                     android:layout_marginbottom="@dimen/top_bottommarginforchart" /> 

p.s. displaying chart on cardview if matters.

is there need update in code? have searched on website didn't find anything.

here java code chart.

mchart = (piechart) rootview.findviewbyid(r.id.chart); mchart.setholecolor(color.white); mchart.setholeradius(40f); mchart.setdescription(""); mchart.setdrawcentertext(true); mchart.setdrawholeenabled(true); mchart.setrotationangle(0); mchart.setdrawslicetext(false); mchart.setrotationenabled(true); mchart.setusepercentvalues(true); mchart.settouchenabled(false); mchart.animatexy(1500, 1500); 

legend

  legend l = mchart.getlegend();   l.setposition(legend.legendposition.right_of_chart_center);   l.setxentryspace(10f);   l.setyentryspace(10f); 

data setup chart

private void setdata(int count, float range)  {      arraylist<entry> yvals1 = new arraylist<entry>();     (int = 0; < count ; i++)     {         yvals1.add(new entry(total_amount[i],i));     }      arraylist<string> xvals = new arraylist<string>();     (int = 0; < count ; i++) {         xvals.add(array1[i]);                }      piedataset set1 = new piedataset(yvals1, "");     set1.setslicespace(3f);      arraylist<integer> colors = new arraylist<integer>();     (int = 0; < count ; i++) {         colors.add(color.parsecolor(colorname[i]));      }       colors.add(colortemplate.getholoblue());     set1.setcolors(colors);      piedata data = new piedata(xvals, set1);     data.setdrawvalues(false);     mchart.setdata(data);     mchart.highlightvalues(null);     mchart.invalidate();  } 

i not sure found out above issue arise when set piechart height wrap_content.

i resolved issue hard coding piechart height not recommend. if has other solution can post it.


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -