MpAndroidChart Piechart legends cutting issue at the bottom center

前端 未结 4 1908
名媛妹妹
名媛妹妹 2021-01-20 13:21

I have attached the screenshot of my usage chart. In red box display the legends and they are cutting in pie chart. Below is my code:

相关标签:
4条回答
  • 2021-01-20 13:29

    i have solved this issue by adding the titles in normal list view

     ListView list = (ListView) findViewById(R.id.list_chart);
     list.setAdapter(new ChartTextLegendAdapter(this, values, colors));
    

    and hide the titles within Legend

    this is my layout XML

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clickable="true"
        android:background="@color/background_color">
    
        <com.github.mikephil.charting.charts.PieChart
            android:id="@+id/chart1"
            android:layout_width="match_parent"
            android:layout_height="300dp" />
    
        <ListView
            android:id="@+id/list_chart"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/chart1" />
    
    </RelativeLayout>
    

    and dont forgot to pass the values and ArrayList of colors manully

     for (int c : ColorTemplate.PASTEL_COLORS)
                colors.add(c);
            for (int c : ColorTemplate.LIBERTY_COLORS)
                colors.add(c);
            for (int c : ColorTemplate.COLORFUL_COLORS)
                colors.add(c);
            for (int c : ColorTemplate.JOYFUL_COLORS)
                colors.add(c);
            for (int c : ColorTemplate.VORDIPLOM_COLORS)
                colors.add(c);
    
            colors.add(ColorTemplate.getHoloBlue());
    
    
            values.DetailAmount = getIntent().getStringArrayListExtra("amount");
            values.DetailId = getIntent().getIntegerArrayListExtra("id");
            values.DetailName = getIntent().getStringArrayListExtra("names");
            values.DetailEnglishName = getIntent().getStringArrayListExtra("enames");
            month_name = getIntent().getStringExtra("month_name");
    

    hope this will solve your issue too.

    0 讨论(0)
  • 2021-01-20 13:37

    have you tried customizing with xml attribute android:translationY="-10dp" ?

    OR view.setExtraOffsets(...);

    you can manage dp accordingly.

    UPDATE

    l.setYOffset(10f);

    0 讨论(0)
  • 2021-01-20 13:48

    Most probably there is an issue with the chart offsets. Try this, should solve your problem

    pieChart.setExtraOffsets(0, 0, 0, 25);
    

    This function sets extra offsets (around the chart view) to be appended to the auto-calculated offsets. The arguments are (left, top, right, bottom). Play around with the values to see which offsets suits your needs.

    0 讨论(0)
  • 2021-01-20 13:48

    Try to set padding or margin to PieChart , Or maybe align legend in horizontal direction.

    0 讨论(0)
提交回复
热议问题