2017-08-13 41 views
0

我正在使用MPAndroidCharts庫創建餅圖。一切都很順利,只是一個問題I M就面臨ValueTextColorXValueText餅圖中的字體顏色不變

Pie_chart

Pie_chart(zoomed in)

XValuesLabel在白色字體顏色到來,YValueLabel黑FONTCOLOR。 我想雙方的它黑色的,但不知何故setValueTextColor()不XValuesLabel

Log.d("PIECHART dataset", "addDataSet started"); 
ArrayList yEntrys = new ArrayList<>(); 
ArrayList xEntrys = new ArrayList<>(); 

for(int i = 0; i < yData.length; i++){ 
    if(yData[i]>0) { 

    switch(i){ 
     case 0: 
      yEntrys.add(new PieEntry(yData[i], "banana")); 
      break; 
     case 1: 
      yEntrys.add(new PieEntry(yData[i], "guava")); 
      break; 
     case 2: 
      yEntrys.add(new PieEntry(yData[i], "apple")); 
      break; 
     case 3: 
      yEntrys.add(new PieEntry(yData[i], "pineapple")); 
      break; 
     case 4: 
      yEntrys.add(new PieEntry(yData[i], "mango")); 
      break; 
     case 5: 
      yEntrys.add(new PieEntry(yData[i], "papaya")); 
      break; 
     case 6: 
      yEntrys.add(new PieEntry(yData[i], "dates")); 
      break; 
     default : ; 
    } 

    } 
} 
//create the data set 

pieDataSet = new PieDataSet(yEntrys, ""); 
pieDataSet.setSliceSpace(2f); 
pieDataSet.setValueTextSize(15f); 
pieDataSet.setValueTextColor(Color.RED);/* this line not working */ 
pieDataSet.setSelectionShift(10f); 
pieDataSet.setValueLinePart1OffsetPercentage(80.f); 
pieDataSet.setValueLinePart1Length(1f); 
pieDataSet.setValueLinePart2Length(0.9f); 
pieDataSet.setXValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); 
//pieDataSet.setYValuePosition(PieDataSet.ValuePosition.OUTSIDE_SLICE); 

//add colors to dataset 
ArrayList<Integer> colors = new ArrayList<>(); 
colors.add(Color.rgb(156,254,230)); 
colors.add(Color.rgb(159,185,235)); 
colors.add(Color.rgb(143,231,161)); 
colors.add(Color.rgb(160,239,136)); 
colors.add(Color.rgb(200,246,139)); 
colors.add(Color.rgb(176,219,233)); 
colors.add(Color.rgb(183,176,253)); 

pieDataSet.setColors(colors); 

///// disabling chart legend 
pieChart.getLegend().setEnabled(false); 

Log.d("PIECHART dataset2", xEntrys.size()+" "); 

//create pie data object 
PieData pieData = new PieData(pieDataSet); 
pieData.setValueTextColor(Color.RED);/* only YValue color changes, Xvalues   remains white*/ 
pieData.setValueFormatter(new valueFormat()); 
pieChart.setData(pieData); 
//pieDataSet.notifyDataSetChanged(); 
//pieChart.invalidate(); 

作出任何影響,請幫助。由於

回答

0

嘗試添加此:

int colorBlack = Color.parseColor("#000000"); 
pieChart.setEntryLabelColor(colorBlack); 
+0

非常感謝,這工作完全正常.. :) –