MPAndroidChart - Legend labels are being cut off

后端 未结 9 1355
自闭症患者
自闭症患者 2020-12-15 17:18

I am using MPAndroidChart library. Anybody has this problem? When I put the labels in BOTTOM position, these are cut.

Thank you

9条回答
  •  一生所求
    2020-12-15 17:59

    You have to implement customize legends with their legends colours and lables by following steps Step 1

    Legend legend = mChart.getLegend();
    

    Step 2

    int colorcodes[] = legend.Colors();
    

    Steps 3

    for (int i = 0; i <  legend.Colors().length-1; i++) {
     .....
     .....
     }
    

    Steps 4

    Then you have to take one layout horizontal or vertical. You have to get legends color codes and legends lable and according to legends length create layout and label. Code sample is given below

            LinearLayout.LayoutParams parms_left_layout = new LinearLayout.LayoutParams(
                    LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
            parms_left_layout.weight = 1F;
            LinearLayout left_layout = new LinearLayout(context);
            left_layout.setOrientation(LinearLayout.HORIZONTAL);
            left_layout.setGravity(Gravity.CENTER);
            left_layout.setLayoutParams(parms_left_layout);
    
            LinearLayout.LayoutParams parms_legen_layout = new LinearLayout.LayoutParams(
                    20, 20);
            parms_legen_layout.setMargins(0, 0, 20, 0);
            LinearLayout legend_layout = new LinearLayout(context);
            legend_layout.setLayoutParams(parms_legen_layout);
            legend_layout.setOrientation(LinearLayout.HORIZONTAL);
            legend_layout.setBackgroundColor(colorcodes[i]);
            left_layout.addView(legend_layout);
    
            TextView txt_unit = new TextView(context);
            txt_unit.setText(legend.getLabel(i));
    

    Hope this will help you

提交回复
热议问题