0

I want the legend to be represented vertically on the right of the pie chart. I'm currently using this code:

legend.setVerticalAlignment(Legend.LegendVerticalAlignment.CENTER);
legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT);
legend.setOrientation(Legend.LegendOrientation.VERTICAL);
legend.setDrawInside(false);

My layout code:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@id/rl_supermarket_bar_chart"
    android:layout_marginBottom="10dp"
    android:layout_marginEnd="10dp"
    android:layout_marginStart="10dp"
    android:background="@drawable/layout_bg">

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

</RelativeLayout>

But it makes the chart very small. How can I solve this issue?

enter image description here

Paktalin
  • 236
  • 4
  • 16
  • Show your layout file – Lucas Cabrales May 08 '18 at 21:18
  • @LucasDeMoraisCabrales Hey. The legend cannot be specified in the layout file, it goes in the same view as the pie chart does. But I added it in the question – Paktalin May 08 '18 at 21:21
  • I meant to see the graph view and its parents – Lucas Cabrales May 08 '18 at 21:22
  • Just for testing sake, set a fixed height for your `PieChart`, like `200dp` and see if it's okay – Lucas Cabrales May 08 '18 at 21:24
  • @LucasDeMoraisCabrales I tried to, the output remains the same – Paktalin May 08 '18 at 21:30
  • It seems to me that the issue is in the line "legend.setVerticalAlignment(Legend.LegendVerticalAlignment.CENTER);", since if I don't put it, the size remains normal. But the position is wrong – Paktalin May 08 '18 at 21:32
  • I just tried it here and I see no issued with it, are you sure that your layout is set to occupy the full width of the "card"? Also check if you have the latest version: `implementation 'com.github.PhilJay:MPAndroidChart:v3.0.2'` – Lucas Cabrales May 08 '18 at 21:41
  • Yes, I'm not touching the layout file at all, the size of the chart varies depending on the settings. If I put smth like this the size is ok, but the legend is drawn inside: legend.setVerticalAlignment(Legend.LegendVerticalAlignment.TOP); legend.setHorizontalAlignment(Legend.LegendHorizontalAlignment.RIGHT); legend.setOrientation(Legend.LegendOrientation.VERTICAL); legend.setDrawInside(false); – Paktalin May 08 '18 at 21:47
  • The version is even v3.0.3 :) – Paktalin May 08 '18 at 21:48

0 Answers0