I wanted to use MPAndroidChartLibrary in my application, but I am experiencing problems which I can't solve on my own. I would like to put the chart into the CardView which is stored inside ListView. CardView's xml looks like this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="16dp"
card_view:cardUseCompatPadding="true"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginBottom="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textDateStartTitle"
android:paddingLeft="5dp"
android:textSize="26sp"
android:textColor="@color/accent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"/>
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/pie_chart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
When opening the fragment containing these CardViews I get an error:
java.lang.IllegalArgumentException: width and height must be > 0 at android.graphics.Bitmap.createBitmap(Bitmap.java:808) at android.graphics.Bitmap.createBitmap(Bitmap.java:787) at android.graphics.Bitmap.createBitmap(Bitmap.java:754) at com.github.mikephil.charting.charts.Chart.onSizeChanged(Chart.java:2197)
When I set android:layout_width
and android:layout_height
to some fixed values (eg. 200dp) inside com.github.mikephil.charting.charts.PieChart
the chart looks ok and there is no error. How to get rid of this error while having width and height depending on the parent/content?