Skip to content Skip to sidebar Skip to footer

Width And Height Must Be > 0 Error When Using Mpandroidchart Library

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 stor

Solution 1:

Right now, your chart height does not depend on the height of its parent LinearLayout:

<com.github.mikephil.charting.charts.PieChart
            android:id="@+id/pie_chart"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />

Try this instead:

<com.github.mikephil.charting.charts.PieChart
            android:id="@+id/pie_chart"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            />

The second set of attributes will allow your PieChart to fill all the vertical height available inside the container LinearLayout (after accounting for the height of the TextView above it).

Solution 2:

The only way I found was to attach the saving of file to gallery in onclick of a button. It works perfectly after that. I guess Once the view is fully drawn, the system have correct height and width.

Post a Comment for "Width And Height Must Be > 0 Error When Using Mpandroidchart Library"