2015-01-08 23 views

Trả lời

4

Chúng được cắt bởi vì văn bản của bạn quá dàithư viện không hỗ trợ "gói" của nhãn cho một dòng mới.

Bạn sẽ phải rút ngắn nhãn chú thích hoặc tự mình thực hiện chức năng mong muốn.

+0

Cảm ơn bạn đã trả lời. – rguerra

6

Bạn phải thực hiện huyền thoại tùy chỉnh với truyền thuyết màu sắc của họ và lables bởi bước sau Bước 1

Truyền thuyết huyền thoại = mChart.getLegend();

Bước 2

int colorcodes [] = legend.Colors();

bước 3

for (int i = 0;. I < legend.Colors() chiều dài-1; i ++) { ..... ..... }

Các bước 4

Sau đó, bạn phải thực hiện một bố cục ngang hoặc dọc. Bạn phải có được mã màu huyền thoại và truyền thuyết lable và theo truyền thuyết chiều dài tạo bố trí và nhãn. mẫu mã được đưa ra dưới đây

 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)); 

Hy vọng điều này sẽ giúp bạn

4

Ở đây tôi sẽ chỉ cho bạn một cách dễ dàng bằng cách "truyền thống Android Way", nó khá đơn giản, mã của tôi là dưới đây:

<LinearLayout 
    android:id="@+id/i_am_chart_view_container" 
    ... 
    android:paddingRight="20dp" 
    android:clipChildren="false" 
    android:clipToPadding="false" 
    .../> 

Chỉ cần thêm một số padding vào bố cục vùng chứa hoặc một số margin vào chế độ xem biểu đồ và cuối cùng đặt clipChildren & clipToPadding thành sai.

Kết quả dưới đây:

khu vực màu xanh là đệm hoặc lề khu vực.

enter image description here

32

này có vẻ là một mới feature kể từ tháng Sáu (2015):

chart.getLegend().setWordWrapEnabled(true); 

Javadoc:

/** 
* Should the legend word wrap?/this is currently supported only for: 
* BelowChartLeft, BelowChartRight, BelowChartCenter./note that word 
* wrapping a legend takes a toll on performance./you may want to set 
* maxSizePercent when word wrapping, to set the point where the text wraps. 
*/default: false 
* 
* @param enabled 
*/ 
public void setWordWrapEnabled(boolean enabled) { 
    mWordWrapEnabled = enabled; 
} 
+0

Cảm ơn rất nhiều ... Tôi đã giải quyết cho iOS 'chartView.legend.wordWrapEnabled = true;' – Hiren

+0

tôi đồng ý, đã làm việc tốt cho tôi! – Zhar

+0

tuyệt vời! bạn đã tiết kiệm thời gian của tôi –

2
Legend l = pieChart.getLegend(); 
l.setPosition(LegendPosition.BELOW_CHART_LEFT); 
l.setXEntrySpace(7f); 
l.setYEntrySpace(0f); 
l.setYOffset(0f); 
l.setDirection(LegendDirection.LEFT_TO_RIGHT); 
l.setWordWrapEnabled(true); 
1

Để tránh clipping của huyền thoại đánh giá cao sử dụng khối mã sau đây

Legend legend=lineChart.getLegend(); 
legend.setWordWrapEnabled(true); 

Doc (đối với huyền thoại):

/** 
    * Should the legend word wrap?/this is currently supported only for: 
    * BelowChartLeft, BelowChartRight, BelowChartCenter./note that word 
    * wrapping a legend takes a toll on performance./you may want to set 
    * maxSizePercent when word wrapping, to set the point where the text wraps. 
    */default: false 
    * 
    * @param enabled 
    */ 
    public void setWordWrapEnabled(boolean enabled) { 
     mWordWrapEnabled = enabled; 
    } 

Để tránh cắt nhãn trục x sử dụng

XAxis xAxis = lineChart.getXAxis(); 
xAxis.setAvoidFirstLastClipping(true); 

Doc (đối với nhãn trục x):

/** 
    * if set to true, the chart will avoid that the first and last label entry 
    * in the chart "clip" off the edge of the chart or the screen 
    * 
    * @param enabled 
    */ 
    public void setAvoidFirstLastClipping(boolean enabled) { 
     mAvoidFirstLastClipping = enabled; 
    } 
+0

Cảm ơn, công trình này, nhưng giá trị điểm dữ liệu đầu tiên và cuối cùng cũng bị cắt, bất kỳ giải pháp nào? – erical

+0

@erical Bạn có thể vui lòng cung cấp ảnh chụp màn hình cho sự cố của mình không? –

2

Set hỗ trợ nội dung quấn chỉ Legends postion khi vị trí huyền thoại được BelowChartLeft, BelowChartRight, BelowChartCenter

 Legend legend = pieChart.getLegend(); 
     legend.setPosition(Legend.LegendPosition.BELOW_CHART_LEFT); 
     legend.setWordWrapEnabled(true); 

Sau bộ tập dữ liệu này

pieChart.setData(pieData) 

nó sẽ làm việc tốt

0

Sau một chặng đường dài nghiên cứu, tôi đã tìm ra giải pháp. Đoạn mã dưới giải quyết nó.

chart.getLegend(). SetWordWrapEnabled (true);

Các vấn đề liên quan